-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parsing,parsing_handlers): add API to enhance parsing result (#49)
This PR introduces an API that enables users to augment Tree Sitter's output, enriching the tree structure with additional information.
- Loading branch information
Showing
3 changed files
with
30 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |