Rust Sitter makes it easy to create efficient parsers in Rust by leveraging the Tree Sitter parser generator. With Rust Sitter, you can define your entire grammar with annotations on idiomatic Rust code, and let macros generate the parser and type-safe bindings for you!
First, add Rust/Tree Sitter to your Cargo.toml
:
[dependencies]
rust-sitter = "0.4.2"
[build-dependencies]
rust-sitter-tool = "0.4.2"
Note: By default, Rust Sitter uses a fork of Tree Sitter with a pure-Rust runtime to support wasm32-unknown-unknown
. To use the standard C runtime instead, disable default features and enable the tree-sitter-standard
feature
The first step is to configure your build.rs
to compile and link the generated Tree Sitter parser:
use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-changed=src");
rust_sitter_tool::build_parsers(