@willbooster/tree-sitter-ruby 8.0.0 → 10.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 CHANGED
@@ -23,8 +23,8 @@ code instead of aborting the process.
23
23
  ## Support Scope
24
24
 
25
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
26
+ nodes without crashing, hanging, or taking more than linear time. Parse each input without a previous tree; reusing
27
+ an old tree is unsupported. No queries (highlights, locals, injections, tags) are shipped. Node types, field names, and
28
28
  the trees that error recovery produces may change; such changes are released as new major versions.
29
29
 
30
30
  ## Usage
package/grammar.js CHANGED
@@ -168,6 +168,7 @@ module.exports = grammar({
168
168
  [$._yield_pattern_not, $._test_pattern_not],
169
169
  [$._yield_argument_list, $._yield_pair_key_arguments],
170
170
  [$._body_expr, $._yield_value],
171
+ [$._spaced_body_expr, $._yield_value],
171
172
  [$._endless_command_operand, $._yield_value],
172
173
  [$._yield_argument, $._command_argument],
173
174
  [$._command_value, $._yield_value, $.pair],
@@ -263,7 +264,7 @@ module.exports = grammar({
263
264
 
264
265
  singleton_method: ($) => singletonMethod($, $._method_rest),
265
266
 
266
- _method_rest: ($) => methodRest($, $._body_expr),
267
+ _method_rest: ($) => methodRest($, $._body_expr, $._spaced_body_expr),
267
268
 
268
269
  rescue_modifier_arg: ($) => prec(PREC.RESCUE, seq(field('body', $._arg), 'rescue', field('handler', $._arg))),
269
270
 
@@ -276,7 +277,15 @@ module.exports = grammar({
276
277
  rescue_modifier_expression: ($) =>
277
278
  prec(PREC.RESCUE, seq(field('body', $._non_pattern_expression), 'rescue', field('handler', $._arg))),
278
279
 
279
- _body_expr: ($) => seq('=', field('body', endlessBody($, $._arg, $._endless_body_rescue))),
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
+ _endless_equals: () => token.immediate(/(?:[ \t\f\v\r]|\\\r?\n)*=/),
287
+
288
+ _spaced_endless_equals: () => token.immediate(/(?:[ \t\f\v\r]|\\\r?\n)+=/),
280
289
 
281
290
  _endless_body_rescue: ($) => endlessBodyRescue($, $._arg),
282
291
 
@@ -1504,58 +1513,43 @@ module.exports = grammar({
1504
1513
 
1505
1514
  _variable: ($) => prec.right(choice($.super, reserved('variables', $.identifier), $.constant)),
1506
1515
 
1507
- operator: () =>
1508
- choice(
1509
- '..',
1510
- '|',
1511
- '^',
1512
- '&',
1513
- '<=>',
1514
- '==',
1515
- '===',
1516
- '=~',
1517
- '>',
1518
- '>=',
1519
- '<',
1520
- '<=',
1521
- '+',
1522
- '!=',
1523
- '-',
1524
- '*',
1525
- '/',
1526
- '%',
1527
- '!',
1528
- '!~',
1529
- '**',
1530
- '<<',
1531
- '>>',
1532
- '~',
1533
- '+@',
1534
- '-@',
1535
- '~@',
1536
- '[]',
1537
- '[]=',
1538
- '`'
1539
- ),
1516
+ operator: ($) => choice($._nonsetter_operator, '[]='),
1517
+
1518
+ _nonsetter_operator: ($) => choice($._spaced_method_operator, $._gapless_method_operator),
1519
+
1520
+ _spaced_method_operator: () => choice('|', '^', '&', '==', '>', '<', '*', '/', '%', '!', '**', '<<', '>>', '[]'),
1521
+
1522
+ _gapless_method_operator: () =>
1523
+ choice('<=>', '===', '=~', '>=', '<=', '+', '!=', '-', '!@', '!~', '~', '+@', '-@', '~@', '`'),
1540
1524
 
1541
1525
  _method_name: ($) =>
1542
- choice(
1543
- reserved('methodNames', $.identifier),
1544
- $._function_identifier,
1545
- $.constant,
1546
- $.setter,
1547
- $.simple_symbol,
1548
- $.delimited_symbol,
1549
- $.operator,
1550
- $._nonlocal_variable
1551
- ),
1526
+ choice($._nonsetter_method_name, $.setter, alias('[]=', $.operator), $.simple_symbol, $.delimited_symbol),
1527
+
1528
+ _nonsetter_method_name: ($) => choice($._spaced_definition_name, $._gapless_definition_name),
1529
+
1530
+ _spaced_definition_name: ($) =>
1531
+ choice($._method_identifier, $._function_identifier, $.constant, alias($._spaced_method_operator, $.operator)),
1532
+
1533
+ _gapless_definition_name: ($) => alias($._gapless_method_operator, $.operator),
1534
+
1535
+ _method_identifier: ($) =>
1536
+ choice(reserved('methodNames', $.identifier), alias($.self, $.identifier), alias($.super, $.identifier)),
1552
1537
 
1553
1538
  _nonlocal_variable: ($) => choice($.instance_variable, $.class_variable, $.global_variable),
1554
1539
 
1555
- setter: ($) => seq(field('name', $.identifier), token.immediate('=')),
1540
+ setter: ($) =>
1541
+ seq(field('name', choice($._method_identifier, alias($.constant, $.identifier))), token.immediate('=')),
1556
1542
 
1557
1543
  undef: ($) => seq('undef', commaSep1($._method_name)),
1558
- alias: ($) => seq('alias', field('name', $._method_name), field('alias', $._method_name)),
1544
+ alias: ($) =>
1545
+ choice(
1546
+ seq('alias', field('name', $._method_name), field('alias', $._method_name)),
1547
+ seq(
1548
+ 'alias',
1549
+ field('name', $.global_variable),
1550
+ field('alias', alias($._alias_global_variable, $.global_variable))
1551
+ )
1552
+ ),
1559
1553
 
1560
1554
  comment: ($) => choice($._line_comment, $._block_comment, token(prec(PREC.COMMENT, seq('#', /.*/)))),
1561
1555
 
@@ -1582,10 +1576,14 @@ module.exports = grammar({
1582
1576
  instance_variable: () => token(seq('@', ALPHA_CHAR, IDENTIFIER_CHARS)),
1583
1577
  class_variable: () => token(seq('@@', ALPHA_CHAR, IDENTIFIER_CHARS)),
1584
1578
 
1585
- global_variable: () =>
1579
+ global_variable: ($) => choice($._named_global_variable, /\$[0-9]+/),
1580
+
1581
+ _alias_global_variable: ($) => choice($._named_global_variable, '$0'),
1582
+
1583
+ _named_global_variable: () =>
1586
1584
  token(
1587
1585
  choice(
1588
- /\$(-[a-zA-Z0-9_]|[!@&`'+~=/\\,;.<>*$?:"]|[0-9]+)/,
1586
+ /\$(-[a-zA-Z0-9_]|[!@&`'+~=/\\,;.<>*$?:"])/,
1589
1587
  seq('$-', /[^\u0000-\u007F]/),
1590
1588
  seq('$', ALPHA_CHAR, IDENTIFIER_CHARS)
1591
1589
  )
@@ -1975,10 +1973,12 @@ function singletonMethod($, rest) {
1975
1973
  * @param {RuleOrLiteral} body
1976
1974
  */
1977
1975
  function endlessMethodRest($, body) {
1976
+ const parameters = seq(field('parameters', alias($.parameters, $.method_parameters)), alias($._endless_equals, '='));
1978
1977
  return seq(
1979
- field('name', $._method_name),
1980
- optional(field('parameters', alias($.parameters, $.method_parameters))),
1981
- '=',
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
1982
  field('body', body)
1983
1983
  );
1984
1984
  }
@@ -2111,23 +2111,19 @@ function callExpression($, primary, member, allowDoBlock = true) {
2111
2111
  /**
2112
2112
  * @param {GrammarSymbols<string>} $
2113
2113
  * @param {RuleOrLiteral} bodyExpression
2114
+ * @param {RuleOrLiteral} spacedBodyExpression
2114
2115
  */
2115
- function methodRest($, bodyExpression) {
2116
- return seq(
2117
- field('name', $._method_name),
2118
- choice(
2119
- bodyExpression,
2120
- seq(
2121
- field('parameters', alias($.parameters, $.method_parameters)),
2122
- choice(seq(optional($._terminator), optional(field('body', $.body_statement)), 'end'), bodyExpression)
2123
- ),
2124
- seq(
2125
- optional(field('parameters', alias($.bare_parameters, $.method_parameters))),
2126
- $._body_separator,
2127
- optional(field('body', $.body_statement)),
2128
- 'end'
2129
- )
2130
- )
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)
2131
2127
  );
2132
2128
  }
2133
2129
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-ruby",
3
- "version": "8.0.0",
3
+ "version": "10.0.0",
4
4
  "description": "Ruby grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -161,10 +161,6 @@
161
161
  "type": "_method_name",
162
162
  "named": true,
163
163
  "subtypes": [
164
- {
165
- "type": "_nonlocal_variable",
166
- "named": true
167
- },
168
164
  {
169
165
  "type": "constant",
170
166
  "named": true
@@ -642,6 +638,10 @@
642
638
  {
643
639
  "type": "_method_name",
644
640
  "named": true
641
+ },
642
+ {
643
+ "type": "global_variable",
644
+ "named": true
645
645
  }
646
646
  ]
647
647
  },
@@ -652,6 +652,10 @@
652
652
  {
653
653
  "type": "_method_name",
654
654
  "named": true
655
+ },
656
+ {
657
+ "type": "global_variable",
658
+ "named": true
655
659
  }
656
660
  ]
657
661
  }
@@ -1984,6 +1988,11 @@
1984
1988
  "named": true,
1985
1989
  "fields": {}
1986
1990
  },
1991
+ {
1992
+ "type": "global_variable",
1993
+ "named": true,
1994
+ "fields": {}
1995
+ },
1987
1996
  {
1988
1997
  "type": "hash",
1989
1998
  "named": true,
@@ -2559,7 +2568,19 @@
2559
2568
  "required": true,
2560
2569
  "types": [
2561
2570
  {
2562
- "type": "_method_name",
2571
+ "type": "constant",
2572
+ "named": true
2573
+ },
2574
+ {
2575
+ "type": "identifier",
2576
+ "named": true
2577
+ },
2578
+ {
2579
+ "type": "operator",
2580
+ "named": true
2581
+ },
2582
+ {
2583
+ "type": "setter",
2563
2584
  "named": true
2564
2585
  }
2565
2586
  ]
@@ -3297,7 +3318,19 @@
3297
3318
  "required": true,
3298
3319
  "types": [
3299
3320
  {
3300
- "type": "_method_name",
3321
+ "type": "constant",
3322
+ "named": true
3323
+ },
3324
+ {
3325
+ "type": "identifier",
3326
+ "named": true
3327
+ },
3328
+ {
3329
+ "type": "operator",
3330
+ "named": true
3331
+ },
3332
+ {
3333
+ "type": "setter",
3301
3334
  "named": true
3302
3335
  }
3303
3336
  ]
@@ -3880,6 +3913,10 @@
3880
3913
  "type": "!=",
3881
3914
  "named": false
3882
3915
  },
3916
+ {
3917
+ "type": "!@",
3918
+ "named": false
3919
+ },
3883
3920
  {
3884
3921
  "type": "!~",
3885
3922
  "named": false
@@ -3892,6 +3929,10 @@
3892
3929
  "type": "#{",
3893
3930
  "named": false
3894
3931
  },
3932
+ {
3933
+ "type": "$0",
3934
+ "named": false
3935
+ },
3895
3936
  {
3896
3937
  "type": "%",
3897
3938
  "named": false
@@ -4204,10 +4245,6 @@
4204
4245
  "type": "for",
4205
4246
  "named": false
4206
4247
  },
4207
- {
4208
- "type": "global_variable",
4209
- "named": true
4210
- },
4211
4248
  {
4212
4249
  "type": "heredoc_beginning",
4213
4250
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -13,7 +13,7 @@
13
13
  }
14
14
  ],
15
15
  "metadata": {
16
- "version": "8.0.0",
16
+ "version": "10.0.0",
17
17
  "license": "MIT",
18
18
  "description": "Ruby grammar for tree-sitter",
19
19
  "authors": [