Skip to content

Commit

Permalink
refactor: reorganize files for simpler lib
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed May 2, 2024
1 parent dc1bffb commit ff4813a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
10 changes: 10 additions & 0 deletions parsing_handlers/src/language.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::{java::get_default_java_parsing_handlers, ParsingHandlers};
use model::Language;

impl From<Language> for ParsingHandlers {
fn from(language: Language) -> Self {
match language {
Language::Java => get_default_java_parsing_handlers(),
}
}
}
29 changes: 3 additions & 26 deletions parsing_handlers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
mod java;
mod language;
mod parsing_handlers;

use java::get_default_java_parsing_handlers;
use model::Language;

pub type ParsingHandler = fn(root: model::CSTNode) -> model::CSTNode;

pub struct ParsingHandlers {
handlers: Vec<ParsingHandler>,
}

impl ParsingHandlers {
pub fn new(handlers: Vec<ParsingHandler>) -> Self {
Self { handlers }
}

pub fn run<'a>(&'a self, root: model::CSTNode<'a>) -> model::CSTNode<'a> {
self.handlers.iter().fold(root, |acc, handler| handler(acc))
}
}

impl From<Language> for ParsingHandlers {
fn from(language: Language) -> Self {
match language {
Language::Java => get_default_java_parsing_handlers(),
}
}
}
pub use parsing_handlers::{ParsingHandler, ParsingHandlers};
17 changes: 17 additions & 0 deletions parsing_handlers/src/parsing_handlers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use model::CSTNode;

pub type ParsingHandler = fn(root: CSTNode) -> CSTNode;

pub struct ParsingHandlers {
handlers: Vec<ParsingHandler>,
}

impl ParsingHandlers {
pub fn new(handlers: Vec<ParsingHandler>) -> Self {
Self { handlers }
}

pub fn run<'a>(&'a self, root: CSTNode<'a>) -> CSTNode<'a> {
self.handlers.iter().fold(root, |acc, handler| handler(acc))
}
}

0 comments on commit ff4813a

Please sign in to comment.