-
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
9 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,11 @@ | ||
[package] | ||
name = "parsing_handlers" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
model = { path = "../model" } | ||
log = { workspace = true } | ||
uuid = { workspace = true } |
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,5 @@ | ||
use crate::ParsingHandlers; | ||
|
||
pub fn get_default_java_parsing_handlers() -> ParsingHandlers { | ||
ParsingHandlers::new(vec![]) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod java; | ||
mod language; | ||
mod 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)) | ||
} | ||
} |