@willbooster/tree-sitter-ruby
Ruby grammar for tree-sitter, forked from tree-sitter/tree-sitter-ruby. We are grateful to its authors and contributors. This is not an official release of that project.
This fork extends the upstream grammar to parse anonymous block forwarding, spaced block arguments, and command calls in endless methods, with a parser generated by
WillBooster/tree-sitter, whose compact parse tables make the
parser smaller. The parser carries that fork's own ABI number (0x5742000c) and omits tables dropped in runtime 19, so it
requires the WillBooster runtime 19.x; upstream's tree-sitter runtime and incompatible ABI versions of the fork's runtime
reject it.
The scanner preserves long heredoc identifiers
when their state fits the runtime's serialization buffer. If the open heredocs cannot fit, their bodies are parsed as
code instead of aborting the process.
Support Scope
This fork maintains only full parsing: valid input yields a correct tree, and invalid input yields ERROR or MISSING
nodes without crashing, hanging, or taking more than linear time. Parse each input without a previous tree; reusing
an old tree is unsupported. No queries (highlights, locals, injections, tags) are shipped. Node types, field names, and
the trees that error recovery produces may change; such changes are released as new major versions.
Usage
The npm package ships tree-sitter-ruby.wasm for
@willbooster/web-tree-sitter, which runs in Node.js, Bun,
browsers, and Cloudflare Workers. The parser requires runtime 19.x.
In Node.js and Bun, load the grammar from its path:
import from 'node:url';
import from '@willbooster/web-tree-sitter';
await ;
const parser = ;
const wasmPath = ;
parser.;
const tree = parser.;
In browsers, load the grammar from its URL. With Vite:
import rubyUrl from '@willbooster/tree-sitter-ruby/tree-sitter-ruby.wasm?url';
import from '@willbooster/web-tree-sitter';
import runtimeUrl from '@willbooster/web-tree-sitter/web-tree-sitter.wasm?url';
await ;
const parser = ;
parser.;
In Cloudflare Workers, which do not allow compiling Wasm at run time, import both .wasm files as modules:
import ruby from '@willbooster/tree-sitter-ruby/tree-sitter-ruby.wasm';
import from '@willbooster/web-tree-sitter';
import runtime from '@willbooster/web-tree-sitter/web-tree-sitter.wasm';
await ;
const parser = ;
parser.;
The package also ships the node types in src/node-types.json.
In Rust, depend on the crate and on willbooster-tree-sitter, the runtime this package is tested and fuzzed with. The parser requires runtime 19.x:
let mut parser = new;
parser.set_language?;
Development
bun run test/ci-setup: run once to install Chromium beforebun run test.bun run build/ci: run beforebun run test, and commitsrc/after changinggrammar.js,tree-sitter.json,test/corpus/, or tracked files inexamples/. Stage added or removedexamples/files withgit add -A examplesbefore generating so the profile sees them.script/parse-examples: run without arguments to updatescript/known-failures.txtafter a grammar or pin change alters whichruby/specfiles fail to parse.script/tree-sitter: use for direct CLI commands such asscript/tree-sitter parse file.rbso they run theWillBooster/tree-sitterversion locked inCargo.lock.