@willbooster/tree-sitter-c-sharp 1.0.9 → 1.0.11

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
@@ -83,6 +83,7 @@ module.exports = grammar({
83
83
  [$.constant_pattern, $.lvalue_expression, $._name],
84
84
 
85
85
  [$.type, $._name_invocation_pattern, $.recursive_pattern],
86
+ [$.type, $.recursive_pattern],
86
87
  [$.attribute, $.type, $._name_invocation_pattern, $.recursive_pattern],
87
88
 
88
89
  [$.parenthesized_pattern, $._parenthesized_pattern_with_designation],
@@ -1082,10 +1083,15 @@ module.exports = grammar({
1082
1083
  prec.dynamic(1, seq($.positional_pattern_clause, $._simple_designation)),
1083
1084
  // positional pattern without variable designation (no type prefix)
1084
1085
  $.positional_pattern_clause,
1085
- // other type followed by pattern clauses (type is required here to avoid ambiguity)
1086
+ // other type followed by a property pattern clause
1087
+ seq(field('type', $.type), $.property_pattern_clause, optional($._simple_designation)),
1088
+ // A positional clause follows only a name (above), a predefined type, or an array type. Letting any type take
1089
+ // one reads `Name(A.B)` once more, through `type`; after a syntax error, the extra GLR versions then exceed
1090
+ // the runtime's limit, and which reading survives depends on the versions alive, not on dynamic precedence.
1086
1091
  seq(
1087
- field('type', $.type),
1088
- choice(seq($.positional_pattern_clause, optional($.property_pattern_clause)), $.property_pattern_clause),
1092
+ field('type', choice($.predefined_type, $.array_type)),
1093
+ $.positional_pattern_clause,
1094
+ optional($.property_pattern_clause),
1089
1095
  optional($._simple_designation)
1090
1096
  ),
1091
1097
  // no type, just pattern clauses (no variable designation to avoid conflict with above)
@@ -1245,19 +1251,15 @@ module.exports = grammar({
1245
1251
 
1246
1252
  postfix_unary_expression: ($) => prec(PREC.POSTFIX, seq(postfixOperand($), choice('++', '--', '!'))),
1247
1253
 
1254
+ // `&` and `*` have rules of their own (`_address_of_expression`, `_pointer_indirection_expression`, and
1255
+ // `_value_indirection_expression`), aliased to this node. The dynamic precedence of `+`, `-`, and `^` is explained
1256
+ // at `_pointer_indirection_expression`.
1248
1257
  prefix_unary_expression: ($) =>
1249
1258
  prec(
1250
1259
  PREC.UNARY,
1251
- seq(
1252
- // `&` and `*` are intentionally NOT in this choice list:
1253
- // * `&` → `_address_of_expression` (operand restricted to lvalue
1254
- // — see comment on that rule for the #413 rationale)
1255
- // * `*` → `_pointer_indirection_expression` and
1256
- // `_value_indirection_expression`
1257
- // They are aliased back to `prefix_unary_expression` so the
1258
- // public AST is unaffected.
1259
- choice('++', '--', '+', '-', '!', '~', '^'),
1260
- $.expression
1260
+ choice(
1261
+ seq(choice('++', '--', '!', '~'), $.expression),
1262
+ prec.dynamic(-2, seq(choice('+', '-', '^'), $.expression))
1261
1263
  )
1262
1264
  ),
1263
1265
 
@@ -1269,12 +1271,13 @@ module.exports = grammar({
1269
1271
  // form's operand lets `=` follow every expression that can be the operand, which grows the parser by about 4,800
1270
1272
  // states and nearly doubles the Wasm build, while these operands add about 550.
1271
1273
  //
1272
- // Dynamic precedences: an assignable dereference -2, a read-only one -4, a read-only cast +1, and an assignable cast
1273
- // -1. C# reads a parenthesized name as a cast only when the token after `)` is `~`, `!`, `(`, an identifier, a
1274
- // literal, or a keyword (C# spec §12.9.8 Cast expressions), and these values keep that reading: `(a) * b` is a
1275
- // multiplication (0), not a cast of `*b` (+1 - 2); `*(p) + 1` and `*(p) & x` apply to a dereference of `(p)` (-2),
1276
- // not to a dereference of a cast of `+1` or `&x` (-4 + 1 or -2 - 1); `*(b)[0]` dereferences an element access
1277
- // (-2), not a cast of `[0]` (-2 - 1). Where both casts fit, they give the same tree.
1274
+ // Dynamic precedences: an assignable dereference -2, a read-only one -4, a read-only cast +1, an assignable cast -1,
1275
+ // and a unary `+`, `-`, `^`, or `&` -2. C# reads a parenthesized name as a cast only when the token after `)` is
1276
+ // `~`, `!`, `(`, an identifier, a literal, or a keyword (C# spec §12.9.8 Cast expressions), and these values keep
1277
+ // that reading: `(a) * b`, `(a) - b`, and `(a) & b` are binary expressions (0), not casts of `*b`, `-b`, or `&b`
1278
+ // (+1 - 2); `*(p) + 1` and `*(p) & x` apply to a dereference of `(p)` (-2), not to a dereference of a cast of `+1`
1279
+ // or `&x` (-5); `*(b)[0]` dereferences an element access (-2), not a cast of `[0]` (-3). Where both casts fit, they
1280
+ // give the same tree.
1278
1281
  _pointer_indirection_expression: ($) =>
1279
1282
  prec.dynamic(
1280
1283
  -2,
@@ -1321,9 +1324,10 @@ module.exports = grammar({
1321
1324
  // Address-of is split out from `prefix_unary_expression` and takes only a variable: an lvalue, or an invocation,
1322
1325
  // which can return a reference (`&span.GetPinnableReference()`). If a cast could take `&` before any expression,
1323
1326
  // the lexer would split `&&` into two `&` tokens and `(a) && (b > 0)` would read as a cast of `&(&(b > 0))`; as
1324
- // `(b > 0)` is not a variable, that reading fails and `&&` stays one token.
1327
+ // `(b > 0)` is not a variable, that reading fails and `&&` stays one token. The dynamic precedence is explained at
1328
+ // `_pointer_indirection_expression`.
1325
1329
  _address_of_expression: ($) =>
1326
- prec.right(PREC.UNARY, seq('&', choice($.lvalue_expression, $.invocation_expression))),
1330
+ prec.dynamic(-2, prec.right(PREC.UNARY, seq('&', choice($.lvalue_expression, $.invocation_expression)))),
1327
1331
 
1328
1332
  query_expression: ($) => seq($.from_clause, $._query_body),
1329
1333
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c-sharp",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "C# 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": "1.0.9",
22
+ "version": "1.0.11",
23
23
  "license": "MIT",
24
24
  "description": "C# grammar for tree-sitter",
25
25
  "authors": [