3 unstable releases
0.2.0 | Mar 5, 2023 |
---|---|
0.1.1 | Feb 27, 2023 |
0.1.0 | Feb 27, 2023 |
#89 in #installer
Used in code-blocks-server
11KB
197 lines
tree-sitter-installer
Library for downloading, compiling and loading a tree-sitter parser at runtime.
Example
use tree_sitter_installer::ParserInstaller;
fn main() {
let text = r#"
struct A {
a: i32
}
fn main() {}
"#;
let installer = ParserInstaller {
download_cmd: "git clone https://github.com/tree-sitter/tree-sitter-rust",
symbol: b"language",
name: "tree_sitter_rust",
};
let mut parser = installer
.install_parser(
&tempfile::tempdir()
.expect("failed to get tempdir")
.path()
.join("rust-parser"),
)
.expect("failed to install rust parser");
let tree = parser.parse(text, None).expect("failed to parse text");
println!("{}", tree.root_node().to_sexp());
// prints: (source_file (struct_item name: (type_identifier) body: (field_declaration_list (field_declaration name: (field_identifier) type: (primitive_type)))) (function_item name: (identifier) parameters: (parameters) body: (block)))
}
Dependencies
~2.9–4.5MB
~79K SLoC