@willbooster/tree-sitter-ruby 6.0.5 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -12
- package/grammar.js +2 -1
- package/package.json +7 -8
- package/src/node-types.json +4 -0
- package/tree-sitter-ruby.wasm +0 -0
- package/tree-sitter.json +1 -7
- package/queries/highlights.scm +0 -151
- package/queries/locals.scm +0 -27
- package/queries/tags.scm +0 -64
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/WillBooster/tree-sitter-ruby/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/WillBooster/tree-sitter-ruby/actions/workflows/test-rust.yml)
|
|
7
7
|
[](https://github.com/semantic-release/semantic-release)
|
|
8
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
9
9
|
[](https://crates.io/crates/willbooster-tree-sitter-ruby)
|
|
10
10
|
|
|
11
11
|
Ruby grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
|
|
@@ -20,6 +20,13 @@ The scanner preserves long heredoc identifiers
|
|
|
20
20
|
when their state fits the runtime's serialization buffer. If the open heredocs cannot fit, their bodies are parsed as
|
|
21
21
|
code instead of aborting the process.
|
|
22
22
|
|
|
23
|
+
## Support Scope
|
|
24
|
+
|
|
25
|
+
This fork maintains only full parsing: valid input yields a correct tree, and invalid input yields `ERROR` or `MISSING`
|
|
26
|
+
nodes without crashing, hanging, or taking more than linear time. Incremental parsing works as in upstream tree-sitter
|
|
27
|
+
but is not tested here, and no queries (highlights, locals, injections, tags) are shipped. Node types, field names, and
|
|
28
|
+
the trees that error recovery produces may change; such changes are released as new major versions.
|
|
29
|
+
|
|
23
30
|
## Usage
|
|
24
31
|
|
|
25
32
|
The npm package ships `tree-sitter-ruby.wasm` for
|
|
@@ -64,16 +71,15 @@ const parser = new Parser();
|
|
|
64
71
|
parser.setLanguage(await Language.load(ruby));
|
|
65
72
|
```
|
|
66
73
|
|
|
67
|
-
The package also ships the
|
|
74
|
+
The package also ships the node types in `src/node-types.json`.
|
|
68
75
|
|
|
69
76
|
In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-ruby) and on
|
|
70
77
|
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
|
|
71
78
|
fuzzed with. The parser requires runtime 15.x:
|
|
72
79
|
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
tree-sitter-ruby = { package = "willbooster-tree-sitter-ruby", version = "6" }
|
|
80
|
+
```sh
|
|
81
|
+
cargo add willbooster-tree-sitter@15.0.0 --rename tree-sitter
|
|
82
|
+
cargo add willbooster-tree-sitter-ruby --rename tree-sitter-ruby
|
|
77
83
|
```
|
|
78
84
|
|
|
79
85
|
```rust
|
|
@@ -108,11 +114,8 @@ Profiles in `.tmp/generation-profiles/` are temporary and must not be committed.
|
|
|
108
114
|
`bun run test` runs:
|
|
109
115
|
|
|
110
116
|
- the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
|
|
111
|
-
-
|
|
112
|
-
|
|
113
|
-
`TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
|
|
114
|
-
- included-range comment and incremental-edit checks (`test/unit/includedRanges.test.ts`), which load the Wasm build
|
|
115
|
-
produced by `bun run build/ci`;
|
|
117
|
+
- included-range comment checks (`test/unit/includedRanges.test.ts`), which load the Wasm build produced by
|
|
118
|
+
`bun run build/ci`;
|
|
116
119
|
- a check that the real-world Ruby files of [ruby/spec](https://github.com/ruby/spec) cloned into `examples/` fail to
|
|
117
120
|
parse exactly as listed in `script/known-failures.txt`. The first run clones the repository, which is pinned to a
|
|
118
121
|
commit in `script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples`
|
|
@@ -123,7 +126,7 @@ Profiles in `.tmp/generation-profiles/` are temporary and must not be committed.
|
|
|
123
126
|
Node.js compatibility (`test/unit/workerd.test.ts`). Run `bun run test/ci-setup` once to install Chromium.
|
|
124
127
|
|
|
125
128
|
The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
|
|
126
|
-
by every checkout
|
|
129
|
+
by every checkout.
|
|
127
130
|
|
|
128
131
|
CI also runs these tests on Linux arm64 and macOS, where the Rust binding compiles the parser natively, and fuzzes the
|
|
129
132
|
parser with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
|
package/grammar.js
CHANGED
|
@@ -94,6 +94,7 @@ module.exports = grammar({
|
|
|
94
94
|
$._heredoc_resume,
|
|
95
95
|
$._body_comment,
|
|
96
96
|
$._body_line_break,
|
|
97
|
+
$._end_of_source,
|
|
97
98
|
],
|
|
98
99
|
|
|
99
100
|
extras: ($) => [$.comment, $.heredoc_body, $._heredoc_resume, /\s/, /\\\r?\n/],
|
|
@@ -228,7 +229,7 @@ module.exports = grammar({
|
|
|
228
229
|
],
|
|
229
230
|
|
|
230
231
|
rules: {
|
|
231
|
-
program: ($) => seq(optional($._statements), optional(
|
|
232
|
+
program: ($) => seq(optional($._statements), optional(seq(alias($._end_of_source, '__END__'), $.uninterpreted))),
|
|
232
233
|
|
|
233
234
|
// External extras must yield to the internal lexer after __END__.
|
|
234
235
|
uninterpreted: ($) => choice(/(.|\s)*/, $._uninterpreted),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-ruby",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Ruby grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"grammar.js",
|
|
19
|
-
"queries/*.scm",
|
|
20
19
|
"tree-sitter.json",
|
|
21
20
|
"src/node-types.json",
|
|
22
21
|
"*.wasm"
|
|
@@ -46,20 +45,20 @@
|
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
47
|
"@tsconfig/bun": "1.0.11",
|
|
49
|
-
"@types/bun": "1.4.
|
|
48
|
+
"@types/bun": "1.4.4",
|
|
50
49
|
"@vitest/browser-playwright": "5.0.5",
|
|
51
50
|
"@willbooster/oxlint-config": "1.4.9",
|
|
52
|
-
"@willbooster/wb": "
|
|
51
|
+
"@willbooster/wb": "23.0.2",
|
|
53
52
|
"@willbooster/web-tree-sitter": "15.0.0",
|
|
54
53
|
"conventional-changelog-conventionalcommits": "10.4.1",
|
|
55
54
|
"lefthook": "2.2.2",
|
|
56
|
-
"oxlint": "1.
|
|
57
|
-
"oxlint-tsgolint": "7.0.
|
|
55
|
+
"oxlint": "1.89.0",
|
|
56
|
+
"oxlint-tsgolint": "7.0.2005",
|
|
58
57
|
"playwright": "1.64.1",
|
|
59
58
|
"semantic-release": "25.0.9",
|
|
60
|
-
"vite": "8.3.
|
|
59
|
+
"vite": "8.3.5",
|
|
61
60
|
"vitest": "5.0.5",
|
|
62
|
-
"wrangler": "4.
|
|
61
|
+
"wrangler": "4.152.0"
|
|
63
62
|
},
|
|
64
63
|
"peerDependencies": {
|
|
65
64
|
"@willbooster/web-tree-sitter": "^15.0.0"
|
package/src/node-types.json
CHANGED
package/tree-sitter-ruby.wasm
CHANGED
|
Binary file
|
package/tree-sitter.json
CHANGED
|
@@ -9,17 +9,11 @@
|
|
|
9
9
|
"file-types": [
|
|
10
10
|
"rb"
|
|
11
11
|
],
|
|
12
|
-
"highlights": [
|
|
13
|
-
"queries/highlights.scm"
|
|
14
|
-
],
|
|
15
|
-
"tags": [
|
|
16
|
-
"queries/tags.scm"
|
|
17
|
-
],
|
|
18
12
|
"injection-regex": "ruby"
|
|
19
13
|
}
|
|
20
14
|
],
|
|
21
15
|
"metadata": {
|
|
22
|
-
"version": "
|
|
16
|
+
"version": "8.0.0",
|
|
23
17
|
"license": "MIT",
|
|
24
18
|
"description": "Ruby grammar for tree-sitter",
|
|
25
19
|
"authors": [
|
package/queries/highlights.scm
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
(identifier) @variable
|
|
2
|
-
|
|
3
|
-
((identifier) @function.method
|
|
4
|
-
(#is-not? local))
|
|
5
|
-
|
|
6
|
-
[
|
|
7
|
-
"alias"
|
|
8
|
-
"and"
|
|
9
|
-
"begin"
|
|
10
|
-
"break"
|
|
11
|
-
"case"
|
|
12
|
-
"class"
|
|
13
|
-
"def"
|
|
14
|
-
"do"
|
|
15
|
-
"else"
|
|
16
|
-
"elsif"
|
|
17
|
-
"end"
|
|
18
|
-
"ensure"
|
|
19
|
-
"for"
|
|
20
|
-
"if"
|
|
21
|
-
"in"
|
|
22
|
-
"module"
|
|
23
|
-
"next"
|
|
24
|
-
"or"
|
|
25
|
-
"rescue"
|
|
26
|
-
"retry"
|
|
27
|
-
"return"
|
|
28
|
-
"then"
|
|
29
|
-
"unless"
|
|
30
|
-
"until"
|
|
31
|
-
"when"
|
|
32
|
-
"while"
|
|
33
|
-
"yield"
|
|
34
|
-
] @keyword
|
|
35
|
-
|
|
36
|
-
(constant) @constructor
|
|
37
|
-
|
|
38
|
-
; Function calls
|
|
39
|
-
|
|
40
|
-
"defined?" @function.method.builtin
|
|
41
|
-
|
|
42
|
-
(call
|
|
43
|
-
method: [(identifier) (constant)] @function.method)
|
|
44
|
-
|
|
45
|
-
((identifier) @function.method.builtin
|
|
46
|
-
(#eq? @function.method.builtin "require"))
|
|
47
|
-
|
|
48
|
-
; Function definitions
|
|
49
|
-
|
|
50
|
-
(alias (identifier) @function.method)
|
|
51
|
-
(setter (identifier) @function.method)
|
|
52
|
-
(method name: [(identifier) (constant)] @function.method)
|
|
53
|
-
(singleton_method name: [(identifier) (constant)] @function.method)
|
|
54
|
-
|
|
55
|
-
; Identifiers
|
|
56
|
-
|
|
57
|
-
[
|
|
58
|
-
(class_variable)
|
|
59
|
-
(instance_variable)
|
|
60
|
-
] @property
|
|
61
|
-
|
|
62
|
-
((identifier) @constant.builtin
|
|
63
|
-
(#match? @constant.builtin "^__(FILE|LINE|ENCODING)__$"))
|
|
64
|
-
|
|
65
|
-
(file) @constant.builtin
|
|
66
|
-
(line) @constant.builtin
|
|
67
|
-
(encoding) @constant.builtin
|
|
68
|
-
|
|
69
|
-
(hash_splat_nil
|
|
70
|
-
"**" @operator) @constant.builtin
|
|
71
|
-
|
|
72
|
-
((constant) @constant
|
|
73
|
-
(#match? @constant "^[A-Z\\d_]+$"))
|
|
74
|
-
|
|
75
|
-
[
|
|
76
|
-
(self)
|
|
77
|
-
(super)
|
|
78
|
-
] @variable.builtin
|
|
79
|
-
|
|
80
|
-
(block_parameter (identifier) @variable.parameter)
|
|
81
|
-
(block_parameters (identifier) @variable.parameter)
|
|
82
|
-
(destructured_parameter (identifier) @variable.parameter)
|
|
83
|
-
(hash_splat_parameter (identifier) @variable.parameter)
|
|
84
|
-
(lambda_parameters (identifier) @variable.parameter)
|
|
85
|
-
(method_parameters (identifier) @variable.parameter)
|
|
86
|
-
(splat_parameter (identifier) @variable.parameter)
|
|
87
|
-
|
|
88
|
-
(keyword_parameter name: (identifier) @variable.parameter)
|
|
89
|
-
(optional_parameter name: (identifier) @variable.parameter)
|
|
90
|
-
|
|
91
|
-
; Literals
|
|
92
|
-
|
|
93
|
-
[
|
|
94
|
-
(string)
|
|
95
|
-
(bare_string)
|
|
96
|
-
(subshell)
|
|
97
|
-
(heredoc_body)
|
|
98
|
-
(heredoc_beginning)
|
|
99
|
-
] @string
|
|
100
|
-
|
|
101
|
-
[
|
|
102
|
-
(simple_symbol)
|
|
103
|
-
(delimited_symbol)
|
|
104
|
-
(hash_key_symbol)
|
|
105
|
-
(bare_symbol)
|
|
106
|
-
] @string.special.symbol
|
|
107
|
-
|
|
108
|
-
(regex) @string.special.regex
|
|
109
|
-
(escape_sequence) @escape
|
|
110
|
-
|
|
111
|
-
[
|
|
112
|
-
(integer)
|
|
113
|
-
(float)
|
|
114
|
-
] @number
|
|
115
|
-
|
|
116
|
-
[
|
|
117
|
-
(nil)
|
|
118
|
-
(true)
|
|
119
|
-
(false)
|
|
120
|
-
] @constant.builtin
|
|
121
|
-
|
|
122
|
-
(interpolation
|
|
123
|
-
"#{" @punctuation.special
|
|
124
|
-
"}" @punctuation.special) @embedded
|
|
125
|
-
|
|
126
|
-
(comment) @comment
|
|
127
|
-
|
|
128
|
-
; Operators
|
|
129
|
-
|
|
130
|
-
[
|
|
131
|
-
"="
|
|
132
|
-
"=>"
|
|
133
|
-
"->"
|
|
134
|
-
] @operator
|
|
135
|
-
|
|
136
|
-
[
|
|
137
|
-
","
|
|
138
|
-
";"
|
|
139
|
-
"."
|
|
140
|
-
] @punctuation.delimiter
|
|
141
|
-
|
|
142
|
-
[
|
|
143
|
-
"("
|
|
144
|
-
")"
|
|
145
|
-
"["
|
|
146
|
-
"]"
|
|
147
|
-
"{"
|
|
148
|
-
"}"
|
|
149
|
-
"%w("
|
|
150
|
-
"%i("
|
|
151
|
-
] @punctuation.bracket
|
package/queries/locals.scm
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
((method) @local.scope
|
|
2
|
-
(#set! local.scope-inherits false))
|
|
3
|
-
|
|
4
|
-
[
|
|
5
|
-
(lambda)
|
|
6
|
-
(block)
|
|
7
|
-
(do_block)
|
|
8
|
-
] @local.scope
|
|
9
|
-
|
|
10
|
-
(block_parameter (identifier) @local.definition)
|
|
11
|
-
(block_parameters (identifier) @local.definition)
|
|
12
|
-
(destructured_parameter (identifier) @local.definition)
|
|
13
|
-
(hash_splat_parameter (identifier) @local.definition)
|
|
14
|
-
(lambda_parameters (identifier) @local.definition)
|
|
15
|
-
(method_parameters (identifier) @local.definition)
|
|
16
|
-
(splat_parameter (identifier) @local.definition)
|
|
17
|
-
|
|
18
|
-
(keyword_parameter name: (identifier) @local.definition)
|
|
19
|
-
(optional_parameter name: (identifier) @local.definition)
|
|
20
|
-
|
|
21
|
-
(identifier) @local.reference
|
|
22
|
-
|
|
23
|
-
(assignment left: (identifier) @local.definition)
|
|
24
|
-
(operator_assignment left: (identifier) @local.definition)
|
|
25
|
-
(left_assignment_list (identifier) @local.definition)
|
|
26
|
-
(rest_assignment (identifier) @local.definition)
|
|
27
|
-
(destructured_left_assignment (identifier) @local.definition)
|
package/queries/tags.scm
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
; Method definitions
|
|
2
|
-
|
|
3
|
-
(
|
|
4
|
-
(comment)* @doc
|
|
5
|
-
.
|
|
6
|
-
[
|
|
7
|
-
(method
|
|
8
|
-
name: (_) @name) @definition.method
|
|
9
|
-
(singleton_method
|
|
10
|
-
name: (_) @name) @definition.method
|
|
11
|
-
]
|
|
12
|
-
(#strip! @doc "^#\\s*")
|
|
13
|
-
(#select-adjacent! @doc @definition.method)
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
(alias
|
|
17
|
-
name: (_) @name) @definition.method
|
|
18
|
-
|
|
19
|
-
(setter
|
|
20
|
-
(identifier) @ignore)
|
|
21
|
-
|
|
22
|
-
; Class definitions
|
|
23
|
-
|
|
24
|
-
(
|
|
25
|
-
(comment)* @doc
|
|
26
|
-
.
|
|
27
|
-
[
|
|
28
|
-
(class
|
|
29
|
-
name: [
|
|
30
|
-
(constant) @name
|
|
31
|
-
(scope_resolution
|
|
32
|
-
name: (_) @name)
|
|
33
|
-
]) @definition.class
|
|
34
|
-
(singleton_class
|
|
35
|
-
value: [
|
|
36
|
-
(constant) @name
|
|
37
|
-
(scope_resolution
|
|
38
|
-
name: (_) @name)
|
|
39
|
-
]) @definition.class
|
|
40
|
-
]
|
|
41
|
-
(#strip! @doc "^#\\s*")
|
|
42
|
-
(#select-adjacent! @doc @definition.class)
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
; Module definitions
|
|
46
|
-
|
|
47
|
-
(
|
|
48
|
-
(module
|
|
49
|
-
name: [
|
|
50
|
-
(constant) @name
|
|
51
|
-
(scope_resolution
|
|
52
|
-
name: (_) @name)
|
|
53
|
-
]) @definition.module
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
; Calls
|
|
57
|
-
|
|
58
|
-
(call method: (identifier) @name) @reference.call
|
|
59
|
-
|
|
60
|
-
(
|
|
61
|
-
[(identifier) (constant)] @name @reference.call
|
|
62
|
-
(#is-not? local)
|
|
63
|
-
(#not-match? @name "^(lambda|load|require|require_relative|__FILE__|__LINE__)$")
|
|
64
|
-
)
|