@willbooster/tree-sitter-c-sharp 5.0.1 → 5.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
@@ -109,8 +109,7 @@ cargo test
109
109
  `script/tree-sitter` (also `bun run tree-sitter`) runs the tree-sitter CLI of WillBooster/tree-sitter at the runtime
110
110
  version locked in `Cargo.lock`, so the parser is generated, built, tested, and fuzzed with the generator and the
111
111
  runtime this package ships. The first run downloads that CLI from its GitHub Release into `.tmp/`, or builds it with
112
- `cargo` (with the `cmake` that `mise.toml` pins) when the download fails or the release has no binary that runs here. The `tree-sitter-cli` package provides
113
- only the types of the grammar DSL that `grammar.js` checks against; its `tree-sitter` binary is upstream's.
112
+ `cargo` (with the `cmake` that `mise.toml` pins) when the download fails or the release has no binary that runs here.
114
113
 
115
114
  `bun run generate` records a fresh generation profile from the applicable `test/corpus` cases and Git-tracked
116
115
  files in `examples/`, then generates compact parser tables. The parser also embeds metadata from `tree-sitter.json`. After changing a grammar,
package/grammar.js CHANGED
@@ -6,9 +6,13 @@
6
6
  * @license MIT
7
7
  */
8
8
 
9
- /// <reference types="tree-sitter-cli/dsl" />
10
9
  // @ts-check
11
10
 
11
+ const { alias, choice, field, grammar, optional, prec, repeat, repeat1, seq, sym, token } =
12
+ /** @type {typeof globalThis & import('@willbooster/web-tree-sitter/dsl').DSL} */ (globalThis);
13
+
14
+ /** @typedef {'_preproc_expression' | '_top_level_item_no_statement' | 'attribute_list' | 'declaration' | 'enum_member_declaration' | 'expression' | 'method_signature' | 'statement'} PreprocContentRule */
15
+
12
16
  const PREC = {
13
17
  GENERIC: 19,
14
18
  DOT: 18,
@@ -134,36 +138,36 @@ module.exports = grammar({
134
138
  [$.receiver_parameter, $.scoped_type, $._reserved_identifier],
135
139
  ],
136
140
 
137
- externals: ($) => [
138
- $._optional_semi,
139
- $.interpolation_regular_start,
140
- $.interpolation_verbatim_start,
141
- $.interpolation_raw_start,
142
- $.interpolation_start_quote,
143
- $.interpolation_end_quote,
144
- $.interpolation_open_brace,
145
- $.interpolation_close_brace,
146
- $.interpolation_string_content,
147
- $.raw_string_start,
148
- $.raw_string_end,
149
- $.raw_string_content,
141
+ externals: () => [
142
+ sym('_optional_semi'),
143
+ sym('interpolation_regular_start'),
144
+ sym('interpolation_verbatim_start'),
145
+ sym('interpolation_raw_start'),
146
+ sym('interpolation_start_quote'),
147
+ sym('interpolation_end_quote'),
148
+ sym('interpolation_open_brace'),
149
+ sym('interpolation_close_brace'),
150
+ sym('interpolation_string_content'),
151
+ sym('raw_string_start'),
152
+ sym('raw_string_end'),
153
+ sym('raw_string_content'),
150
154
  // C# 14: emitted by the scanner at '(' when forward-scanning shows a
151
155
  // simple-lambda parameter list (at least one element has a parameter
152
156
  // modifier) closed by ')=>'.
153
- $._lambda_paren_open,
154
- $._end_of_input,
155
- $._directive_newline,
156
- $._file_directive_preproc_arg,
157
- $._file_directive_sdk,
158
- $._file_directive_package,
159
- $._file_directive_property,
160
- $._file_directive_project,
161
- $._file_directive_ref,
162
- $._file_directive_include,
163
- $._file_directive_exclude,
164
- $.file_directive_kind,
165
- $._file_directive_literal_context,
166
- $._file_directive_newline,
157
+ sym('_lambda_paren_open'),
158
+ sym('_end_of_input'),
159
+ sym('_directive_newline'),
160
+ sym('_file_directive_preproc_arg'),
161
+ sym('_file_directive_sdk'),
162
+ sym('_file_directive_package'),
163
+ sym('_file_directive_property'),
164
+ sym('_file_directive_project'),
165
+ sym('_file_directive_ref'),
166
+ sym('_file_directive_include'),
167
+ sym('_file_directive_exclude'),
168
+ sym('file_directive_kind'),
169
+ sym('_file_directive_literal_context'),
170
+ sym('_file_directive_newline'),
167
171
  ],
168
172
 
169
173
  extras: ($) => [
@@ -218,7 +222,7 @@ module.exports = grammar({
218
222
  $.extern_alias_directive,
219
223
  $.using_directive,
220
224
  $.global_attribute,
221
- alias($.preproc_if_in_top_level, $.preproc_if),
225
+ alias(sym('preproc_if_in_top_level'), sym('preproc_if')),
222
226
  $._namespace_member_declaration,
223
227
  $.file_scoped_namespace_declaration
224
228
  ),
@@ -249,7 +253,7 @@ module.exports = grammar({
249
253
 
250
254
  attribute_list: ($) => seq('[', optional($.attribute_target_specifier), commaSep1($.attribute), optional(','), ']'),
251
255
 
252
- _attribute_list: ($) => choice($.attribute_list, $.preproc_if_in_attribute_list),
256
+ _attribute_list: ($) => choice($.attribute_list, sym('preproc_if_in_attribute_list')),
253
257
 
254
258
  // Higher precedence than `_reserved_identifier`: when both interpretations
255
259
  // are valid (e.g. `[field :` could be `_reserved_identifier` followed by
@@ -262,7 +266,7 @@ module.exports = grammar({
262
266
  _namespace_member_declaration: ($) => choice($.namespace_declaration, $.type_declaration),
263
267
 
264
268
  namespace_declaration: ($) =>
265
- seq('namespace', field('name', $._name), field('body', $.declaration_list), $._optional_semi),
269
+ seq('namespace', field('name', $._name), field('body', $.declaration_list), sym('_optional_semi')),
266
270
 
267
271
  file_scoped_namespace_declaration: ($) => seq('namespace', field('name', $._name), ';'),
268
272
 
@@ -304,7 +308,7 @@ module.exports = grammar({
304
308
  enum_declaration: ($) =>
305
309
  seq(
306
310
  $._enum_declaration_initializer,
307
- choice(seq(field('body', $.enum_member_declaration_list), $._optional_semi), ';')
311
+ choice(seq(field('body', $.enum_member_declaration_list), sym('_optional_semi')), ';')
308
312
  ),
309
313
 
310
314
  _enum_declaration_initializer: ($) =>
@@ -313,7 +317,9 @@ module.exports = grammar({
313
317
  enum_member_declaration_list: ($) =>
314
318
  seq(
315
319
  '{',
316
- commaSep(choice($.enum_member_declaration, alias($.preproc_if_in_enum_member_declaration, $.preproc_if))),
320
+ commaSep(
321
+ choice($.enum_member_declaration, alias(sym('preproc_if_in_enum_member_declaration'), sym('preproc_if')))
322
+ ),
317
323
  optional(','),
318
324
  '}'
319
325
  ),
@@ -368,7 +374,7 @@ module.exports = grammar({
368
374
  seq(':', $.primary_constructor_base_type, optional(seq(',', commaSep1($._name))))
369
375
  ),
370
376
 
371
- _declaration_list_body: ($) => choice(seq(field('body', $.declaration_list), $._optional_semi), ';'),
377
+ _declaration_list_body: ($) => choice(seq(field('body', $.declaration_list), sym('_optional_semi')), ';'),
372
378
 
373
379
  primary_constructor_base_type: ($) => seq(field('type', $._name), $.argument_list),
374
380
 
@@ -512,7 +518,7 @@ module.exports = grammar({
512
518
  $.conversion_operator_declaration,
513
519
  $.property_declaration,
514
520
  $.using_directive,
515
- $.preproc_if,
521
+ sym('preproc_if'),
516
522
  $.extension_declaration
517
523
  ),
518
524
 
@@ -576,7 +582,8 @@ module.exports = grammar({
576
582
 
577
583
  method_declaration: ($) => seq($._method_signature, $._function_body),
578
584
 
579
- conditional_method_declaration: ($) => seq(alias($.preproc_if_in_method_signature, $.preproc_if), $._function_body),
585
+ conditional_method_declaration: ($) =>
586
+ seq(alias(sym('preproc_if_in_method_signature'), sym('preproc_if')), $._function_body),
580
587
 
581
588
  method_signature: ($) => $._method_signature,
582
589
 
@@ -860,7 +867,7 @@ module.exports = grammar({
860
867
  $.while_statement,
861
868
  $.local_declaration_statement,
862
869
  $.local_function_statement,
863
- alias($.preproc_if_in_top_level, $.preproc_if)
870
+ alias(sym('preproc_if_in_top_level'), sym('preproc_if'))
864
871
  )
865
872
  ),
866
873
 
@@ -1187,7 +1194,7 @@ module.exports = grammar({
1187
1194
  $.implicit_stackalloc_expression,
1188
1195
  $.initializer_expression,
1189
1196
  $.query_expression,
1190
- alias($.preproc_if_in_expression, $.preproc_if)
1197
+ alias(sym('preproc_if_in_expression'), sym('preproc_if'))
1191
1198
  ),
1192
1199
 
1193
1200
  lvalue_expression: ($) =>
@@ -1197,7 +1204,7 @@ module.exports = grammar({
1197
1204
  $.tuple_expression,
1198
1205
  $._simple_name,
1199
1206
  $.element_access_expression,
1200
- alias($.bracketed_argument_list, $.element_binding_expression),
1207
+ alias($.bracketed_argument_list, sym('element_binding_expression')),
1201
1208
  alias($._pointer_indirection_expression, $.prefix_unary_expression),
1202
1209
  alias($._parenthesized_lvalue_expression, $.parenthesized_expression),
1203
1210
  // C# 14 null-conditional assignment: `obj?.x = v`, `obj?[i] = v`.
@@ -1284,7 +1291,7 @@ module.exports = grammar({
1284
1291
 
1285
1292
  binary_expression: ($) =>
1286
1293
  choice(
1287
- ...[
1294
+ .../** @type {[string, number][]} */ ([
1288
1295
  ['&&', PREC.LOGICAL_AND],
1289
1296
  ['||', PREC.LOGICAL_OR],
1290
1297
  ['>>', PREC.SHIFT],
@@ -1304,15 +1311,10 @@ module.exports = grammar({
1304
1311
  ['!=', PREC.EQUAL],
1305
1312
  ['>=', PREC.REL],
1306
1313
  ['>', PREC.REL],
1307
- ].map(([operator, precedence]) =>
1314
+ ]).map(([operator, precedence]) =>
1308
1315
  prec.left(
1309
1316
  precedence,
1310
- seq(
1311
- field('left', $.expression),
1312
- // @ts-ignore
1313
- field('operator', operator),
1314
- field('right', $.expression)
1315
- )
1317
+ seq(field('left', $.expression), field('operator', operator), field('right', $.expression))
1316
1318
  )
1317
1319
  ),
1318
1320
  prec.right(
@@ -1445,7 +1447,7 @@ module.exports = grammar({
1445
1447
  seq(
1446
1448
  field('condition', $.expression),
1447
1449
  '?',
1448
- choice($.member_binding_expression, alias($.bracketed_argument_list, $.element_binding_expression))
1450
+ choice($.member_binding_expression, alias($.bracketed_argument_list, sym('element_binding_expression')))
1449
1451
  )
1450
1452
  ),
1451
1453
 
@@ -1495,66 +1497,66 @@ module.exports = grammar({
1495
1497
  interpolated_string_expression: ($) =>
1496
1498
  choice(
1497
1499
  seq(
1498
- alias($.interpolation_regular_start, $.interpolation_start),
1499
- alias($.interpolation_start_quote, '"'),
1500
+ alias(sym('interpolation_regular_start'), sym('interpolation_start')),
1501
+ alias(sym('interpolation_start_quote'), '"'),
1500
1502
  repeat($._interpolated_string_content),
1501
- alias($.interpolation_end_quote, '"')
1503
+ alias(sym('interpolation_end_quote'), '"')
1502
1504
  ),
1503
1505
  seq(
1504
- alias($.interpolation_verbatim_start, $.interpolation_start),
1505
- alias($.interpolation_start_quote, '"'),
1506
+ alias(sym('interpolation_verbatim_start'), sym('interpolation_start')),
1507
+ alias(sym('interpolation_start_quote'), '"'),
1506
1508
  repeat($._interpolated_verbatim_string_content),
1507
- alias($.interpolation_end_quote, '"')
1509
+ alias(sym('interpolation_end_quote'), '"')
1508
1510
  ),
1509
1511
  seq(
1510
- alias($.interpolation_raw_start, $.interpolation_start),
1511
- alias($.interpolation_start_quote, $.interpolation_quote),
1512
+ alias(sym('interpolation_raw_start'), sym('interpolation_start')),
1513
+ alias(sym('interpolation_start_quote'), sym('interpolation_quote')),
1512
1514
  repeat($._interpolated_raw_string_content),
1513
- alias($.interpolation_end_quote, $.interpolation_quote)
1515
+ alias(sym('interpolation_end_quote'), sym('interpolation_quote'))
1514
1516
  )
1515
1517
  ),
1516
1518
 
1517
1519
  _interpolated_string_content: ($) =>
1518
- choice(alias($.interpolation_string_content, $.string_content), $.escape_sequence, $.interpolation),
1520
+ choice(alias(sym('interpolation_string_content'), sym('string_content')), $.escape_sequence, $.interpolation),
1519
1521
 
1520
1522
  _interpolated_verbatim_string_content: ($) =>
1521
1523
  choice(
1522
- alias($.interpolation_string_content, $.string_content),
1524
+ alias(sym('interpolation_string_content'), sym('string_content')),
1523
1525
  alias($._multiline_interpolation, $.interpolation)
1524
1526
  ),
1525
1527
 
1526
1528
  _interpolated_raw_string_content: ($) =>
1527
1529
  choice(
1528
- alias($.interpolation_string_content, $.string_content),
1530
+ alias(sym('interpolation_string_content'), sym('string_content')),
1529
1531
  alias($._multiline_interpolation, $.interpolation)
1530
1532
  ),
1531
1533
 
1532
1534
  interpolation: ($) =>
1533
1535
  seq(
1534
- alias($.interpolation_open_brace, $.interpolation_brace),
1536
+ alias(sym('interpolation_open_brace'), sym('interpolation_brace')),
1535
1537
  $.expression,
1536
1538
  optional($.interpolation_alignment_clause),
1537
1539
  choice(
1538
- alias($.interpolation_close_brace, $.interpolation_brace),
1539
- seq($.interpolation_format_clause, alias(token.immediate('}'), $.interpolation_brace))
1540
+ alias(sym('interpolation_close_brace'), sym('interpolation_brace')),
1541
+ seq($.interpolation_format_clause, alias(token.immediate('}'), sym('interpolation_brace')))
1540
1542
  )
1541
1543
  ),
1542
1544
 
1543
1545
  interpolation_alignment_clause: ($) => seq(',', $.expression),
1544
1546
 
1545
- interpolation_format_clause: ($) =>
1546
- seq(':', optional($._file_directive_literal_context), token.immediate(/[^}"\n\r\u0085\u2028\u2029]+/)),
1547
+ interpolation_format_clause: () =>
1548
+ seq(':', optional(sym('_file_directive_literal_context')), token.immediate(/[^}"\n\r\u0085\u2028\u2029]+/)),
1547
1549
 
1548
1550
  _multiline_interpolation: ($) =>
1549
1551
  seq(
1550
- alias($.interpolation_open_brace, $.interpolation_brace),
1552
+ alias(sym('interpolation_open_brace'), sym('interpolation_brace')),
1551
1553
  $.expression,
1552
1554
  optional($.interpolation_alignment_clause),
1553
1555
  optional(alias($._multiline_interpolation_format_clause, $.interpolation_format_clause)),
1554
- alias($.interpolation_close_brace, $.interpolation_brace)
1556
+ alias(sym('interpolation_close_brace'), sym('interpolation_brace'))
1555
1557
  ),
1556
1558
 
1557
- _multiline_interpolation_format_clause: ($) => seq(':', optional($._file_directive_literal_context), /[^}"]+/),
1559
+ _multiline_interpolation_format_clause: () => seq(':', optional(sym('_file_directive_literal_context')), /[^}"]+/),
1558
1560
 
1559
1561
  member_access_expression: ($) =>
1560
1562
  prec(
@@ -1594,7 +1596,7 @@ module.exports = grammar({
1594
1596
  repeat($._attribute_list),
1595
1597
  repeat(prec.dynamic(1, alias(choice('static', 'async'), $.modifier))),
1596
1598
  choice(
1597
- field('parameters', prec(-1, alias($.identifier, $.implicit_parameter))),
1599
+ field('parameters', prec(-1, alias($.identifier, sym('implicit_parameter')))),
1598
1600
  seq(optional(field('type', $.type)), field('parameters', $._lambda_parameters))
1599
1601
  )
1600
1602
  )
@@ -1619,14 +1621,14 @@ module.exports = grammar({
1619
1621
  // external _lambda_paren_open; the closing ')' is the regular literal.
1620
1622
  _implicit_parameter_list_with_modifiers: ($) =>
1621
1623
  seq(
1622
- $._lambda_paren_open,
1624
+ sym('_lambda_paren_open'),
1623
1625
  commaSep1(
1624
1626
  choice(
1625
1627
  seq(
1626
1628
  repeat1(alias(choice('scoped', 'ref', 'out', 'in', 'readonly'), $.modifier)),
1627
- alias($.identifier, $.implicit_parameter)
1629
+ alias($.identifier, sym('implicit_parameter'))
1628
1630
  ),
1629
- alias($.identifier, $.implicit_parameter)
1631
+ alias($.identifier, sym('implicit_parameter'))
1630
1632
  )
1631
1633
  ),
1632
1634
  ')'
@@ -1749,7 +1751,7 @@ module.exports = grammar({
1749
1751
  string_literal: ($) =>
1750
1752
  seq(
1751
1753
  '"',
1752
- repeat(choice($.string_literal_content, $.escape_sequence, $._file_directive_literal_context)),
1754
+ repeat(choice($.string_literal_content, $.escape_sequence, sym('_file_directive_literal_context'))),
1753
1755
  token.immediate('"'),
1754
1756
  optional($.string_literal_encoding)
1755
1757
  ),
@@ -1763,8 +1765,8 @@ module.exports = grammar({
1763
1765
 
1764
1766
  verbatim_string_literal: () => token(seq('@"', repeat(choice(/[^"]/, '""')), '"', optional(stringEncoding))),
1765
1767
 
1766
- raw_string_literal: ($) =>
1767
- seq($.raw_string_start, $.raw_string_content, $.raw_string_end, optional(stringEncoding)),
1768
+ raw_string_literal: () =>
1769
+ seq(sym('raw_string_start'), sym('raw_string_content'), sym('raw_string_end'), optional(stringEncoding)),
1768
1770
 
1769
1771
  boolean_literal: () => choice('true', 'false'),
1770
1772
 
@@ -1821,7 +1823,7 @@ module.exports = grammar({
1821
1823
 
1822
1824
  ...preprocIf(
1823
1825
  '_in_method_signature',
1824
- ($) => choice($.method_signature, alias($.preproc_if_in_method_signature, $.preproc_if)),
1826
+ ($) => choice($.method_signature, alias(sym('preproc_if_in_method_signature'), sym('preproc_if'))),
1825
1827
  0,
1826
1828
  false,
1827
1829
  true
@@ -1837,7 +1839,7 @@ module.exports = grammar({
1837
1839
  token(prec(-1, /[^\s\u0085\u2028\u2029]([^/\r\n\u0085\u2028\u2029]|\/[^*\r\n\u0085\u2028\u2029])*/)),
1838
1840
  optional($._preproc_arg_slash)
1839
1841
  ),
1840
- _file_directive_argument: ($) => seq($._file_directive_preproc_arg, optional($._preproc_arg_slash)),
1842
+ _file_directive_argument: ($) => seq(sym('_file_directive_preproc_arg'), optional($._preproc_arg_slash)),
1841
1843
  _preproc_arg_slash: () => token.immediate(/\//),
1842
1844
  preproc_directive: () => /#[ \t]*[a-zA-Z0-9]\w*/,
1843
1845
 
@@ -1847,7 +1849,7 @@ module.exports = grammar({
1847
1849
  $.boolean_literal,
1848
1850
  $.integer_literal,
1849
1851
  $.character_literal,
1850
- alias($.preproc_unary_expression, $.unary_expression),
1852
+ alias($.preproc_unary_expression, sym('unary_expression')),
1851
1853
  alias($.preproc_binary_expression, $.binary_expression),
1852
1854
  alias($.preproc_parenthesized_expression, $.parenthesized_expression)
1853
1855
  ),
@@ -1858,6 +1860,7 @@ module.exports = grammar({
1858
1860
  prec.left(PREC.UNARY, seq(field('operator', '!'), field('argument', $._preproc_expression))),
1859
1861
 
1860
1862
  preproc_binary_expression: ($) => {
1863
+ /** @type {[string, number][]} */
1861
1864
  const table = [
1862
1865
  ['||', PREC.LOGICAL_OR],
1863
1866
  ['&&', PREC.LOGICAL_AND],
@@ -1871,7 +1874,6 @@ module.exports = grammar({
1871
1874
  precedence,
1872
1875
  seq(
1873
1876
  field('left', $._preproc_expression),
1874
- // @ts-ignore
1875
1877
  field('operator', operator),
1876
1878
  field('right', $._preproc_expression)
1877
1879
  )
@@ -1884,14 +1886,14 @@ module.exports = grammar({
1884
1886
  seq(
1885
1887
  preprocessor('region'),
1886
1888
  optional(field('content', choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)))),
1887
- directiveEnd($)
1889
+ directiveEnd()
1888
1890
  ),
1889
1891
 
1890
1892
  preproc_endregion: ($) =>
1891
1893
  seq(
1892
1894
  preprocessor('endregion'),
1893
1895
  optional(field('content', choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)))),
1894
- directiveEnd($)
1896
+ directiveEnd()
1895
1897
  ),
1896
1898
 
1897
1899
  preproc_line: ($) =>
@@ -1917,7 +1919,7 @@ module.exports = grammar({
1917
1919
  alias($._preproc_filename, $.string_literal)
1918
1920
  )
1919
1921
  ),
1920
- directiveEnd($)
1922
+ directiveEnd()
1921
1923
  ),
1922
1924
 
1923
1925
  _preproc_filename: ($) =>
@@ -1926,7 +1928,7 @@ module.exports = grammar({
1926
1928
  repeat(
1927
1929
  choice(
1928
1930
  $.string_literal_content,
1929
- $._file_directive_literal_context,
1931
+ sym('_file_directive_literal_context'),
1930
1932
  alias(token.immediate(prec(-1, '\\')), $.string_literal_content),
1931
1933
  alias(
1932
1934
  token.immediate(
@@ -1946,43 +1948,43 @@ module.exports = grammar({
1946
1948
  seq('warning', choice('disable', 'restore'), commaSep(choice($.identifier, $.integer_literal))),
1947
1949
  seq('checksum', alias($._preproc_filename, $.string_literal), $.string_literal, $.string_literal)
1948
1950
  ),
1949
- directiveEnd($)
1951
+ directiveEnd()
1950
1952
  ),
1951
1953
 
1952
- preproc_nullable: ($) =>
1954
+ preproc_nullable: () =>
1953
1955
  seq(
1954
1956
  preprocessor('nullable'),
1955
1957
  choice('enable', 'disable', 'restore'),
1956
1958
  optional(choice('annotations', 'warnings')),
1957
- directiveEnd($)
1959
+ directiveEnd()
1958
1960
  ),
1959
1961
 
1960
1962
  preproc_error: ($) =>
1961
1963
  seq(
1962
1964
  preprocessor('error'),
1963
1965
  choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)),
1964
- directiveEnd($)
1966
+ directiveEnd()
1965
1967
  ),
1966
1968
 
1967
1969
  preproc_warning: ($) =>
1968
1970
  seq(
1969
1971
  preprocessor('warning'),
1970
1972
  choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)),
1971
- directiveEnd($)
1973
+ directiveEnd()
1972
1974
  ),
1973
1975
 
1974
1976
  preproc_define: ($) =>
1975
1977
  seq(
1976
1978
  preprocessor('define'),
1977
1979
  choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)),
1978
- directiveEnd($)
1980
+ directiveEnd()
1979
1981
  ),
1980
1982
 
1981
1983
  preproc_undef: ($) =>
1982
1984
  seq(
1983
1985
  preprocessor('undef'),
1984
1986
  choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)),
1985
- directiveEnd($)
1987
+ directiveEnd()
1986
1988
  ),
1987
1989
 
1988
1990
  file_directive: ($) =>
@@ -1990,27 +1992,27 @@ module.exports = grammar({
1990
1992
  choice(
1991
1993
  fileDirectiveArguments(
1992
1994
  $,
1993
- choice(alias($._file_directive_sdk, '#:sdk'), alias($._file_directive_package, '#:package')),
1995
+ choice(alias(sym('_file_directive_sdk'), '#:sdk'), alias(sym('_file_directive_package'), '#:package')),
1994
1996
  '@',
1995
1997
  'metadata'
1996
1998
  ),
1997
- fileDirectiveArguments($, alias($._file_directive_property, '#:property'), '=', 'value'),
1999
+ fileDirectiveArguments($, alias(sym('_file_directive_property'), '#:property'), '=', 'value'),
1998
2000
  seq(
1999
2001
  choice(
2000
- alias($._file_directive_project, '#:project'),
2001
- alias($._file_directive_ref, '#:ref'),
2002
- alias($._file_directive_include, '#:include'),
2003
- alias($._file_directive_exclude, '#:exclude')
2002
+ alias(sym('_file_directive_project'), '#:project'),
2003
+ alias(sym('_file_directive_ref'), '#:ref'),
2004
+ alias(sym('_file_directive_include'), '#:include'),
2005
+ alias(sym('_file_directive_exclude'), '#:exclude')
2004
2006
  ),
2005
2007
  optional(seq($._file_directive_spacing, field('value', $.file_directive_value)))
2006
2008
  ),
2007
2009
  seq(
2008
- $.file_directive_kind,
2010
+ sym('file_directive_kind'),
2009
2011
  optional(seq($._file_directive_spacing, optional(field('value', $.file_directive_value))))
2010
2012
  )
2011
2013
  ),
2012
2014
  optional($._file_directive_spacing),
2013
- choice($._file_directive_newline, $._end_of_input)
2015
+ choice(sym('_file_directive_newline'), sym('_end_of_input'))
2014
2016
  ),
2015
2017
 
2016
2018
  _file_directive_spacing: () => token.immediate(prec(1, new RegExp(`[${directiveHorizontal}]+`))),
@@ -2041,11 +2043,11 @@ module.exports = grammar({
2041
2043
  });
2042
2044
 
2043
2045
  /**
2044
- * @param {GrammarSymbols<string>} $
2045
- * @param {Rule} kind
2046
+ * @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'_file_directive_spacing' | 'file_directive_name' | 'file_directive_value'>} $
2047
+ * @param {import('@willbooster/web-tree-sitter/dsl').Rule} kind
2046
2048
  * @param {string} separator
2047
2049
  * @param {string} extraField
2048
- * @returns {SeqRule}
2050
+ * @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
2049
2051
  */
2050
2052
  function fileDirectiveArguments($, kind, separator, extraField) {
2051
2053
  return seq(
@@ -2079,23 +2081,20 @@ function fileDirectiveArguments($, kind, separator, extraField) {
2079
2081
  * Ends a directive that opens no conditional section: at a line break, or at the end of the input, which a file may
2080
2082
  * reach without a final line break.
2081
2083
  *
2082
- * @param {GrammarSymbols<string>} $
2083
- *
2084
- * @returns {ChoiceRule}
2084
+ * @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
2085
2085
  */
2086
- function directiveEnd($) {
2087
- return choice(directiveNewLine($), $._end_of_input);
2086
+ function directiveEnd() {
2087
+ return choice(directiveNewLine(), sym('_end_of_input'));
2088
2088
  }
2089
2089
 
2090
- /** @param {GrammarSymbols<string>} $ */
2091
- function directiveNewLine($) {
2092
- return $._directive_newline;
2090
+ function directiveNewLine() {
2091
+ return sym('_directive_newline');
2093
2092
  }
2094
2093
 
2095
2094
  /**
2096
2095
  * @param {string} command
2097
2096
  *
2098
- * @returns {AliasRule}
2097
+ * @returns {import('@willbooster/web-tree-sitter/dsl').AliasRule}
2099
2098
  */
2100
2099
  function preprocessor(command) {
2101
2100
  return alias(new RegExp('#[ \t]*' + command), '#' + command);
@@ -2105,7 +2104,7 @@ function preprocessor(command) {
2105
2104
  *
2106
2105
  * @param {string} suffix
2107
2106
  *
2108
- * @param {RuleBuilder<string>} content
2107
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleBuilder<PreprocContentRule>} content
2109
2108
  *
2110
2109
  * @param {number} precedence
2111
2110
  *
@@ -2113,19 +2112,23 @@ function preprocessor(command) {
2113
2112
  *
2114
2113
  * @param {boolean} required
2115
2114
  *
2116
- * @returns {RuleBuilders<string, string>}
2115
+ * @returns {Record<string, import('@willbooster/web-tree-sitter/dsl').RuleBuilder<PreprocContentRule>>}
2117
2116
  */
2118
2117
  function preprocIf(suffix, content, precedence = 0, rep = true, required = false) {
2118
+ /** @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<PreprocContentRule>} $ */
2119
+ function contentRule($) {
2120
+ const rule = content($);
2121
+ return rep ? repeat(rule) : required ? rule : optional(rule);
2122
+ }
2123
+
2119
2124
  /**
2120
2125
  *
2121
- * @param {GrammarSymbols<string>} $
2122
- *
2123
- * @returns {ChoiceRule}
2126
+ * @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
2124
2127
  */
2125
- function alternativeBlock($) {
2128
+ function alternativeBlock() {
2126
2129
  return choice(
2127
- suffix ? alias($['preproc_else' + suffix], $.preproc_else) : $.preproc_else,
2128
- suffix ? alias($['preproc_elif' + suffix], $.preproc_elif) : $.preproc_elif
2130
+ suffix ? alias(sym('preproc_else' + suffix), sym('preproc_else')) : sym('preproc_else'),
2131
+ suffix ? alias(sym('preproc_elif' + suffix), sym('preproc_elif')) : sym('preproc_elif')
2129
2132
  );
2130
2133
  }
2131
2134
 
@@ -2136,18 +2139,14 @@ function preprocIf(suffix, content, precedence = 0, rep = true, required = false
2136
2139
  seq(
2137
2140
  preprocessor('if'),
2138
2141
  field('condition', $._preproc_expression),
2139
- directiveNewLine($),
2140
- rep ? repeat(content($)) : required ? content($) : optional(content($)),
2141
- field('alternative', optional(alternativeBlock($))),
2142
+ directiveNewLine(),
2143
+ contentRule($),
2144
+ field('alternative', optional(alternativeBlock())),
2142
2145
  preprocessor('endif')
2143
2146
  )
2144
2147
  ),
2145
2148
 
2146
- ['preproc_else' + suffix]: ($) =>
2147
- prec(
2148
- precedence,
2149
- seq(preprocessor('else'), rep ? repeat(content($)) : required ? content($) : optional(content($)))
2150
- ),
2149
+ ['preproc_else' + suffix]: ($) => prec(precedence, seq(preprocessor('else'), contentRule($))),
2151
2150
 
2152
2151
  ['preproc_elif' + suffix]: ($) =>
2153
2152
  prec(
@@ -2155,9 +2154,9 @@ function preprocIf(suffix, content, precedence = 0, rep = true, required = false
2155
2154
  seq(
2156
2155
  preprocessor('elif'),
2157
2156
  field('condition', $._preproc_expression),
2158
- directiveNewLine($),
2159
- rep ? repeat(content($)) : required ? content($) : optional(content($)),
2160
- field('alternative', optional(alternativeBlock($)))
2157
+ directiveNewLine(),
2158
+ contentRule($),
2159
+ field('alternative', optional(alternativeBlock()))
2161
2160
  )
2162
2161
  ),
2163
2162
  };
@@ -2169,9 +2168,9 @@ function preprocIf(suffix, content, precedence = 0, rep = true, required = false
2169
2168
  * through `expression` would reduce the unary operator or the cast (precedence UNARY or CAST) before `expression`
2170
2169
  * (precedence 0) lets the postfix operator apply, reading `&a[0]` as `(&a)[0]` and `*(T*)f()[0]` as `(*(T*)f())[0]`.
2171
2170
  *
2172
- * @param {GrammarSymbols<string>} $
2171
+ * @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'expression' | 'invocation_expression' | 'lvalue_expression' | 'parenthesized_expression' | 'postfix_unary_expression'>} $
2173
2172
  *
2174
- * @returns {ChoiceRule}
2173
+ * @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
2175
2174
  */
2176
2175
  function postfixOperand($) {
2177
2176
  return choice(
@@ -2184,49 +2183,49 @@ function postfixOperand($) {
2184
2183
  }
2185
2184
 
2186
2185
  /**
2187
- * @param {Rule} rule
2186
+ * @param {import('@willbooster/web-tree-sitter/dsl').Rule} rule
2188
2187
  *
2189
- * @returns {SeqRule}
2188
+ * @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
2190
2189
  */
2191
2190
  function commaSep1(rule) {
2192
2191
  return seq(rule, repeat(seq(',', rule)));
2193
2192
  }
2194
2193
 
2195
2194
  /**
2196
- * @param {Rule} rule
2195
+ * @param {import('@willbooster/web-tree-sitter/dsl').Rule} rule
2197
2196
  *
2198
- * @returns {SeqRule}
2197
+ * @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
2199
2198
  */
2200
2199
  function commaSep2(rule) {
2201
2200
  return seq(rule, repeat1(seq(',', rule)));
2202
2201
  }
2203
2202
 
2204
2203
  /**
2205
- * @param {Rule} rule
2204
+ * @param {import('@willbooster/web-tree-sitter/dsl').Rule} rule
2206
2205
  *
2207
- * @returns {ChoiceRule}
2206
+ * @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
2208
2207
  */
2209
2208
  function commaSep(rule) {
2210
2209
  return optional(commaSep1(rule));
2211
2210
  }
2212
2211
 
2213
2212
  /**
2214
- * @param {RuleOrLiteral} rule
2213
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
2215
2214
  *
2216
- * @param {RuleOrLiteral} separator
2215
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} separator
2217
2216
  *
2218
- * @returns {SeqRule}
2217
+ * @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
2219
2218
  */
2220
2219
  function sep1(rule, separator) {
2221
2220
  return seq(rule, repeat(seq(separator, rule)));
2222
2221
  }
2223
2222
 
2224
2223
  /**
2225
- * @param {RuleOrLiteral} rule
2224
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
2226
2225
  *
2227
- * @param {RuleOrLiteral} separator
2226
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} separator
2228
2227
  *
2229
- * @returns {ChoiceRule}
2228
+ * @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
2230
2229
  */
2231
2230
  function sep(rule, separator) {
2232
2231
  return optional(sep1(rule, separator));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c-sharp",
3
- "version": "5.0.1",
3
+ "version": "5.0.2",
4
4
  "description": "C# grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -57,7 +57,6 @@
57
57
  "playwright": "1.63.0",
58
58
  "semantic-release": "25.0.9",
59
59
  "sort-package-json": "4.0.0",
60
- "tree-sitter-cli": "0.27.0",
61
60
  "typescript": "7.0.2",
62
61
  "vite": "8.3.2",
63
62
  "vitest": "5.0.3",
Binary file
package/tree-sitter.json CHANGED
@@ -19,7 +19,7 @@
19
19
  }
20
20
  ],
21
21
  "metadata": {
22
- "version": "5.0.1",
22
+ "version": "5.0.2",
23
23
  "license": "MIT",
24
24
  "description": "C# grammar for tree-sitter",
25
25
  "authors": [