Repository navigation
Releases
v0.27.0
Maintained fork of tree-sitter-ruby. Changes since 0.26.0:
Parsing
- Checked on all 78,129 Ruby files of Rails, Discourse, GitLab and Mastodon: every one now agrees with Prism. Two fixes came out of it:
- a call with arguments after a command's do block, as RSpec writes it:
expect(x).to receive(:y) do … end.and_return(z), and chains likeend.c(1).d; + 1.abswith a space is+(1.abs), as in Ruby.
- a call with arguments after a command's do block, as RSpec writes it:
- A string key in a hash pattern binds its name: after
in {"name":},name +1isname + 1. - Heredocs: a line that repeats the end word (
EOSEOS) and a lone carriage return no longer end the body.
Queries
highlights.scm: the implicit block parametersitand_1to_9are parameters, no longer method calls.it "..." doin RSpec stays a call.locals.scm:in {name:},in {"name":},in (x)andin _a | _bdefine their names, so later uses are variables.
Quality and security
- The tests run 97.7 % of the scanner's lines and 92.4 % of its branches; CI fails if that drops.
- The scanner builds without warnings under gcc and clang (
-Wall -Wextra -Wpedantic -Wshadow -Werror). - Fuzzing with ClusterFuzzLite: five minutes per sanitizer on each pull request that touches the parser, an hour each every night.
- OpenSSF Best Practices badge (passing) and an OpenSSF Scorecard; SECURITY.md with private vulnerability reporting, and CONTRIBUTING.md.
- Performance history of every release since upstream 0.23.1.
On npm (@magikdidi24/tree-sitter-ruby), crates.io and PyPI (tree-sitter-ruby-magikdidi24).
NOTE: Download tree-sitter-ruby.tar.gz for the complete source code.
v0.26.0
Maintained fork of tree-sitter-ruby. Changes since 0.25.0:
Parsing
- Names bound by pattern matching are local variables, as in Ruby: after
in [x],in {name:},in A => x,v => xorv in [x],x +1isx + 1. Pins, constants andk: vkeys bind nothing. String keys (in {"name":}) are not handled yet. - An incremental reparse gives the same tree as a fresh parse in 6 more cases, found by a new edit fuzzer:
<<and%wafter a reused node,rescueor;on the line afterkey:,def x = v in [d], and a literal left open. A literal left open is now content up to the end of the file ("abc→ a string with a missing quote), as in Prism.
Size and speed
- The parser is 27 % smaller:
parser.c19.9 → 14.6 MB, 7925 → 6123 states, wasm 2.77 → 2.02 MB (the playground loads faster). - About 2 % fewer instructions to parse.
- In
node-types.json, an endless method (def f = …) is now an_arginstead of a_primary, as in Ruby's grammar.
Packages and CI
- On npm (
@magikdidi24/tree-sitter-ruby), crates.io and PyPI (tree-sitter-ruby-magikdidi24), published with trusted publishing (OIDC): no registry token is stored anywhere. - Pull requests fail when the parser runs more than 3 % more instructions (cachegrind).
- Every night: an hour of fuzzing, and the edit fuzzer with ASan and UBSan.
- Scanner coverage by the tests: 95.9 % of lines, 86.4 % of branches (badge in the README).
NOTE: Download tree-sitter-ruby.tar.gz for the complete source code.
v0.25.0
Maintained fork of tree-sitter-ruby. Changes since 0.24.1:
ABI 15
src/parser.cis generated for ABI 15, which tree-sitter 0.25 and newer runtimes read (Neovim 0.11, py-tree-sitter 0.25, node-tree-sitter 0.25, the Rust crate 0.25). It carries the grammar name, version and supertypes.- Older runtimes (Neovim 0.10, tree-sitter 0.22 to 0.24) need
tree-sitter generate --abi 14from the source tarball. - The Neovim, Helix and Zed Ruby queries all compile against this grammar.
Playground
- Try the parser in the browser: https://magikdidi24.github.io/tree-sitter-ruby/
Packages
- Package names for this fork, same import names (
tree_sitter_ruby):@magikdidi24/tree-sitter-rubyon npm,tree-sitter-ruby-magikdidi24for Cargo and pip. Until they reach the registries, install from git (see the README). - The Go module path is
github.com/Magikdidi24/tree-sitter-ruby.
CI
- The inputs that once crashed, hung or slowed the scanner (heredoc floods, deep nesting, long comma lists, random bytes, every prefix of the constructs that keep scanner state) are parsed under ASan and UBSan, with a 10 s limit per file.
Performance
- Identifier characters are looked up in a table: 46 MB of real Ruby parse in 4.81 s instead of 4.88 s (user CPU).
NOTE: Download tree-sitter-ruby.tar.gz for the complete source code.
v0.24.1
Maintained fork of tree-sitter-ruby. Changes since 0.24.0:
Parsing
- Like Ruby,
x +1isx + 1whenxis a local variable, and the callx(+1)otherwise. The same goes for-,*,**,&,[,/,%and<<. The scanner tracks assignments, parameters,forandrescue =>variables, numbered parameters, and the scopes of blocks, lambdas, methods (endless ones too), classes and modules. Pattern-matching bindings are not tracked. def self(token): a method may be namedself.- Hash keys
defined?:,key?:andkey!:. - Symbols of special globals:
:$',:$:,:$;,:$-w. return[1],return-1,return*a,return - (x)andbreak[1]take an operand, as in Ruby.- Checked against Prism on stdlib, the installed gems and ruby/spec: 6685 of 6689 files agree, up from 6680 (the other 4 are UTF-16 fixtures and files Prism rejects).
Queries
locals.scm: a superclass (class A < base) and the object ofclass << objare read in the outer scope.
Build and CI
- tree-sitter CLI 0.27.2, still ABI 14 (the Python binding needs it).
TREE_SITTER_JS_RUNTIME=denogenerates the same parser as Node. deno lintinstead of ESLint; npm audit is clean.- Rust: tree-sitter 0.27.2,
rust-version = "1.90", tree-sitter-language 0.1.8 or newer. - Python: no
wheelbuild dependency (setuptools 71 or newer). - CI actions pinned to commits, read-only tokens, CodeQL on the scanner, Dependabot for every ecosystem, and the ruby/spec examples really parsed.
Performance
- Local-variable tracking costs about 7 % of parse time (46 MB of real Ruby: 4.70 s → 5.02 s, user CPU) and some memory per token (a method with 8 locals: +2 % peak RSS).
Not published on npm, crates.io or PyPI (those names belong to upstream). Use the source tarball or a git dependency on this repo.
NOTE: Download tree-sitter-ruby.tar.gz for the complete source code.
v0.24.0: release: 0.24.0
Maintained fork of tree-sitter-ruby. Changes since 0.23.1:
Parsing
- Every open upstream issue is handled: 21 fixed (heredocs, ERB comments, anonymous
&block args, multi-byte symbols,%literals, Ruby 4.0 leading||/and/or, scanner crash on deserialize, ...), 4 closed as wontfix with a reason. - Checked against Prism on ruby/spec: 4440 of 4444 files agree (the other 4 are UTF-16 fixtures and files Prism rejects).
Queries
- Better highlights, locals and tags, and a new
injections.scm(regex, heredocs labelled SQL, GraphQL, HTML, Bash, Ruby).
Build
- Generated with tree-sitter CLI 0.27.1, still ABI 14.
- Rust crate on edition 2024: needs Rust 1.85 or newer.
- Go bindings use go-tree-sitter 0.25 (Go 1.23), Python needs 3.10 or newer.
- In
node-types.json,call.operatoris now"." | "&." | "::".
Not published on npm, crates.io or PyPI (those names belong to upstream). Use the source tarball or a git dependency on this repo.
NOTE: Download tree-sitter-ruby.tar.gz for the complete source code.