Mesquite
Mesquite is a pure, safe Rust port of tree-sitter 0.25.10 and 58 grammars.
- Pure Rust. No C sources, build scripts or C compiler. The only external
dependencies are
regexandstreaming-iterator. - Safe. Every crate has
#![forbid(unsafe_code)]. - Drop-in names. The runtime's library is
tree_sitterand follows tree-sitter's Rust API. Each grammar crate's library and constants are named like the upstream crate's (tree_sitter_rust::LANGUAGE), so most code that uses tree-sitter only needs itsCargo.tomlchanged. - Same results as C. Trees, incremental reparses, query results and progress callbacks match the C library's, apart from a few C bugs it fixes.
Languages
Astro, Bash, C, C#, C++, CMake, CSS, CUDA, Dart, Diff, Elixir, Elm, Embedded templates (ERB, EJS), Erlang, F#, Fortran, GLSL, Go, GraphQL, Haskell, HCL, HTML, Java, JavaScript, JSDoc, JSON, Julia, Kotlin, Lua, Make, Markdown, Objective-C, OCaml, Odin, Perl, PHP, PowerShell, Protocol Buffers, Python, R, Ruby, Rust, Scala, Solidity, SQL, Svelte, Swift, TOML, TypeScript and TSX, Verilog, XML and DTD, YAML, Zig.
The crates, their upstream versions and their constants are listed in docs/grammars.md.
Speed
Parse time relative to C tree-sitter 0.25.10 with the same grammars (below 1 is faster).
| Inputs | Mesquite / C |
|---|---|
| All 58 grammars (geometric mean) | 0.73 |
| C (Linux kernel) | 0.66 |
| C++ | 0.66 |
| Rust | 0.70 |
| Python | 0.71 |
| TypeScript | 0.72 |
| JavaScript | 0.68 |
| Go | 0.81 |
| Java | 0.67 |
Mesquite is faster on 53 of the 58 grammars. Each grammar's tables are decoded the first time it is used, which takes a median of 19 ms. Every grammar, the machine, the method and how to compare on your own files are in docs/speed.md.
Installation
Add the runtime and a grammar crate for each language you parse:
[]
= "0.25.10"
= "0.1.0"
The library names are tree_sitter and tree_sitter_rust, so use tree_sitter::...
lines stay as they are. To keep upstream's dependency names as well, rename the packages:
[]
= { = "mesquite", = "0.25.10" }
= { = "mesquite_rust", = "0.1.0" }
The crates use the 2024 edition and need Rust 1.89 or later.
Usage
use ;
let mut parser = new;
parser
.set_language
.expect;
let source = "fn main() {}";
let tree = parser.parse.unwrap;
assert_eq!;
let query = new
.unwrap;
let mut cursor = new;
let mut matches = cursor.matches;
while let Some = matches.next
Documentation
- Grammars: every grammar crate, its upstream crate and constants, and the repository layout.
- Differences from tree-sitter 0.25.10: chiefly the missing C
API and WebAssembly support, a
Parserthat isSendbut notSync, and the C bugs the port fixes. - Speed: the full comparison with C.
Tests
License
MIT, like tree-sitter and most of the grammars. Four grammars are Apache-2.0 (Astro,
Elixir, Erlang and HCL). The copyright notices are in NOTICE, and the license
texts in LICENSE, runtime/LICENSE, tables/LICENSE and
grammars/<key>/LICENSE.