mesquite_bash 0.1.0

The Bash grammar for Mesquite (pure-Rust tree-sitter), from tree-sitter-bash 0.25.1
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented0 out of 1 items with examples
  • Size
  • Source code size: 1.7 MB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.8 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • mesa-hills-research/mesquite
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mesa-hills-research

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 regex and streaming-iterator.
  • Safe. Every crate has #![forbid(unsafe_code)].
  • Drop-in names. The runtime's library is tree_sitter and 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 its Cargo.toml changed.
  • 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:

[dependencies]
mesquite = "0.25.10"
mesquite_rust = "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:

[dependencies]
tree-sitter = { package = "mesquite", version = "0.25.10" }
tree-sitter-rust = { package = "mesquite_rust", version = "0.1.0" }

The crates use the 2024 edition and need Rust 1.89 or later.

Usage

use tree_sitter::{Parser, Query, QueryCursor, StreamingIterator};

let mut parser = Parser::new();
parser
    .set_language(&tree_sitter_rust::LANGUAGE.into())
    .expect("Error loading Rust grammar");
let source = "fn main() {}";
let tree = parser.parse(source, None).unwrap();
assert_eq!(
    tree.root_node().to_sexp(),
    "(source_file (function_item name: (identifier) parameters: (parameters) body: (block)))"
);

let query = Query::new(
    &tree_sitter_rust::LANGUAGE.into(),
    "(function_item name: (identifier) @name)",
)
.unwrap();
let mut cursor = QueryCursor::new();
let mut matches = cursor.matches(&query, tree.root_node(), source.as_bytes());
while let Some(found) = matches.next() {
    for capture in found.captures.iter() {
        println!("{}", capture.node.utf8_text(source.as_bytes()).unwrap());
    }
}

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 Parser that is Send but not Sync, and the C bugs the port fixes.
  • Speed: the full comparison with C.

Tests

cargo test --workspace

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.