@willbooster/tree-sitter-ruby 11.0.1 → 13.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 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, $._command_pair],
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
- [$._body_expr, $._yield_value],
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, $._yield_command_pair],
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,53 @@ module.exports = grammar({
264
263
 
265
264
  singleton_method: ($) => singletonMethod($, $._method_rest),
266
265
 
267
- _method_rest: ($) => methodRest($, $._body_expr, $._spaced_body_expr),
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(field('parameters', alias($.bare_parameters, $.method_parameters)), $._terminator),
280
+ $._body_separator
281
+ )
282
+ )
283
+ ),
284
+
285
+ _endless_method_header: ($) => {
286
+ const parameters = seq(
287
+ field('parameters', alias($.parameters, $.method_parameters)),
288
+ alias($._endless_equals, '=')
289
+ );
290
+ return choice(
291
+ seq(field('name', $._spaced_definition_name), choice(alias($._spaced_endless_equals, '='), parameters)),
292
+ seq(field('name', $._gapless_definition_name), choice(alias($._endless_equals, '='), parameters))
293
+ );
294
+ },
295
+
296
+ _singleton_method_object: ($) =>
297
+ seq(
298
+ choice(
299
+ field('object', choice($._variable, $.self, $._nonlocal_variable)),
300
+ seq('(', field('object', $._arg), ')')
301
+ ),
302
+ choice('.', '::')
303
+ ),
304
+
305
+ // As in Ruby's grammar, an endless definition is an argument rather than a primary, so it is never the receiver of a
306
+ // call or element reference.
307
+ _endless_method: ($) => seq('def', $._endless_method_rest),
308
+
309
+ _endless_singleton_method: ($) => singletonMethod($, $._endless_method_rest),
310
+
311
+ _endless_method_rest: ($) =>
312
+ seq($._endless_method_header, field('body', endlessBody($, $._arg, $._endless_body_rescue))),
268
313
 
269
314
  rescue_modifier_arg: ($) => prec(PREC.RESCUE, seq(field('body', $._arg), 'rescue', field('handler', $._arg))),
270
315
 
@@ -277,12 +322,6 @@ module.exports = grammar({
277
322
  rescue_modifier_expression: ($) =>
278
323
  prec(PREC.RESCUE, seq(field('body', $._non_pattern_expression), 'rescue', field('handler', $._arg))),
279
324
 
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
325
  _endless_equals: () => token.immediate(/(?:[ \t\f\v\r]|\\\r?\n)*=/),
287
326
 
288
327
  _spaced_endless_equals: () => token.immediate(/(?:[ \t\f\v\r]|\\\r?\n)+=/),
@@ -293,7 +332,7 @@ module.exports = grammar({
293
332
 
294
333
  _command_singleton_method: ($) => singletonMethod($, $._command_method_rest),
295
334
 
296
- _command_method_rest: ($) => endlessMethodRest($, $._endless_command),
335
+ _command_method_rest: ($) => seq($._endless_method_header, field('body', $._endless_command)),
297
336
 
298
337
  // Ruby 4.0's default parser (Prism) lets an endless body hold at most one `rescue`, applied outside any `not`; a
299
338
  // further `rescue` applies to the whole definition.
@@ -362,7 +401,7 @@ module.exports = grammar({
362
401
  seq(
363
402
  'class',
364
403
  field('name', choice($.constant, $.scope_resolution)),
365
- choice(seq(field('superclass', $.superclass), $._body_separator), optional($._terminator)),
404
+ choice(seq(field('superclass', $.superclass), $._terminator), optional($._terminator)),
366
405
  optional(field('body', $.body_statement)),
367
406
  'end'
368
407
  ),
@@ -374,7 +413,7 @@ module.exports = grammar({
374
413
  'class',
375
414
  alias($._singleton_class_left_angle_left_langle, '<<'),
376
415
  field('value', $._arg),
377
- $._body_separator,
416
+ $._terminator,
378
417
  optional(field('body', $.body_statement)),
379
418
  'end'
380
419
  ),
@@ -818,6 +857,8 @@ module.exports = grammar({
818
857
  choice(
819
858
  alias($._unary_minus_pow, $.unary),
820
859
  $._primary,
860
+ alias($._endless_method, $.method),
861
+ alias($._endless_singleton_method, $.singleton_method),
821
862
  $.operator_assignment,
822
863
  $.conditional,
823
864
  $.range,
@@ -836,6 +877,8 @@ module.exports = grammar({
836
877
  choice(
837
878
  alias($._unary_minus_pow, $.unary),
838
879
  $._primary,
880
+ alias($._endless_method, $.method),
881
+ alias($._endless_singleton_method, $.singleton_method),
839
882
  $.assignment,
840
883
  $.operator_assignment,
841
884
  $.conditional,
@@ -1104,7 +1147,8 @@ module.exports = grammar({
1104
1147
 
1105
1148
  _yield_singleton_method: ($) => singletonMethod($, $._yield_method_rest),
1106
1149
 
1107
- _yield_method_rest: ($) => endlessMethodRest($, endlessBody($, $._yield_value, $._yield_method_body_rescue)),
1150
+ _yield_method_rest: ($) =>
1151
+ seq($._endless_method_header, field('body', endlessBody($, $._yield_value, $._yield_method_body_rescue))),
1108
1152
 
1109
1153
  _yield_method_body_rescue: ($) => endlessBodyRescue($, $._yield_value),
1110
1154
 
@@ -1150,9 +1194,17 @@ module.exports = grammar({
1150
1194
  )
1151
1195
  ),
1152
1196
 
1153
- _command_pair: ($) => commandPair($, $._command_pair_key),
1197
+ _command_pair: ($) => commandPair($, $._command_pair_head),
1198
+
1199
+ // As with definitions, a pair ends wherever an expression can, so the key and `=>` are rules of their own so that
1200
+ // their states are shared by every context.
1201
+ _super_command_pair_head: ($) => prec.right(PREC.PATTERN, seq(field('key', alias($._super_command, $.call)), '=>')),
1202
+
1203
+ _command_pair_head: ($) => commandPairHead($, $._command_pair_key),
1204
+
1205
+ _yield_command_pair_head: ($) => commandPairHead($, $._yield_command_pair_key, false),
1154
1206
 
1155
- _yield_command_pair: ($) => commandPair($, $._yield_command_pair_key, false),
1207
+ _yield_command_pair: ($) => commandPair($, $._yield_command_pair_head),
1156
1208
 
1157
1209
  _yield_command_pair_key: ($) =>
1158
1210
  seq(
@@ -1710,6 +1762,9 @@ module.exports = grammar({
1710
1762
 
1711
1763
  empty_statement: () => prec(-1, ';'),
1712
1764
 
1765
+ // The scanner emits comments after this line break into the body even when only comments precede `end`. It follows
1766
+ // only a method name: after an expression, its validity would split the states of every expression from those of
1767
+ // other contexts.
1713
1768
  _body_separator: ($) => choice(prec.dynamic(1, $._body_line_break), ';'),
1714
1769
 
1715
1770
  _terminator: ($) => choice(prec.dynamic(1, $._line_break), ';'),
@@ -1899,33 +1954,39 @@ function commandCallWithBlock($, receiver, argumentsRule) {
1899
1954
 
1900
1955
  /**
1901
1956
  * @param {GrammarSymbols<string>} $
1902
- * @param {RuleOrLiteral} key
1903
- * @param {boolean} allowBlockContinuation
1957
+ * @param {RuleOrLiteral} head
1904
1958
  */
1905
- function commandPair($, key, allowBlockContinuation = true) {
1906
- const value = $._arg;
1959
+ function commandPair($, head) {
1907
1960
  return prec.dynamic(
1908
1961
  1,
1909
1962
  choice(
1910
- prec.right(PREC.PATTERN, seq(field('key', alias($._super_command, $.call)), '=>', field('value', value))),
1911
- prec.right(
1912
- seq(
1913
- field(
1914
- 'key',
1915
- choice(
1916
- alias(key, $.call),
1917
- alias($._super_command_with_block, $.call),
1918
- alias($._yield_pair_key, $.yield),
1919
- alias(allowBlockContinuation ? $._pattern_command_not : $._yield_not, $.unary),
1920
- alias($._chained_assignment, $.assignment),
1921
- alias($._chained_operator_assignment, $.operator_assignment),
1922
- ...(allowBlockContinuation ? [$._chained_arg] : [])
1923
- )
1924
- ),
1925
- '=>',
1926
- field('value', value)
1963
+ prec.right(PREC.PATTERN, seq($._super_command_pair_head, field('value', $._arg))),
1964
+ prec.right(seq(head, field('value', $._arg)))
1965
+ )
1966
+ );
1967
+ }
1968
+
1969
+ /**
1970
+ * @param {GrammarSymbols<string>} $
1971
+ * @param {RuleOrLiteral} key
1972
+ * @param {boolean} allowBlockContinuation
1973
+ */
1974
+ function commandPairHead($, key, allowBlockContinuation = true) {
1975
+ return prec.right(
1976
+ seq(
1977
+ field(
1978
+ 'key',
1979
+ choice(
1980
+ alias(key, $.call),
1981
+ alias($._super_command_with_block, $.call),
1982
+ alias($._yield_pair_key, $.yield),
1983
+ alias(allowBlockContinuation ? $._pattern_command_not : $._yield_not, $.unary),
1984
+ alias($._chained_assignment, $.assignment),
1985
+ alias($._chained_operator_assignment, $.operator_assignment),
1986
+ ...(allowBlockContinuation ? [$._chained_arg] : [])
1927
1987
  )
1928
- )
1988
+ ),
1989
+ '=>'
1929
1990
  )
1930
1991
  );
1931
1992
  }
@@ -1955,32 +2016,7 @@ function argument($, expression, commandPairRule = $._command_pair) {
1955
2016
  * @param {RuleOrLiteral} rest
1956
2017
  */
1957
2018
  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
- );
2019
+ return seq('def', $._singleton_method_object, rest);
1984
2020
  }
1985
2021
 
1986
2022
  /**
@@ -2108,25 +2144,6 @@ function callExpression($, primary, member, allowDoBlock = true) {
2108
2144
  );
2109
2145
  }
2110
2146
 
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
2147
  /**
2131
2148
  * @param {GrammarSymbols<string>} $
2132
2149
  * @param {boolean} allowAssignment
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-ruby",
3
- "version": "11.0.1",
3
+ "version": "13.0.0",
4
4
  "description": "Ruby grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -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
Binary file
package/tree-sitter.json CHANGED
@@ -13,7 +13,7 @@
13
13
  }
14
14
  ],
15
15
  "metadata": {
16
- "version": "11.0.1",
16
+ "version": "13.0.0",
17
17
  "license": "MIT",
18
18
  "description": "Ruby grammar for tree-sitter",
19
19
  "authors": [