tree-sitter-installer

Crates.iotree-sitter-installer
lib.rstree-sitter-installer
version0.2.0
sourcesrc
created_at2023-02-27 17:36:16.9473
updated_at2023-03-05 11:27:32.929306
descriptionA tool to install tree-sitter parsers at runtime
homepage
repositoryhttps://github.com/selfint/code-blocks
max_upload_size
id796248
size24,091
(selfint)

documentation

README

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)))
}
Commit count: 171

cargo fmt