@willbooster/tree-sitter-ruby 11.0.1 → 12.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/grammar.js +96 -83
- package/package.json +1 -1
- package/src/node-types.json +8 -40
- package/tree-sitter-ruby.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -134,7 +134,6 @@ module.exports = grammar({
|
|
|
134
134
|
[$._signed_command_argument_list, $._yield_signed_argument_list],
|
|
135
135
|
[$._chained_match_pattern, $._yield_value],
|
|
136
136
|
[$._endless_body_rescue, $._yield_method_body_rescue],
|
|
137
|
-
[$._body_expr, $._yield_method_rest],
|
|
138
137
|
[$._pattern_command_not, $._command_not],
|
|
139
138
|
[$._negated_chained_test_pattern, $._yield_test_pattern],
|
|
140
139
|
[$._chained_test_pattern, $._negated_chained_test_pattern, $._yield_test_pattern, $._command_not],
|
|
@@ -145,7 +144,7 @@ module.exports = grammar({
|
|
|
145
144
|
[$._argument_command_value, $._chained_match_pattern, $._yield_value],
|
|
146
145
|
[$._argument_command_value, $._yield_value, $.pair],
|
|
147
146
|
[$._argument_command_value, $._yield_value],
|
|
148
|
-
[$._argument_command_value, $.
|
|
147
|
+
[$._argument_command_value, $._command_pair_head],
|
|
149
148
|
[$._argument_command_value, $.pair],
|
|
150
149
|
[$._argument_command_value, $._command_definition_pair],
|
|
151
150
|
[$._argument_command_value, $._chained_match_pattern],
|
|
@@ -155,6 +154,7 @@ module.exports = grammar({
|
|
|
155
154
|
[$._yield_argument_list, $._yield_call_pair_key_arguments],
|
|
156
155
|
[$.command_call, $._command_pair, $._yield_command_pair],
|
|
157
156
|
[$._command_pair, $._yield_command_pair],
|
|
157
|
+
[$._command_pair_head, $._yield_command_pair_head],
|
|
158
158
|
[$._command_value, $._command_pair, $._yield_command_pair],
|
|
159
159
|
[$._pattern_unary, $.unary],
|
|
160
160
|
[$._arg, $._pattern_arg],
|
|
@@ -167,15 +167,14 @@ module.exports = grammar({
|
|
|
167
167
|
[$._yield_argument, $._yield_pair_key_arguments],
|
|
168
168
|
[$._yield_pattern_not, $._test_pattern_not],
|
|
169
169
|
[$._yield_argument_list, $._yield_pair_key_arguments],
|
|
170
|
-
[$.
|
|
171
|
-
[$._spaced_body_expr, $._yield_value],
|
|
170
|
+
[$._endless_method_rest, $._yield_value],
|
|
172
171
|
[$._endless_command_operand, $._yield_value],
|
|
173
172
|
[$._yield_argument, $._command_argument],
|
|
174
173
|
[$._command_value, $._yield_value, $.pair],
|
|
175
174
|
[$._command_value, $._chained_match_pattern, $._yield_value],
|
|
176
175
|
[$._command_value, $._yield_value],
|
|
177
176
|
[$._yield_value, $.pair],
|
|
178
|
-
[$._yield_value, $.
|
|
177
|
+
[$._yield_value, $._yield_command_pair_head],
|
|
179
178
|
[$._chained_command_argument_list, $.command_argument_list],
|
|
180
179
|
[$._pair_block_argument, $.block_argument],
|
|
181
180
|
[$.command_call_with_block, $._super_command_with_block],
|
|
@@ -264,7 +263,52 @@ module.exports = grammar({
|
|
|
264
263
|
|
|
265
264
|
singleton_method: ($) => singletonMethod($, $._method_rest),
|
|
266
265
|
|
|
267
|
-
_method_rest: ($) =>
|
|
266
|
+
_method_rest: ($) => seq($._method_header, optional(field('body', $.body_statement)), 'end'),
|
|
267
|
+
|
|
268
|
+
// A definition can end wherever an expression can, so the states of a rule ending in its body are copied for each
|
|
269
|
+
// context. The prefixes of definitions are rules of their own so that their states are shared by every context.
|
|
270
|
+
_method_header: ($) =>
|
|
271
|
+
prec.right(
|
|
272
|
+
seq(
|
|
273
|
+
field(
|
|
274
|
+
'name',
|
|
275
|
+
choice($._spaced_definition_name, $._gapless_definition_name, $.setter, alias('[]=', $.operator))
|
|
276
|
+
),
|
|
277
|
+
choice(
|
|
278
|
+
seq(field('parameters', alias($.parameters, $.method_parameters)), optional($._terminator)),
|
|
279
|
+
seq(optional(field('parameters', alias($.bare_parameters, $.method_parameters))), $._body_separator)
|
|
280
|
+
)
|
|
281
|
+
)
|
|
282
|
+
),
|
|
283
|
+
|
|
284
|
+
_endless_method_header: ($) => {
|
|
285
|
+
const parameters = seq(
|
|
286
|
+
field('parameters', alias($.parameters, $.method_parameters)),
|
|
287
|
+
alias($._endless_equals, '=')
|
|
288
|
+
);
|
|
289
|
+
return choice(
|
|
290
|
+
seq(field('name', $._spaced_definition_name), choice(alias($._spaced_endless_equals, '='), parameters)),
|
|
291
|
+
seq(field('name', $._gapless_definition_name), choice(alias($._endless_equals, '='), parameters))
|
|
292
|
+
);
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
_singleton_method_object: ($) =>
|
|
296
|
+
seq(
|
|
297
|
+
choice(
|
|
298
|
+
field('object', choice($._variable, $.self, $._nonlocal_variable)),
|
|
299
|
+
seq('(', field('object', $._arg), ')')
|
|
300
|
+
),
|
|
301
|
+
choice('.', '::')
|
|
302
|
+
),
|
|
303
|
+
|
|
304
|
+
// As in Ruby's grammar, an endless definition is an argument rather than a primary, so it is never the receiver of a
|
|
305
|
+
// call or element reference.
|
|
306
|
+
_endless_method: ($) => seq('def', $._endless_method_rest),
|
|
307
|
+
|
|
308
|
+
_endless_singleton_method: ($) => singletonMethod($, $._endless_method_rest),
|
|
309
|
+
|
|
310
|
+
_endless_method_rest: ($) =>
|
|
311
|
+
seq($._endless_method_header, field('body', endlessBody($, $._arg, $._endless_body_rescue))),
|
|
268
312
|
|
|
269
313
|
rescue_modifier_arg: ($) => prec(PREC.RESCUE, seq(field('body', $._arg), 'rescue', field('handler', $._arg))),
|
|
270
314
|
|
|
@@ -277,12 +321,6 @@ module.exports = grammar({
|
|
|
277
321
|
rescue_modifier_expression: ($) =>
|
|
278
322
|
prec(PREC.RESCUE, seq(field('body', $._non_pattern_expression), 'rescue', field('handler', $._arg))),
|
|
279
323
|
|
|
280
|
-
_body_expr: ($) =>
|
|
281
|
-
seq(alias($._endless_equals, '='), field('body', endlessBody($, $._arg, $._endless_body_rescue))),
|
|
282
|
-
|
|
283
|
-
_spaced_body_expr: ($) =>
|
|
284
|
-
seq(alias($._spaced_endless_equals, '='), field('body', endlessBody($, $._arg, $._endless_body_rescue))),
|
|
285
|
-
|
|
286
324
|
_endless_equals: () => token.immediate(/(?:[ \t\f\v\r]|\\\r?\n)*=/),
|
|
287
325
|
|
|
288
326
|
_spaced_endless_equals: () => token.immediate(/(?:[ \t\f\v\r]|\\\r?\n)+=/),
|
|
@@ -293,7 +331,7 @@ module.exports = grammar({
|
|
|
293
331
|
|
|
294
332
|
_command_singleton_method: ($) => singletonMethod($, $._command_method_rest),
|
|
295
333
|
|
|
296
|
-
_command_method_rest: ($) =>
|
|
334
|
+
_command_method_rest: ($) => seq($._endless_method_header, field('body', $._endless_command)),
|
|
297
335
|
|
|
298
336
|
// Ruby 4.0's default parser (Prism) lets an endless body hold at most one `rescue`, applied outside any `not`; a
|
|
299
337
|
// further `rescue` applies to the whole definition.
|
|
@@ -818,6 +856,8 @@ module.exports = grammar({
|
|
|
818
856
|
choice(
|
|
819
857
|
alias($._unary_minus_pow, $.unary),
|
|
820
858
|
$._primary,
|
|
859
|
+
alias($._endless_method, $.method),
|
|
860
|
+
alias($._endless_singleton_method, $.singleton_method),
|
|
821
861
|
$.operator_assignment,
|
|
822
862
|
$.conditional,
|
|
823
863
|
$.range,
|
|
@@ -836,6 +876,8 @@ module.exports = grammar({
|
|
|
836
876
|
choice(
|
|
837
877
|
alias($._unary_minus_pow, $.unary),
|
|
838
878
|
$._primary,
|
|
879
|
+
alias($._endless_method, $.method),
|
|
880
|
+
alias($._endless_singleton_method, $.singleton_method),
|
|
839
881
|
$.assignment,
|
|
840
882
|
$.operator_assignment,
|
|
841
883
|
$.conditional,
|
|
@@ -1104,7 +1146,8 @@ module.exports = grammar({
|
|
|
1104
1146
|
|
|
1105
1147
|
_yield_singleton_method: ($) => singletonMethod($, $._yield_method_rest),
|
|
1106
1148
|
|
|
1107
|
-
_yield_method_rest: ($) =>
|
|
1149
|
+
_yield_method_rest: ($) =>
|
|
1150
|
+
seq($._endless_method_header, field('body', endlessBody($, $._yield_value, $._yield_method_body_rescue))),
|
|
1108
1151
|
|
|
1109
1152
|
_yield_method_body_rescue: ($) => endlessBodyRescue($, $._yield_value),
|
|
1110
1153
|
|
|
@@ -1150,9 +1193,17 @@ module.exports = grammar({
|
|
|
1150
1193
|
)
|
|
1151
1194
|
),
|
|
1152
1195
|
|
|
1153
|
-
_command_pair: ($) => commandPair($, $.
|
|
1196
|
+
_command_pair: ($) => commandPair($, $._command_pair_head),
|
|
1197
|
+
|
|
1198
|
+
// As with definitions, a pair ends wherever an expression can, so the key and `=>` are rules of their own so that
|
|
1199
|
+
// their states are shared by every context.
|
|
1200
|
+
_super_command_pair_head: ($) => prec.right(PREC.PATTERN, seq(field('key', alias($._super_command, $.call)), '=>')),
|
|
1201
|
+
|
|
1202
|
+
_command_pair_head: ($) => commandPairHead($, $._command_pair_key),
|
|
1203
|
+
|
|
1204
|
+
_yield_command_pair_head: ($) => commandPairHead($, $._yield_command_pair_key, false),
|
|
1154
1205
|
|
|
1155
|
-
_yield_command_pair: ($) => commandPair($, $.
|
|
1206
|
+
_yield_command_pair: ($) => commandPair($, $._yield_command_pair_head),
|
|
1156
1207
|
|
|
1157
1208
|
_yield_command_pair_key: ($) =>
|
|
1158
1209
|
seq(
|
|
@@ -1899,33 +1950,39 @@ function commandCallWithBlock($, receiver, argumentsRule) {
|
|
|
1899
1950
|
|
|
1900
1951
|
/**
|
|
1901
1952
|
* @param {GrammarSymbols<string>} $
|
|
1902
|
-
* @param {RuleOrLiteral}
|
|
1903
|
-
* @param {boolean} allowBlockContinuation
|
|
1953
|
+
* @param {RuleOrLiteral} head
|
|
1904
1954
|
*/
|
|
1905
|
-
function commandPair($,
|
|
1906
|
-
const value = $._arg;
|
|
1955
|
+
function commandPair($, head) {
|
|
1907
1956
|
return prec.dynamic(
|
|
1908
1957
|
1,
|
|
1909
1958
|
choice(
|
|
1910
|
-
prec.right(PREC.PATTERN, seq(
|
|
1911
|
-
prec.right(
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1959
|
+
prec.right(PREC.PATTERN, seq($._super_command_pair_head, field('value', $._arg))),
|
|
1960
|
+
prec.right(seq(head, field('value', $._arg)))
|
|
1961
|
+
)
|
|
1962
|
+
);
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
/**
|
|
1966
|
+
* @param {GrammarSymbols<string>} $
|
|
1967
|
+
* @param {RuleOrLiteral} key
|
|
1968
|
+
* @param {boolean} allowBlockContinuation
|
|
1969
|
+
*/
|
|
1970
|
+
function commandPairHead($, key, allowBlockContinuation = true) {
|
|
1971
|
+
return prec.right(
|
|
1972
|
+
seq(
|
|
1973
|
+
field(
|
|
1974
|
+
'key',
|
|
1975
|
+
choice(
|
|
1976
|
+
alias(key, $.call),
|
|
1977
|
+
alias($._super_command_with_block, $.call),
|
|
1978
|
+
alias($._yield_pair_key, $.yield),
|
|
1979
|
+
alias(allowBlockContinuation ? $._pattern_command_not : $._yield_not, $.unary),
|
|
1980
|
+
alias($._chained_assignment, $.assignment),
|
|
1981
|
+
alias($._chained_operator_assignment, $.operator_assignment),
|
|
1982
|
+
...(allowBlockContinuation ? [$._chained_arg] : [])
|
|
1927
1983
|
)
|
|
1928
|
-
)
|
|
1984
|
+
),
|
|
1985
|
+
'=>'
|
|
1929
1986
|
)
|
|
1930
1987
|
);
|
|
1931
1988
|
}
|
|
@@ -1955,32 +2012,7 @@ function argument($, expression, commandPairRule = $._command_pair) {
|
|
|
1955
2012
|
* @param {RuleOrLiteral} rest
|
|
1956
2013
|
*/
|
|
1957
2014
|
function singletonMethod($, rest) {
|
|
1958
|
-
return seq(
|
|
1959
|
-
'def',
|
|
1960
|
-
seq(
|
|
1961
|
-
choice(
|
|
1962
|
-
field('object', choice($._variable, $.self, $._nonlocal_variable)),
|
|
1963
|
-
seq('(', field('object', $._arg), ')')
|
|
1964
|
-
),
|
|
1965
|
-
choice('.', '::')
|
|
1966
|
-
),
|
|
1967
|
-
rest
|
|
1968
|
-
);
|
|
1969
|
-
}
|
|
1970
|
-
|
|
1971
|
-
/**
|
|
1972
|
-
* @param {GrammarSymbols<string>} $
|
|
1973
|
-
* @param {RuleOrLiteral} body
|
|
1974
|
-
*/
|
|
1975
|
-
function endlessMethodRest($, body) {
|
|
1976
|
-
const parameters = seq(field('parameters', alias($.parameters, $.method_parameters)), alias($._endless_equals, '='));
|
|
1977
|
-
return seq(
|
|
1978
|
-
choice(
|
|
1979
|
-
seq(field('name', $._spaced_definition_name), choice(alias($._spaced_endless_equals, '='), parameters)),
|
|
1980
|
-
seq(field('name', $._gapless_definition_name), choice(alias($._endless_equals, '='), parameters))
|
|
1981
|
-
),
|
|
1982
|
-
field('body', body)
|
|
1983
|
-
);
|
|
2015
|
+
return seq('def', $._singleton_method_object, rest);
|
|
1984
2016
|
}
|
|
1985
2017
|
|
|
1986
2018
|
/**
|
|
@@ -2108,25 +2140,6 @@ function callExpression($, primary, member, allowDoBlock = true) {
|
|
|
2108
2140
|
);
|
|
2109
2141
|
}
|
|
2110
2142
|
|
|
2111
|
-
/**
|
|
2112
|
-
* @param {GrammarSymbols<string>} $
|
|
2113
|
-
* @param {RuleOrLiteral} bodyExpression
|
|
2114
|
-
* @param {RuleOrLiteral} spacedBodyExpression
|
|
2115
|
-
*/
|
|
2116
|
-
function methodRest($, bodyExpression, spacedBodyExpression) {
|
|
2117
|
-
const parameters = field('parameters', alias($.parameters, $.method_parameters));
|
|
2118
|
-
const body = optional(field('body', $.body_statement));
|
|
2119
|
-
const block = choice(
|
|
2120
|
-
seq(parameters, optional($._terminator), body, 'end'),
|
|
2121
|
-
seq(optional(field('parameters', alias($.bare_parameters, $.method_parameters))), $._body_separator, body, 'end')
|
|
2122
|
-
);
|
|
2123
|
-
return choice(
|
|
2124
|
-
seq(field('name', $._spaced_definition_name), choice(block, spacedBodyExpression, seq(parameters, bodyExpression))),
|
|
2125
|
-
seq(field('name', $._gapless_definition_name), choice(block, bodyExpression, seq(parameters, bodyExpression))),
|
|
2126
|
-
seq(field('name', choice($.setter, alias('[]=', $.operator))), block)
|
|
2127
|
-
);
|
|
2128
|
-
}
|
|
2129
|
-
|
|
2130
2143
|
/**
|
|
2131
2144
|
* @param {GrammarSymbols<string>} $
|
|
2132
2145
|
* @param {boolean} allowAssignment
|
package/package.json
CHANGED
package/src/node-types.json
CHANGED
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
"type": "conditional",
|
|
20
20
|
"named": true
|
|
21
21
|
},
|
|
22
|
+
{
|
|
23
|
+
"type": "method",
|
|
24
|
+
"named": true
|
|
25
|
+
},
|
|
22
26
|
{
|
|
23
27
|
"type": "operator_assignment",
|
|
24
28
|
"named": true
|
|
@@ -27,6 +31,10 @@
|
|
|
27
31
|
"type": "range",
|
|
28
32
|
"named": true
|
|
29
33
|
},
|
|
34
|
+
{
|
|
35
|
+
"type": "singleton_method",
|
|
36
|
+
"named": true
|
|
37
|
+
},
|
|
30
38
|
{
|
|
31
39
|
"type": "unary",
|
|
32
40
|
"named": true
|
|
@@ -2481,18 +2489,10 @@
|
|
|
2481
2489
|
"type": "if_modifier",
|
|
2482
2490
|
"named": true
|
|
2483
2491
|
},
|
|
2484
|
-
{
|
|
2485
|
-
"type": "method",
|
|
2486
|
-
"named": true
|
|
2487
|
-
},
|
|
2488
2492
|
{
|
|
2489
2493
|
"type": "scope_resolution",
|
|
2490
2494
|
"named": true
|
|
2491
2495
|
},
|
|
2492
|
-
{
|
|
2493
|
-
"type": "singleton_method",
|
|
2494
|
-
"named": true
|
|
2495
|
-
},
|
|
2496
2496
|
{
|
|
2497
2497
|
"type": "unless_modifier",
|
|
2498
2498
|
"named": true
|
|
@@ -2537,10 +2537,6 @@
|
|
|
2537
2537
|
"type": "element_reference",
|
|
2538
2538
|
"named": true
|
|
2539
2539
|
},
|
|
2540
|
-
{
|
|
2541
|
-
"type": "method",
|
|
2542
|
-
"named": true
|
|
2543
|
-
},
|
|
2544
2540
|
{
|
|
2545
2541
|
"type": "rescue_modifier",
|
|
2546
2542
|
"named": true
|
|
@@ -2553,10 +2549,6 @@
|
|
|
2553
2549
|
"type": "scope_resolution",
|
|
2554
2550
|
"named": true
|
|
2555
2551
|
},
|
|
2556
|
-
{
|
|
2557
|
-
"type": "singleton_method",
|
|
2558
|
-
"named": true
|
|
2559
|
-
},
|
|
2560
2552
|
{
|
|
2561
2553
|
"type": "yield",
|
|
2562
2554
|
"named": true
|
|
@@ -2833,18 +2825,10 @@
|
|
|
2833
2825
|
"type": "hash_key_symbol",
|
|
2834
2826
|
"named": true
|
|
2835
2827
|
},
|
|
2836
|
-
{
|
|
2837
|
-
"type": "method",
|
|
2838
|
-
"named": true
|
|
2839
|
-
},
|
|
2840
2828
|
{
|
|
2841
2829
|
"type": "scope_resolution",
|
|
2842
2830
|
"named": true
|
|
2843
2831
|
},
|
|
2844
|
-
{
|
|
2845
|
-
"type": "singleton_method",
|
|
2846
|
-
"named": true
|
|
2847
|
-
},
|
|
2848
2832
|
{
|
|
2849
2833
|
"type": "string",
|
|
2850
2834
|
"named": true
|
|
@@ -3287,10 +3271,6 @@
|
|
|
3287
3271
|
"type": "element_reference",
|
|
3288
3272
|
"named": true
|
|
3289
3273
|
},
|
|
3290
|
-
{
|
|
3291
|
-
"type": "method",
|
|
3292
|
-
"named": true
|
|
3293
|
-
},
|
|
3294
3274
|
{
|
|
3295
3275
|
"type": "rescue_modifier",
|
|
3296
3276
|
"named": true
|
|
@@ -3303,10 +3283,6 @@
|
|
|
3303
3283
|
"type": "scope_resolution",
|
|
3304
3284
|
"named": true
|
|
3305
3285
|
},
|
|
3306
|
-
{
|
|
3307
|
-
"type": "singleton_method",
|
|
3308
|
-
"named": true
|
|
3309
|
-
},
|
|
3310
3286
|
{
|
|
3311
3287
|
"type": "yield",
|
|
3312
3288
|
"named": true
|
|
@@ -3525,10 +3501,6 @@
|
|
|
3525
3501
|
"type": "if_modifier",
|
|
3526
3502
|
"named": true
|
|
3527
3503
|
},
|
|
3528
|
-
{
|
|
3529
|
-
"type": "method",
|
|
3530
|
-
"named": true
|
|
3531
|
-
},
|
|
3532
3504
|
{
|
|
3533
3505
|
"type": "rescue_modifier",
|
|
3534
3506
|
"named": true
|
|
@@ -3537,10 +3509,6 @@
|
|
|
3537
3509
|
"type": "scope_resolution",
|
|
3538
3510
|
"named": true
|
|
3539
3511
|
},
|
|
3540
|
-
{
|
|
3541
|
-
"type": "singleton_method",
|
|
3542
|
-
"named": true
|
|
3543
|
-
},
|
|
3544
3512
|
{
|
|
3545
3513
|
"type": "unless_modifier",
|
|
3546
3514
|
"named": true
|
package/tree-sitter-ruby.wasm
CHANGED
|
Binary file
|