The Tree-sitter Rust bindings provide idiomatic Rust access to the Tree-sitter parsing library. The bindings are available on crates.io and provide a safe, ergonomic API for parsing and analyzing source code.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tree-sitter/tree-sitter/llms.txt
Use this file to discover all available pages before exploring further.
Installation
Add Tree-sitter to yourCargo.toml:
Basic Usage
First, create a parser:Core Types
The Rust bindings expose several key types:Parser
Create and configure parsers for generating syntax trees
Tree
Represent and manipulate syntax trees
Node
Navigate and inspect individual nodes in a syntax tree
Query
Search syntax trees using pattern matching
Language
Define and inspect language grammars
Wasm
Load and use WebAssembly-based grammars
ABI Compatibility
The Rust bindings include version constants for checking ABI compatibility:The latest ABI version supported by the current version of the library
The earliest ABI version supported by the current version of the library
Features
The crate supports several optional features:Enables standard library support. When enabled:
- Error types implement
std::error::Error regexperformance optimizations are enabled- DOT graph methods are available
Enables WebAssembly support for loading grammar files compiled to Wasm. Requires the
wasmtime-c-api crate.Error Handling
The bindings use idiomatic Rust error handling withResult types:
Next Steps
Parser API
Learn how to create and configure parsers
Tree Traversal
Navigate and inspect syntax trees
Query Patterns
Search syntax trees with queries
Wasm Support
Use WebAssembly-based grammars