@willbooster/tree-sitter-ruby 3.0.4 → 3.0.6

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
@@ -86,6 +86,7 @@ module.exports = grammar({
86
86
  $._block_comment,
87
87
  $._uninterpreted,
88
88
  $._not_parenthesized,
89
+ $._lambda_brace,
89
90
  ],
90
91
 
91
92
  extras: ($) => [$.comment, $.heredoc_body, /\s/, /\\\r?\n/],
@@ -1206,10 +1207,20 @@ module.exports = grammar({
1206
1207
  PREC.CURLY_BLOCK,
1207
1208
  prec.dynamic(
1208
1209
  2,
1209
- seq('{', field('parameters', optional($.block_parameters)), optional(field('body', $.block_body)), '}')
1210
+ seq(
1211
+ $._block_open,
1212
+ field('parameters', optional($.block_parameters)),
1213
+ optional(field('body', $.block_body)),
1214
+ '}'
1215
+ )
1210
1216
  )
1211
1217
  ),
1212
1218
 
1219
+ // Where both a block and a hash argument can start (`foo {`, `x.y {`), the `{` would otherwise be shared until a
1220
+ // later conflict picks the hash. Reducing the brace on its own forces the choice right after it, and the precedence
1221
+ // makes it a block, as in Ruby.
1222
+ _block_open: () => prec(PREC.CURLY_BLOCK, '{'),
1223
+
1213
1224
  _arg_rhs: ($) => choice($._arg, alias($.rescue_modifier_arg, $.rescue_modifier)),
1214
1225
 
1215
1226
  _ordinary_rhs_expression: ($) => prec(PREC.ASSIGN, $._arg_rhs),
@@ -1666,7 +1677,18 @@ module.exports = grammar({
1666
1677
  )
1667
1678
  )
1668
1679
  ),
1669
- field('body', choice($.block, $.do_block))
1680
+ field('body', choice(alias($._lambda_block, $.block), $.do_block))
1681
+ ),
1682
+
1683
+ // As with parse.y's tLAMBEG, the scanner emits this `{` where a lambda body can start, so that it opens the body
1684
+ // after bare parameters even where a parameter default could take a block or start a hash (`-> a=b() { }`,
1685
+ // `-> x: { }`).
1686
+ _lambda_block: ($) =>
1687
+ seq(
1688
+ alias($._lambda_brace, '{'),
1689
+ field('parameters', optional($.block_parameters)),
1690
+ optional(field('body', $.block_body)),
1691
+ '}'
1670
1692
  ),
1671
1693
 
1672
1694
  _parenthesized_lambda_parameters: ($) =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-ruby",
3
- "version": "3.0.4",
3
+ "version": "3.0.6",
4
4
  "description": "Ruby grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
Binary file
package/tree-sitter.json CHANGED
@@ -19,7 +19,7 @@
19
19
  }
20
20
  ],
21
21
  "metadata": {
22
- "version": "3.0.4",
22
+ "version": "3.0.6",
23
23
  "license": "MIT",
24
24
  "description": "Ruby grammar for tree-sitter",
25
25
  "authors": [