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), with C built by GCC 13.4 or Clang 21.1.
| Inputs | GCC 13.4 | Clang 21.1 |
|---|---|---|
| All 58 grammars (geometric mean) | 0.71 | 0.72 |
| C (Linux kernel) | 0.62 | 0.68 |
| C++ | 0.72 | 0.73 |
| Rust | 0.68 | 0.71 |
| Python | 0.71 | 0.75 |
| TypeScript | 0.71 | 0.75 |
| JavaScript | 0.72 | 0.75 |
| Go | 0.66 | 0.80 |
| Java | 0.66 | 0.79 |
Mesquite is faster on 57 of the 58 grammars. Its large grammar tables are read in place from the binary, as C reads its static arrays, so a grammar's first use takes at most 0.1 ms. Every grammar, memory, binary size, reparsing, 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.26.0"
= "0.2.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.26.0" }
= { = "mesquite_rust", = "0.2.0" }
Mesquite 0.26 still follows tree-sitter 0.25.10. Its version moved past 0.25 when the grammar crates' tables changed, so it needs the 0.2 grammar crates. 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.