@willbooster/tree-sitter-c-sharp 15.0.0 → 15.0.2

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
@@ -5,7 +5,7 @@
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-c-sharp/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-c-sharp/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-c-sharp/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-c-sharp/actions/workflows/test-rust.yml)
7
7
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
8
- [![wbfy](https://img.shields.io/badge/wbfy-20.43.2-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.48.9-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
9
  [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-c-sharp.svg)](https://crates.io/crates/willbooster-tree-sitter-c-sharp)
10
10
 
11
11
  C# grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
@@ -48,6 +48,7 @@ In Node.js and Bun, load it from the package:
48
48
 
49
49
  ```js
50
50
  import { fileURLToPath } from 'node:url';
51
+
51
52
  import { Language, Parser } from '@willbooster/web-tree-sitter';
52
53
 
53
54
  await Parser.init();
@@ -60,9 +61,9 @@ const tree = parser.parse('class Program {}\n');
60
61
  In browsers, serve both `.wasm` files and load them by URL. With Vite:
61
62
 
62
63
  ```js
64
+ import cSharpUrl from '@willbooster/tree-sitter-c-sharp/tree-sitter-c_sharp.wasm?url';
63
65
  import { Language, Parser } from '@willbooster/web-tree-sitter';
64
66
  import runtimeUrl from '@willbooster/web-tree-sitter/web-tree-sitter.wasm?url';
65
- import cSharpUrl from '@willbooster/tree-sitter-c-sharp/tree-sitter-c_sharp.wasm?url';
66
67
 
67
68
  await Parser.init({ locateFile: () => runtimeUrl });
68
69
  const parser = new Parser();
@@ -74,9 +75,9 @@ compiles them at build time) and pass them to `Parser.init` and `Language.load`.
74
75
  `nodejs_compat` flag:
75
76
 
76
77
  ```js
78
+ import cSharp from '@willbooster/tree-sitter-c-sharp/tree-sitter-c_sharp.wasm';
77
79
  import { Language, Parser } from '@willbooster/web-tree-sitter';
78
80
  import runtime from '@willbooster/web-tree-sitter/web-tree-sitter.wasm';
79
- import cSharp from '@willbooster/tree-sitter-c-sharp/tree-sitter-c_sharp.wasm';
80
81
 
81
82
  await Parser.init({ wasmModule: runtime });
82
83
  const parser = new Parser();
package/grammar.js CHANGED
@@ -53,6 +53,9 @@ module.exports = grammar({
53
53
  name: 'c_sharp',
54
54
 
55
55
  conflicts: ($) => [
56
+ [$._stackalloc_array_type, $.array_type],
57
+ [$._stackalloc_array_type, $._array_base_type],
58
+ [$._stackalloc_nullable_type, $.nullable_type],
56
59
  [$._simple_name, $._expression_simple_name, $._pattern_simple_identifier_name, $._ambiguous_cast_qualified_name],
57
60
  [$._expression_simple_name, $._ambiguous_cast_qualified_name],
58
61
  [$._simple_name, $._expression_simple_name, $._ambiguous_cast_qualified_name],
@@ -185,6 +188,13 @@ module.exports = grammar({
185
188
  [$._pattern_identifier, $.from_clause, $._reserved_identifier],
186
189
  [$.scoped_type, $._pattern_identifier, $._reserved_identifier],
187
190
  [$._pattern_identifier, $._lambda_expression_init, $.anonymous_method_expression, $._reserved_identifier],
191
+ [
192
+ $._pattern_identifier,
193
+ $._lambda_expression_init,
194
+ $._typed_lambda_expression_init,
195
+ $.anonymous_method_expression,
196
+ $._reserved_identifier,
197
+ ],
188
198
  [$._pattern_identifier, $.identifier],
189
199
  [$.implicit_type, $._pattern_identifier, $._reserved_identifier],
190
200
  [$._pattern_primary_expression, $._conditional_access_receiver],
@@ -251,11 +261,23 @@ module.exports = grammar({
251
261
  [$._reserved_identifier, $.modifier],
252
262
  [$._reserved_identifier],
253
263
  [$._lambda_expression_init, $.anonymous_method_expression, $._reserved_identifier],
264
+ [$._lambda_expression_init, $._typed_lambda_expression_init, $.anonymous_method_expression, $._reserved_identifier],
254
265
  [$._lambda_expression_init, $._reserved_identifier],
266
+ [$._lambda_expression_init, $._typed_lambda_expression_init, $._reserved_identifier],
255
267
  [$.modifier, $._lambda_expression_init, $.anonymous_method_expression],
268
+ [$.modifier, $._lambda_expression_init, $._typed_lambda_expression_init, $.anonymous_method_expression],
256
269
  [$.modifier, $._lambda_expression_init],
270
+ [$.modifier, $._lambda_expression_init, $._typed_lambda_expression_init],
257
271
  [$.modifier, $._lambda_expression_init, $._reserved_identifier],
272
+ [$.modifier, $._lambda_expression_init, $._typed_lambda_expression_init, $._reserved_identifier],
258
273
  [$.modifier, $._lambda_expression_init, $.anonymous_method_expression, $._reserved_identifier],
274
+ [
275
+ $.modifier,
276
+ $._lambda_expression_init,
277
+ $._typed_lambda_expression_init,
278
+ $.anonymous_method_expression,
279
+ $._reserved_identifier,
280
+ ],
259
281
  [$._reserved_identifier, $.scoped_type],
260
282
  [$._reserved_identifier, $.implicit_type],
261
283
  [$._reserved_identifier, $.from_clause],
@@ -359,6 +381,9 @@ module.exports = grammar({
359
381
  sym('_expression_generic_end'),
360
382
  sym('_definite_expression_generic_end'),
361
383
  sym('_if_alternative_directive'),
384
+ sym('_conditional_consequence_start'),
385
+ sym('_expression_generic_start'),
386
+ sym('_stackalloc_context'),
362
387
  ],
363
388
 
364
389
  extras: ($) => [
@@ -632,7 +657,7 @@ module.exports = grammar({
632
657
 
633
658
  type_parameter_list: ($) =>
634
659
  seq(
635
- '<',
660
+ genericStart(),
636
661
  commaSep1($.type_parameter),
637
662
  choice('>', alias(sym('_expression_generic_end'), '>'), alias(sym('_definite_expression_generic_end'), '>'))
638
663
  ),
@@ -1055,7 +1080,7 @@ module.exports = grammar({
1055
1080
 
1056
1081
  type_argument_list: ($) =>
1057
1082
  seq(
1058
- '<',
1083
+ genericStart(),
1059
1084
  choice(repeat(','), commaSep1($.type)),
1060
1085
  choice('>', alias(sym('_expression_generic_end'), '>'), alias(sym('_definite_expression_generic_end'), '>'))
1061
1086
  ),
@@ -1067,7 +1092,7 @@ module.exports = grammar({
1067
1092
 
1068
1093
  _expression_type_argument_list: ($) =>
1069
1094
  seq(
1070
- '<',
1095
+ genericStart(),
1071
1096
  choice(
1072
1097
  seq(choice(repeat(','), commaSep1($.type)), alias(sym('_expression_generic_end'), '>')),
1073
1098
  seq(repeat(','), alias(sym('_definite_expression_generic_end'), '>')),
@@ -1129,7 +1154,7 @@ module.exports = grammar({
1129
1154
 
1130
1155
  _ambiguous_expression_arguments: ($) =>
1131
1156
  seq(
1132
- '<',
1157
+ genericStart(),
1133
1158
  commaSep1(alias($._nongeneric_expression_type_argument, $.type)),
1134
1159
  choice('>', alias(sym('_expression_generic_end'), '>'), alias(sym('_definite_expression_generic_end'), '>'))
1135
1160
  ),
@@ -1162,7 +1187,7 @@ module.exports = grammar({
1162
1187
 
1163
1188
  _method_expression_arguments: ($) =>
1164
1189
  seq(
1165
- '<',
1190
+ genericStart(),
1166
1191
  choice(
1167
1192
  repeat(','),
1168
1193
  seq(
@@ -1250,6 +1275,32 @@ module.exports = grammar({
1250
1275
 
1251
1276
  array_type: ($) => seq(field('type', $._array_base_type), field('rank', $.array_rank_specifier)),
1252
1277
 
1278
+ _stackalloc_array_type: ($) =>
1279
+ prec.dynamic(
1280
+ 1,
1281
+ seq(
1282
+ field(
1283
+ 'type',
1284
+ choice(
1285
+ alias($._stackalloc_array_type, $.array_type),
1286
+ $._name,
1287
+ alias($._stackalloc_nullable_type, $.nullable_type),
1288
+ $.pointer_type,
1289
+ $.function_pointer_type,
1290
+ $.predefined_type,
1291
+ $.tuple_type
1292
+ )
1293
+ ),
1294
+ field('rank', $.array_rank_specifier)
1295
+ )
1296
+ ),
1297
+
1298
+ _stackalloc_nullable_type: ($) =>
1299
+ seq(
1300
+ field('type', choice(alias($._stackalloc_array_type, $.array_type), $._name, $.predefined_type, $.tuple_type)),
1301
+ nullableQuestion()
1302
+ ),
1303
+
1253
1304
  _array_base_type: ($) =>
1254
1305
  choice(
1255
1306
  $.array_type,
@@ -1277,7 +1328,7 @@ module.exports = grammar({
1277
1328
  'delegate',
1278
1329
  '*',
1279
1330
  optional($.calling_convention),
1280
- '<',
1331
+ genericStart(),
1281
1332
  repeat(seq($.function_pointer_parameter, ',')),
1282
1333
  field('returns', $.type),
1283
1334
  '>'
@@ -1412,17 +1463,19 @@ module.exports = grammar({
1412
1463
  field('body', $.switch_body)
1413
1464
  ),
1414
1465
 
1415
- switch_body: ($) => seq('{', repeat($.switch_section), blockEnd()),
1466
+ switch_body: ($) => seq('{', optional(conditionalSectionRun($)), repeat($.switch_section), blockEnd()),
1416
1467
 
1417
1468
  switch_section: ($) =>
1418
1469
  prec.left(
1419
1470
  seq(
1420
1471
  choice(seq('case', choice($.expression, seq($.pattern, optional($.when_clause)))), 'default'),
1421
1472
  alias(sym('_case_label_colon'), ':'),
1422
- repeat($.statement)
1473
+ repeat(choice($.statement, $._preproc_if_in_switch_body))
1423
1474
  )
1424
1475
  ),
1425
1476
 
1477
+ _preproc_if_in_switch_body: () => alias(sym('preproc_if_in_switch_body'), sym('preproc_if')),
1478
+
1426
1479
  throw_statement: ($) => seq('throw', optional($.expression), statementEnd()),
1427
1480
 
1428
1481
  try_statement: ($) => seq('try', field('body', $.block), repeat($.catch_clause), optional($.finally_clause)),
@@ -1958,6 +2011,24 @@ module.exports = grammar({
1958
2011
  prec.right(
1959
2012
  PREC.COALESCING,
1960
2013
  seq(field('left', $.expression), field('operator', '??'), field('right', $.expression))
2014
+ ),
2015
+ ...binaryOperators().map(([operator, precedence]) =>
2016
+ prec.left(
2017
+ precedence,
2018
+ seq(
2019
+ field('left', $.expression),
2020
+ field('operator', operator),
2021
+ field('right', alias($._binary_typed_lambda_expression, $.lambda_expression))
2022
+ )
2023
+ )
2024
+ ),
2025
+ prec.right(
2026
+ PREC.COALESCING,
2027
+ seq(
2028
+ field('left', $.expression),
2029
+ field('operator', '??'),
2030
+ field('right', alias($._binary_typed_lambda_expression, $.lambda_expression))
2031
+ )
1961
2032
  )
1962
2033
  ),
1963
2034
 
@@ -2006,6 +2077,7 @@ module.exports = grammar({
2006
2077
  seq(
2007
2078
  field('condition', $.expression),
2008
2079
  ternaryQuestion(),
2080
+ sym('_conditional_consequence_start'),
2009
2081
  field('consequence', $.expression),
2010
2082
  ':',
2011
2083
  sym('_conditional_alternative_start'),
@@ -2454,7 +2526,19 @@ module.exports = grammar({
2454
2526
  parenthesized_expression: ($) => seq('(', $.expression, ')'),
2455
2527
 
2456
2528
  lambda_expression: ($) =>
2457
- prec(-1, seq($._lambda_expression_init, '=>', field('body', choice($.block, $.expression)))),
2529
+ prec(
2530
+ -1,
2531
+ choice(
2532
+ seq($._lambda_expression_init, '=>', field('body', choice($.block, $.expression))),
2533
+ seq($._typed_lambda_expression_init, '=>', field('body', choice($.block, $.expression)))
2534
+ )
2535
+ ),
2536
+
2537
+ _binary_typed_lambda_expression: ($) =>
2538
+ prec(
2539
+ 1,
2540
+ prec.dynamic(-1, seq($._typed_lambda_expression_init, '=>', field('body', choice($.block, $.expression))))
2541
+ ),
2458
2542
 
2459
2543
  _lambda_expression_init: ($) =>
2460
2544
  prec(
@@ -2464,11 +2548,23 @@ module.exports = grammar({
2464
2548
  repeat(prec.dynamic(1, alias(choice('static', 'async'), $.modifier))),
2465
2549
  choice(
2466
2550
  field('parameters', prec(-1, alias($.identifier, sym('implicit_parameter')))),
2467
- seq(optional(field('type', $.type)), field('parameters', $._lambda_parameters))
2551
+ prec(1, prec.dynamic(1, seq(field('type', $.ref_type), field('parameters', $._lambda_parameters)))),
2552
+ field('parameters', $._lambda_parameters)
2468
2553
  )
2469
2554
  )
2470
2555
  ),
2471
2556
 
2557
+ _typed_lambda_expression_init: ($) =>
2558
+ prec(
2559
+ -1,
2560
+ seq(
2561
+ repeat($._attribute_list),
2562
+ repeat(prec.dynamic(1, alias(choice('static', 'async'), $.modifier))),
2563
+ field('type', $.type),
2564
+ field('parameters', $._lambda_parameters)
2565
+ )
2566
+ ),
2567
+
2472
2568
  _lambda_parameters: ($) =>
2473
2569
  prec(
2474
2570
  -1,
@@ -2723,6 +2819,32 @@ module.exports = grammar({
2723
2819
  ...preprocIf('_in_top_level', ($) => conditionalStatements($), 0, false, true),
2724
2820
  ...preprocIf('_in_if_alternative', ($) => seq(optional('else'), conditionalStatements($)), 0, false),
2725
2821
 
2822
+ // Alternatives start with any statements that continue the enclosing section. Nested directives precede the
2823
+ // sections because a directive after a section belongs to that section's statements.
2824
+ preproc_if_in_switch_body: ($) =>
2825
+ conditionalDirective(
2826
+ 'if',
2827
+ $,
2828
+ choice(seq(conditionalSectionRun($), repeat($.switch_section)), repeat1($.switch_section)),
2829
+ field('alternative', optional($._preproc_switch_body_alternative)),
2830
+ preprocessor('endif')
2831
+ ),
2832
+ preproc_elif_in_switch_body: ($) =>
2833
+ conditionalDirective(
2834
+ 'elif',
2835
+ $,
2836
+ repeat($.statement),
2837
+ optional(conditionalSectionRun($)),
2838
+ repeat($.switch_section),
2839
+ field('alternative', optional($._preproc_switch_body_alternative))
2840
+ ),
2841
+ preproc_else_in_switch_body: ($) =>
2842
+ seq(preprocessor('else'), repeat($.statement), optional(conditionalSectionRun($)), repeat($.switch_section)),
2843
+ _preproc_switch_body_alternative: () =>
2844
+ choice(
2845
+ alias(sym('preproc_else_in_switch_body'), sym('preproc_else')),
2846
+ alias(sym('preproc_elif_in_switch_body'), sym('preproc_elif'))
2847
+ ),
2726
2848
  ...preprocIf('_in_expression', ($) => $.expression, -2, false),
2727
2849
  ...conditionalListDirective('_in_initializer', ($) => $.expression),
2728
2850
  ...conditionalListDirective(
@@ -3161,6 +3283,15 @@ function argumentValue($) {
3161
3283
  return choice(seq(optional(choice('ref', 'out', 'in')), $.expression), seq('out', $.declaration_expression));
3162
3284
  }
3163
3285
 
3286
+ /**
3287
+ * Conditional switch sections followed by more of them or by the statements their conditional labels share.
3288
+ *
3289
+ * @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'_preproc_if_in_switch_body' | 'statement'>} $
3290
+ */
3291
+ function conditionalSectionRun($) {
3292
+ return seq($._preproc_if_in_switch_body, repeat(choice($._preproc_if_in_switch_body, $.statement)));
3293
+ }
3294
+
3164
3295
  /**
3165
3296
  * Statements of a conditional branch, where the last may be an if statement whose `else` body follows the directive.
3166
3297
  *
@@ -3325,12 +3456,21 @@ function arrayCreationExpression($, initializer) {
3325
3456
  }
3326
3457
 
3327
3458
  /**
3328
- * @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'type'>} $
3459
+ * @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'_stackalloc_array_type' | 'array_type' | 'type'>} $
3329
3460
  * @param {import('@willbooster/web-tree-sitter/dsl').Rule} initializer
3330
3461
  * @returns {import('@willbooster/web-tree-sitter/dsl').Rule}
3331
3462
  */
3332
3463
  function stackallocExpression($, initializer) {
3333
- return prec.left(seq('stackalloc', field('type', $.type), initializer));
3464
+ return choice(
3465
+ prec.left(seq('stackalloc', field('type', $.type), initializer)),
3466
+ prec.right(
3467
+ seq(
3468
+ alias(sym('_stackalloc_context'), 'stackalloc'),
3469
+ field('type', alias($._stackalloc_array_type, $.array_type)),
3470
+ initializer
3471
+ )
3472
+ )
3473
+ );
3334
3474
  }
3335
3475
 
3336
3476
  /**
@@ -3754,3 +3894,7 @@ function blockEnd() {
3754
3894
  function ampersandOperator() {
3755
3895
  return alias(sym('_ampersand_operator'), '&');
3756
3896
  }
3897
+
3898
+ function genericStart() {
3899
+ return choice('<', alias(sym('_expression_generic_start'), '<'));
3900
+ }
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c-sharp",
3
- "version": "15.0.0",
3
+ "version": "15.0.2",
4
4
  "description": "C# grammar for tree-sitter",
5
5
  "keywords": [
6
+ "c-sharp",
6
7
  "incremental",
7
8
  "parsing",
8
- "tree-sitter",
9
- "c-sharp"
9
+ "tree-sitter"
10
10
  ],
11
+ "license": "MIT",
12
+ "author": "WillBooster Inc.",
11
13
  "repository": {
12
14
  "type": "git",
13
15
  "url": "git+https://github.com/WillBooster/tree-sitter-c-sharp.git"
14
16
  },
15
- "license": "MIT",
16
- "author": "WillBooster Inc.",
17
17
  "files": [
18
18
  "grammar.js",
19
19
  "queries/*.scm",
@@ -21,6 +21,10 @@
21
21
  "src/node-types.json",
22
22
  "*.wasm"
23
23
  ],
24
+ "publishConfig": {
25
+ "access": "public",
26
+ "registry": "https://registry.npmjs.org/"
27
+ },
24
28
  "scripts": {
25
29
  "build-wasm": "script/generate --build-wasm",
26
30
  "build/ci": "bun run build-wasm",
@@ -44,22 +48,19 @@
44
48
  "devDependencies": {
45
49
  "@tsconfig/bun": "1.0.11",
46
50
  "@types/bun": "1.4.3",
47
- "@vitest/browser-playwright": "5.0.3",
48
- "@willbooster/oxfmt-config": "1.2.2",
49
- "@willbooster/oxlint-config": "1.4.8",
50
- "@willbooster/wb": "22.26.2",
51
+ "@vitest/browser-playwright": "5.0.5",
52
+ "@willbooster/oxlint-config": "1.4.9",
53
+ "@willbooster/wb": "22.29.3",
51
54
  "@willbooster/web-tree-sitter": "13.0.0",
52
55
  "conventional-changelog-conventionalcommits": "10.4.1",
53
56
  "lefthook": "2.2.2",
54
- "oxfmt": "0.73.0",
55
57
  "oxlint": "1.88.0",
56
58
  "oxlint-tsgolint": "7.0.2004",
57
- "playwright": "1.64.0",
59
+ "playwright": "1.64.1",
58
60
  "semantic-release": "25.0.9",
59
- "sort-package-json": "4.0.0",
60
61
  "vite": "8.3.4",
61
- "vitest": "5.0.3",
62
- "wrangler": "4.149.0"
62
+ "vitest": "5.0.5",
63
+ "wrangler": "4.151.1"
63
64
  },
64
65
  "peerDependencies": {
65
66
  "@willbooster/web-tree-sitter": "^13.0.0"
@@ -68,9 +69,5 @@
68
69
  "@willbooster/web-tree-sitter": {
69
70
  "optional": true
70
71
  }
71
- },
72
- "publishConfig": {
73
- "access": "public",
74
- "registry": "https://registry.npmjs.org/"
75
72
  }
76
73
  }
@@ -6368,6 +6368,10 @@
6368
6368
  "type": "switch_expression_arm",
6369
6369
  "named": true
6370
6370
  },
6371
+ {
6372
+ "type": "switch_section",
6373
+ "named": true
6374
+ },
6371
6375
  {
6372
6376
  "type": "type_declaration",
6373
6377
  "named": true
@@ -6460,6 +6464,10 @@
6460
6464
  "type": "switch_expression_arm",
6461
6465
  "named": true
6462
6466
  },
6467
+ {
6468
+ "type": "switch_section",
6469
+ "named": true
6470
+ },
6463
6471
  {
6464
6472
  "type": "type_declaration",
6465
6473
  "named": true
@@ -6629,6 +6637,10 @@
6629
6637
  "type": "switch_expression_arm",
6630
6638
  "named": true
6631
6639
  },
6640
+ {
6641
+ "type": "switch_section",
6642
+ "named": true
6643
+ },
6632
6644
  {
6633
6645
  "type": "type_declaration",
6634
6646
  "named": true
@@ -7572,6 +7584,10 @@
7572
7584
  "multiple": true,
7573
7585
  "required": false,
7574
7586
  "types": [
7587
+ {
7588
+ "type": "statement",
7589
+ "named": true
7590
+ },
7575
7591
  {
7576
7592
  "type": "switch_section",
7577
7593
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -24,6 +24,9 @@
24
24
  "src/nullableTypes.h",
25
25
  "src/questionContext.h",
26
26
  "src/questionLiterals.h",
27
+ "src/questionOperands.h",
28
+ "src/questionState.h",
29
+ "src/questionSuffix.h",
27
30
  "src/tree_sitter/alloc.h",
28
31
  "src/tree_sitter/array.h",
29
32
  "src/tree_sitter/parser.h"
@@ -31,7 +34,7 @@
31
34
  }
32
35
  ],
33
36
  "metadata": {
34
- "version": "15.0.0",
37
+ "version": "15.0.2",
35
38
  "license": "MIT",
36
39
  "description": "C# grammar for tree-sitter",
37
40
  "authors": [