Crates.io | tree-sitter-installer |
lib.rs | tree-sitter-installer |
version | 0.2.0 |
source | src |
created_at | 2023-02-27 17:36:16.9473 |
updated_at | 2023-03-05 11:27:32.929306 |
description | A tool to install tree-sitter parsers at runtime |
homepage | |
repository | https://github.com/selfint/code-blocks |
max_upload_size | |
id | 796248 |
size | 24,091 |
Library for downloading, compiling and loading a tree-sitter parser at runtime.
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)))
}