@willbooster/tree-sitter-c-sharp 1.0.10 → 1.0.12

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
@@ -1205,7 +1205,9 @@ module.exports = grammar({
1205
1205
 
1206
1206
  assignment_expression: ($) =>
1207
1207
  seq(
1208
- field('left', $.lvalue_expression),
1208
+ // An invocation can return a reference (`Unsafe.Add(ref x, i) = v`). It ends with `)`, so `=` after it adds few
1209
+ // parse states, unlike making any expression assignable.
1210
+ field('left', choice($.lvalue_expression, $.invocation_expression)),
1209
1211
  field('operator', choice('=', '+=', '-=', '*=', '/=', '%=', '&=', '^=', '|=', '<<=', '>>=', '>>>=', '??=')),
1210
1212
  field('right', $.expression)
1211
1213
  ),
@@ -1251,19 +1253,15 @@ module.exports = grammar({
1251
1253
 
1252
1254
  postfix_unary_expression: ($) => prec(PREC.POSTFIX, seq(postfixOperand($), choice('++', '--', '!'))),
1253
1255
 
1256
+ // `&` and `*` have rules of their own (`_address_of_expression`, `_pointer_indirection_expression`, and
1257
+ // `_value_indirection_expression`), aliased to this node. The dynamic precedence of `+`, `-`, and `^` is explained
1258
+ // at `_pointer_indirection_expression`.
1254
1259
  prefix_unary_expression: ($) =>
1255
1260
  prec(
1256
1261
  PREC.UNARY,
1257
- seq(
1258
- // `&` and `*` are intentionally NOT in this choice list:
1259
- // * `&` → `_address_of_expression` (operand restricted to lvalue
1260
- // — see comment on that rule for the #413 rationale)
1261
- // * `*` → `_pointer_indirection_expression` and
1262
- // `_value_indirection_expression`
1263
- // They are aliased back to `prefix_unary_expression` so the
1264
- // public AST is unaffected.
1265
- choice('++', '--', '+', '-', '!', '~', '^'),
1266
- $.expression
1262
+ choice(
1263
+ seq(choice('++', '--', '!', '~'), $.expression),
1264
+ prec.dynamic(-2, seq(choice('+', '-', '^'), $.expression))
1267
1265
  )
1268
1266
  ),
1269
1267
 
@@ -1275,12 +1273,13 @@ module.exports = grammar({
1275
1273
  // form's operand lets `=` follow every expression that can be the operand, which grows the parser by about 4,800
1276
1274
  // states and nearly doubles the Wasm build, while these operands add about 550.
1277
1275
  //
1278
- // Dynamic precedences: an assignable dereference -2, a read-only one -4, a read-only cast +1, and an assignable cast
1279
- // -1. C# reads a parenthesized name as a cast only when the token after `)` is `~`, `!`, `(`, an identifier, a
1280
- // literal, or a keyword (C# spec §12.9.8 Cast expressions), and these values keep that reading: `(a) * b` is a
1281
- // multiplication (0), not a cast of `*b` (+1 - 2); `*(p) + 1` and `*(p) & x` apply to a dereference of `(p)` (-2),
1282
- // not to a dereference of a cast of `+1` or `&x` (-4 + 1 or -2 - 1); `*(b)[0]` dereferences an element access
1283
- // (-2), not a cast of `[0]` (-2 - 1). Where both casts fit, they give the same tree.
1276
+ // Dynamic precedences: an assignable dereference -2, a read-only one -4, a read-only cast +1, an assignable cast -1,
1277
+ // and a unary `+`, `-`, `^`, or `&` -2. C# reads a parenthesized name as a cast only when the token after `)` is
1278
+ // `~`, `!`, `(`, an identifier, a literal, or a keyword (C# spec §12.9.8 Cast expressions), and these values keep
1279
+ // that reading: `(a) * b`, `(a) - b`, and `(a) & b` are binary expressions (0), not casts of `*b`, `-b`, or `&b`
1280
+ // (+1 - 2); `*(p) + 1` and `*(p) & x` apply to a dereference of `(p)` (-2), not to a dereference of a cast of `+1`
1281
+ // or `&x` (-5); `*(b)[0]` dereferences an element access (-2), not a cast of `[0]` (-3). Where both casts fit, they
1282
+ // give the same tree.
1284
1283
  _pointer_indirection_expression: ($) =>
1285
1284
  prec.dynamic(
1286
1285
  -2,
@@ -1327,9 +1326,10 @@ module.exports = grammar({
1327
1326
  // Address-of is split out from `prefix_unary_expression` and takes only a variable: an lvalue, or an invocation,
1328
1327
  // which can return a reference (`&span.GetPinnableReference()`). If a cast could take `&` before any expression,
1329
1328
  // the lexer would split `&&` into two `&` tokens and `(a) && (b > 0)` would read as a cast of `&(&(b > 0))`; as
1330
- // `(b > 0)` is not a variable, that reading fails and `&&` stays one token.
1329
+ // `(b > 0)` is not a variable, that reading fails and `&&` stays one token. The dynamic precedence is explained at
1330
+ // `_pointer_indirection_expression`.
1331
1331
  _address_of_expression: ($) =>
1332
- prec.right(PREC.UNARY, seq('&', choice($.lvalue_expression, $.invocation_expression))),
1332
+ prec.dynamic(-2, prec.right(PREC.UNARY, seq('&', choice($.lvalue_expression, $.invocation_expression)))),
1333
1333
 
1334
1334
  query_expression: ($) => seq($.from_clause, $._query_body),
1335
1335
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c-sharp",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "C# grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -1006,6 +1006,10 @@
1006
1006
  "multiple": false,
1007
1007
  "required": true,
1008
1008
  "types": [
1009
+ {
1010
+ "type": "invocation_expression",
1011
+ "named": true
1012
+ },
1009
1013
  {
1010
1014
  "type": "lvalue_expression",
1011
1015
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -19,7 +19,7 @@
19
19
  }
20
20
  ],
21
21
  "metadata": {
22
- "version": "1.0.10",
22
+ "version": "1.0.12",
23
23
  "license": "MIT",
24
24
  "description": "C# grammar for tree-sitter",
25
25
  "authors": [