@willbooster/tree-sitter-c-sharp 5.0.0 → 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 +1 -2
- package/grammar.js +158 -139
- package/package.json +1 -2
- package/tree-sitter-c_sharp.wasm +0 -0
- package/tree-sitter.json +1 -1
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.
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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(
|
|
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,
|
|
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),
|
|
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),
|
|
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(
|
|
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),
|
|
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
|
-
|
|
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: ($) =>
|
|
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(
|
|
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(
|
|
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,
|
|
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,
|
|
1450
|
+
choice($.member_binding_expression, alias($.bracketed_argument_list, sym('element_binding_expression')))
|
|
1449
1451
|
)
|
|
1450
1452
|
),
|
|
1451
1453
|
|
|
@@ -1495,46 +1497,66 @@ module.exports = grammar({
|
|
|
1495
1497
|
interpolated_string_expression: ($) =>
|
|
1496
1498
|
choice(
|
|
1497
1499
|
seq(
|
|
1498
|
-
alias(
|
|
1499
|
-
alias(
|
|
1500
|
+
alias(sym('interpolation_regular_start'), sym('interpolation_start')),
|
|
1501
|
+
alias(sym('interpolation_start_quote'), '"'),
|
|
1500
1502
|
repeat($._interpolated_string_content),
|
|
1501
|
-
alias(
|
|
1503
|
+
alias(sym('interpolation_end_quote'), '"')
|
|
1502
1504
|
),
|
|
1503
1505
|
seq(
|
|
1504
|
-
alias(
|
|
1505
|
-
alias(
|
|
1506
|
+
alias(sym('interpolation_verbatim_start'), sym('interpolation_start')),
|
|
1507
|
+
alias(sym('interpolation_start_quote'), '"'),
|
|
1506
1508
|
repeat($._interpolated_verbatim_string_content),
|
|
1507
|
-
alias(
|
|
1509
|
+
alias(sym('interpolation_end_quote'), '"')
|
|
1508
1510
|
),
|
|
1509
1511
|
seq(
|
|
1510
|
-
alias(
|
|
1511
|
-
alias(
|
|
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(
|
|
1515
|
+
alias(sym('interpolation_end_quote'), sym('interpolation_quote'))
|
|
1514
1516
|
)
|
|
1515
1517
|
),
|
|
1516
1518
|
|
|
1517
1519
|
_interpolated_string_content: ($) =>
|
|
1518
|
-
choice(alias(
|
|
1520
|
+
choice(alias(sym('interpolation_string_content'), sym('string_content')), $.escape_sequence, $.interpolation),
|
|
1519
1521
|
|
|
1520
1522
|
_interpolated_verbatim_string_content: ($) =>
|
|
1521
|
-
choice(
|
|
1523
|
+
choice(
|
|
1524
|
+
alias(sym('interpolation_string_content'), sym('string_content')),
|
|
1525
|
+
alias($._multiline_interpolation, $.interpolation)
|
|
1526
|
+
),
|
|
1522
1527
|
|
|
1523
1528
|
_interpolated_raw_string_content: ($) =>
|
|
1524
|
-
choice(
|
|
1529
|
+
choice(
|
|
1530
|
+
alias(sym('interpolation_string_content'), sym('string_content')),
|
|
1531
|
+
alias($._multiline_interpolation, $.interpolation)
|
|
1532
|
+
),
|
|
1525
1533
|
|
|
1526
1534
|
interpolation: ($) =>
|
|
1527
1535
|
seq(
|
|
1528
|
-
alias(
|
|
1536
|
+
alias(sym('interpolation_open_brace'), sym('interpolation_brace')),
|
|
1529
1537
|
$.expression,
|
|
1530
1538
|
optional($.interpolation_alignment_clause),
|
|
1531
|
-
|
|
1532
|
-
|
|
1539
|
+
choice(
|
|
1540
|
+
alias(sym('interpolation_close_brace'), sym('interpolation_brace')),
|
|
1541
|
+
seq($.interpolation_format_clause, alias(token.immediate('}'), sym('interpolation_brace')))
|
|
1542
|
+
)
|
|
1533
1543
|
),
|
|
1534
1544
|
|
|
1535
1545
|
interpolation_alignment_clause: ($) => seq(',', $.expression),
|
|
1536
1546
|
|
|
1537
|
-
interpolation_format_clause: (
|
|
1547
|
+
interpolation_format_clause: () =>
|
|
1548
|
+
seq(':', optional(sym('_file_directive_literal_context')), token.immediate(/[^}"\n\r\u0085\u2028\u2029]+/)),
|
|
1549
|
+
|
|
1550
|
+
_multiline_interpolation: ($) =>
|
|
1551
|
+
seq(
|
|
1552
|
+
alias(sym('interpolation_open_brace'), sym('interpolation_brace')),
|
|
1553
|
+
$.expression,
|
|
1554
|
+
optional($.interpolation_alignment_clause),
|
|
1555
|
+
optional(alias($._multiline_interpolation_format_clause, $.interpolation_format_clause)),
|
|
1556
|
+
alias(sym('interpolation_close_brace'), sym('interpolation_brace'))
|
|
1557
|
+
),
|
|
1558
|
+
|
|
1559
|
+
_multiline_interpolation_format_clause: () => seq(':', optional(sym('_file_directive_literal_context')), /[^}"]+/),
|
|
1538
1560
|
|
|
1539
1561
|
member_access_expression: ($) =>
|
|
1540
1562
|
prec(
|
|
@@ -1574,7 +1596,7 @@ module.exports = grammar({
|
|
|
1574
1596
|
repeat($._attribute_list),
|
|
1575
1597
|
repeat(prec.dynamic(1, alias(choice('static', 'async'), $.modifier))),
|
|
1576
1598
|
choice(
|
|
1577
|
-
field('parameters', prec(-1, alias($.identifier,
|
|
1599
|
+
field('parameters', prec(-1, alias($.identifier, sym('implicit_parameter')))),
|
|
1578
1600
|
seq(optional(field('type', $.type)), field('parameters', $._lambda_parameters))
|
|
1579
1601
|
)
|
|
1580
1602
|
)
|
|
@@ -1599,14 +1621,14 @@ module.exports = grammar({
|
|
|
1599
1621
|
// external _lambda_paren_open; the closing ')' is the regular literal.
|
|
1600
1622
|
_implicit_parameter_list_with_modifiers: ($) =>
|
|
1601
1623
|
seq(
|
|
1602
|
-
|
|
1624
|
+
sym('_lambda_paren_open'),
|
|
1603
1625
|
commaSep1(
|
|
1604
1626
|
choice(
|
|
1605
1627
|
seq(
|
|
1606
1628
|
repeat1(alias(choice('scoped', 'ref', 'out', 'in', 'readonly'), $.modifier)),
|
|
1607
|
-
alias($.identifier,
|
|
1629
|
+
alias($.identifier, sym('implicit_parameter'))
|
|
1608
1630
|
),
|
|
1609
|
-
alias($.identifier,
|
|
1631
|
+
alias($.identifier, sym('implicit_parameter'))
|
|
1610
1632
|
)
|
|
1611
1633
|
),
|
|
1612
1634
|
')'
|
|
@@ -1729,7 +1751,7 @@ module.exports = grammar({
|
|
|
1729
1751
|
string_literal: ($) =>
|
|
1730
1752
|
seq(
|
|
1731
1753
|
'"',
|
|
1732
|
-
repeat(choice($.string_literal_content, $.escape_sequence,
|
|
1754
|
+
repeat(choice($.string_literal_content, $.escape_sequence, sym('_file_directive_literal_context'))),
|
|
1733
1755
|
token.immediate('"'),
|
|
1734
1756
|
optional($.string_literal_encoding)
|
|
1735
1757
|
),
|
|
@@ -1743,8 +1765,8 @@ module.exports = grammar({
|
|
|
1743
1765
|
|
|
1744
1766
|
verbatim_string_literal: () => token(seq('@"', repeat(choice(/[^"]/, '""')), '"', optional(stringEncoding))),
|
|
1745
1767
|
|
|
1746
|
-
raw_string_literal: (
|
|
1747
|
-
seq(
|
|
1768
|
+
raw_string_literal: () =>
|
|
1769
|
+
seq(sym('raw_string_start'), sym('raw_string_content'), sym('raw_string_end'), optional(stringEncoding)),
|
|
1748
1770
|
|
|
1749
1771
|
boolean_literal: () => choice('true', 'false'),
|
|
1750
1772
|
|
|
@@ -1801,7 +1823,7 @@ module.exports = grammar({
|
|
|
1801
1823
|
|
|
1802
1824
|
...preprocIf(
|
|
1803
1825
|
'_in_method_signature',
|
|
1804
|
-
($) => choice($.method_signature, alias(
|
|
1826
|
+
($) => choice($.method_signature, alias(sym('preproc_if_in_method_signature'), sym('preproc_if'))),
|
|
1805
1827
|
0,
|
|
1806
1828
|
false,
|
|
1807
1829
|
true
|
|
@@ -1817,7 +1839,7 @@ module.exports = grammar({
|
|
|
1817
1839
|
token(prec(-1, /[^\s\u0085\u2028\u2029]([^/\r\n\u0085\u2028\u2029]|\/[^*\r\n\u0085\u2028\u2029])*/)),
|
|
1818
1840
|
optional($._preproc_arg_slash)
|
|
1819
1841
|
),
|
|
1820
|
-
_file_directive_argument: ($) => seq(
|
|
1842
|
+
_file_directive_argument: ($) => seq(sym('_file_directive_preproc_arg'), optional($._preproc_arg_slash)),
|
|
1821
1843
|
_preproc_arg_slash: () => token.immediate(/\//),
|
|
1822
1844
|
preproc_directive: () => /#[ \t]*[a-zA-Z0-9]\w*/,
|
|
1823
1845
|
|
|
@@ -1827,7 +1849,7 @@ module.exports = grammar({
|
|
|
1827
1849
|
$.boolean_literal,
|
|
1828
1850
|
$.integer_literal,
|
|
1829
1851
|
$.character_literal,
|
|
1830
|
-
alias($.preproc_unary_expression,
|
|
1852
|
+
alias($.preproc_unary_expression, sym('unary_expression')),
|
|
1831
1853
|
alias($.preproc_binary_expression, $.binary_expression),
|
|
1832
1854
|
alias($.preproc_parenthesized_expression, $.parenthesized_expression)
|
|
1833
1855
|
),
|
|
@@ -1838,6 +1860,7 @@ module.exports = grammar({
|
|
|
1838
1860
|
prec.left(PREC.UNARY, seq(field('operator', '!'), field('argument', $._preproc_expression))),
|
|
1839
1861
|
|
|
1840
1862
|
preproc_binary_expression: ($) => {
|
|
1863
|
+
/** @type {[string, number][]} */
|
|
1841
1864
|
const table = [
|
|
1842
1865
|
['||', PREC.LOGICAL_OR],
|
|
1843
1866
|
['&&', PREC.LOGICAL_AND],
|
|
@@ -1851,7 +1874,6 @@ module.exports = grammar({
|
|
|
1851
1874
|
precedence,
|
|
1852
1875
|
seq(
|
|
1853
1876
|
field('left', $._preproc_expression),
|
|
1854
|
-
// @ts-ignore
|
|
1855
1877
|
field('operator', operator),
|
|
1856
1878
|
field('right', $._preproc_expression)
|
|
1857
1879
|
)
|
|
@@ -1864,14 +1886,14 @@ module.exports = grammar({
|
|
|
1864
1886
|
seq(
|
|
1865
1887
|
preprocessor('region'),
|
|
1866
1888
|
optional(field('content', choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)))),
|
|
1867
|
-
directiveEnd(
|
|
1889
|
+
directiveEnd()
|
|
1868
1890
|
),
|
|
1869
1891
|
|
|
1870
1892
|
preproc_endregion: ($) =>
|
|
1871
1893
|
seq(
|
|
1872
1894
|
preprocessor('endregion'),
|
|
1873
1895
|
optional(field('content', choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)))),
|
|
1874
|
-
directiveEnd(
|
|
1896
|
+
directiveEnd()
|
|
1875
1897
|
),
|
|
1876
1898
|
|
|
1877
1899
|
preproc_line: ($) =>
|
|
@@ -1897,7 +1919,7 @@ module.exports = grammar({
|
|
|
1897
1919
|
alias($._preproc_filename, $.string_literal)
|
|
1898
1920
|
)
|
|
1899
1921
|
),
|
|
1900
|
-
directiveEnd(
|
|
1922
|
+
directiveEnd()
|
|
1901
1923
|
),
|
|
1902
1924
|
|
|
1903
1925
|
_preproc_filename: ($) =>
|
|
@@ -1906,7 +1928,7 @@ module.exports = grammar({
|
|
|
1906
1928
|
repeat(
|
|
1907
1929
|
choice(
|
|
1908
1930
|
$.string_literal_content,
|
|
1909
|
-
|
|
1931
|
+
sym('_file_directive_literal_context'),
|
|
1910
1932
|
alias(token.immediate(prec(-1, '\\')), $.string_literal_content),
|
|
1911
1933
|
alias(
|
|
1912
1934
|
token.immediate(
|
|
@@ -1926,43 +1948,43 @@ module.exports = grammar({
|
|
|
1926
1948
|
seq('warning', choice('disable', 'restore'), commaSep(choice($.identifier, $.integer_literal))),
|
|
1927
1949
|
seq('checksum', alias($._preproc_filename, $.string_literal), $.string_literal, $.string_literal)
|
|
1928
1950
|
),
|
|
1929
|
-
directiveEnd(
|
|
1951
|
+
directiveEnd()
|
|
1930
1952
|
),
|
|
1931
1953
|
|
|
1932
|
-
preproc_nullable: (
|
|
1954
|
+
preproc_nullable: () =>
|
|
1933
1955
|
seq(
|
|
1934
1956
|
preprocessor('nullable'),
|
|
1935
1957
|
choice('enable', 'disable', 'restore'),
|
|
1936
1958
|
optional(choice('annotations', 'warnings')),
|
|
1937
|
-
directiveEnd(
|
|
1959
|
+
directiveEnd()
|
|
1938
1960
|
),
|
|
1939
1961
|
|
|
1940
1962
|
preproc_error: ($) =>
|
|
1941
1963
|
seq(
|
|
1942
1964
|
preprocessor('error'),
|
|
1943
1965
|
choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)),
|
|
1944
|
-
directiveEnd(
|
|
1966
|
+
directiveEnd()
|
|
1945
1967
|
),
|
|
1946
1968
|
|
|
1947
1969
|
preproc_warning: ($) =>
|
|
1948
1970
|
seq(
|
|
1949
1971
|
preprocessor('warning'),
|
|
1950
1972
|
choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)),
|
|
1951
|
-
directiveEnd(
|
|
1973
|
+
directiveEnd()
|
|
1952
1974
|
),
|
|
1953
1975
|
|
|
1954
1976
|
preproc_define: ($) =>
|
|
1955
1977
|
seq(
|
|
1956
1978
|
preprocessor('define'),
|
|
1957
1979
|
choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)),
|
|
1958
|
-
directiveEnd(
|
|
1980
|
+
directiveEnd()
|
|
1959
1981
|
),
|
|
1960
1982
|
|
|
1961
1983
|
preproc_undef: ($) =>
|
|
1962
1984
|
seq(
|
|
1963
1985
|
preprocessor('undef'),
|
|
1964
1986
|
choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)),
|
|
1965
|
-
directiveEnd(
|
|
1987
|
+
directiveEnd()
|
|
1966
1988
|
),
|
|
1967
1989
|
|
|
1968
1990
|
file_directive: ($) =>
|
|
@@ -1970,27 +1992,27 @@ module.exports = grammar({
|
|
|
1970
1992
|
choice(
|
|
1971
1993
|
fileDirectiveArguments(
|
|
1972
1994
|
$,
|
|
1973
|
-
choice(alias(
|
|
1995
|
+
choice(alias(sym('_file_directive_sdk'), '#:sdk'), alias(sym('_file_directive_package'), '#:package')),
|
|
1974
1996
|
'@',
|
|
1975
1997
|
'metadata'
|
|
1976
1998
|
),
|
|
1977
|
-
fileDirectiveArguments($, alias(
|
|
1999
|
+
fileDirectiveArguments($, alias(sym('_file_directive_property'), '#:property'), '=', 'value'),
|
|
1978
2000
|
seq(
|
|
1979
2001
|
choice(
|
|
1980
|
-
alias(
|
|
1981
|
-
alias(
|
|
1982
|
-
alias(
|
|
1983
|
-
alias(
|
|
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')
|
|
1984
2006
|
),
|
|
1985
2007
|
optional(seq($._file_directive_spacing, field('value', $.file_directive_value)))
|
|
1986
2008
|
),
|
|
1987
2009
|
seq(
|
|
1988
|
-
|
|
2010
|
+
sym('file_directive_kind'),
|
|
1989
2011
|
optional(seq($._file_directive_spacing, optional(field('value', $.file_directive_value))))
|
|
1990
2012
|
)
|
|
1991
2013
|
),
|
|
1992
2014
|
optional($._file_directive_spacing),
|
|
1993
|
-
choice(
|
|
2015
|
+
choice(sym('_file_directive_newline'), sym('_end_of_input'))
|
|
1994
2016
|
),
|
|
1995
2017
|
|
|
1996
2018
|
_file_directive_spacing: () => token.immediate(prec(1, new RegExp(`[${directiveHorizontal}]+`))),
|
|
@@ -2021,11 +2043,11 @@ module.exports = grammar({
|
|
|
2021
2043
|
});
|
|
2022
2044
|
|
|
2023
2045
|
/**
|
|
2024
|
-
* @param {GrammarSymbols<
|
|
2025
|
-
* @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
|
|
2026
2048
|
* @param {string} separator
|
|
2027
2049
|
* @param {string} extraField
|
|
2028
|
-
* @returns {SeqRule}
|
|
2050
|
+
* @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
|
|
2029
2051
|
*/
|
|
2030
2052
|
function fileDirectiveArguments($, kind, separator, extraField) {
|
|
2031
2053
|
return seq(
|
|
@@ -2059,23 +2081,20 @@ function fileDirectiveArguments($, kind, separator, extraField) {
|
|
|
2059
2081
|
* Ends a directive that opens no conditional section: at a line break, or at the end of the input, which a file may
|
|
2060
2082
|
* reach without a final line break.
|
|
2061
2083
|
*
|
|
2062
|
-
* @
|
|
2063
|
-
*
|
|
2064
|
-
* @returns {ChoiceRule}
|
|
2084
|
+
* @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
|
|
2065
2085
|
*/
|
|
2066
|
-
function directiveEnd(
|
|
2067
|
-
return choice(directiveNewLine(
|
|
2086
|
+
function directiveEnd() {
|
|
2087
|
+
return choice(directiveNewLine(), sym('_end_of_input'));
|
|
2068
2088
|
}
|
|
2069
2089
|
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
return $._directive_newline;
|
|
2090
|
+
function directiveNewLine() {
|
|
2091
|
+
return sym('_directive_newline');
|
|
2073
2092
|
}
|
|
2074
2093
|
|
|
2075
2094
|
/**
|
|
2076
2095
|
* @param {string} command
|
|
2077
2096
|
*
|
|
2078
|
-
* @returns {AliasRule}
|
|
2097
|
+
* @returns {import('@willbooster/web-tree-sitter/dsl').AliasRule}
|
|
2079
2098
|
*/
|
|
2080
2099
|
function preprocessor(command) {
|
|
2081
2100
|
return alias(new RegExp('#[ \t]*' + command), '#' + command);
|
|
@@ -2085,7 +2104,7 @@ function preprocessor(command) {
|
|
|
2085
2104
|
*
|
|
2086
2105
|
* @param {string} suffix
|
|
2087
2106
|
*
|
|
2088
|
-
* @param {RuleBuilder<
|
|
2107
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleBuilder<PreprocContentRule>} content
|
|
2089
2108
|
*
|
|
2090
2109
|
* @param {number} precedence
|
|
2091
2110
|
*
|
|
@@ -2093,19 +2112,23 @@ function preprocessor(command) {
|
|
|
2093
2112
|
*
|
|
2094
2113
|
* @param {boolean} required
|
|
2095
2114
|
*
|
|
2096
|
-
* @returns {
|
|
2115
|
+
* @returns {Record<string, import('@willbooster/web-tree-sitter/dsl').RuleBuilder<PreprocContentRule>>}
|
|
2097
2116
|
*/
|
|
2098
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
|
+
|
|
2099
2124
|
/**
|
|
2100
2125
|
*
|
|
2101
|
-
* @
|
|
2102
|
-
*
|
|
2103
|
-
* @returns {ChoiceRule}
|
|
2126
|
+
* @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
|
|
2104
2127
|
*/
|
|
2105
|
-
function alternativeBlock(
|
|
2128
|
+
function alternativeBlock() {
|
|
2106
2129
|
return choice(
|
|
2107
|
-
suffix ? alias(
|
|
2108
|
-
suffix ? alias(
|
|
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')
|
|
2109
2132
|
);
|
|
2110
2133
|
}
|
|
2111
2134
|
|
|
@@ -2116,18 +2139,14 @@ function preprocIf(suffix, content, precedence = 0, rep = true, required = false
|
|
|
2116
2139
|
seq(
|
|
2117
2140
|
preprocessor('if'),
|
|
2118
2141
|
field('condition', $._preproc_expression),
|
|
2119
|
-
directiveNewLine(
|
|
2120
|
-
|
|
2121
|
-
field('alternative', optional(alternativeBlock(
|
|
2142
|
+
directiveNewLine(),
|
|
2143
|
+
contentRule($),
|
|
2144
|
+
field('alternative', optional(alternativeBlock())),
|
|
2122
2145
|
preprocessor('endif')
|
|
2123
2146
|
)
|
|
2124
2147
|
),
|
|
2125
2148
|
|
|
2126
|
-
['preproc_else' + suffix]: ($) =>
|
|
2127
|
-
prec(
|
|
2128
|
-
precedence,
|
|
2129
|
-
seq(preprocessor('else'), rep ? repeat(content($)) : required ? content($) : optional(content($)))
|
|
2130
|
-
),
|
|
2149
|
+
['preproc_else' + suffix]: ($) => prec(precedence, seq(preprocessor('else'), contentRule($))),
|
|
2131
2150
|
|
|
2132
2151
|
['preproc_elif' + suffix]: ($) =>
|
|
2133
2152
|
prec(
|
|
@@ -2135,9 +2154,9 @@ function preprocIf(suffix, content, precedence = 0, rep = true, required = false
|
|
|
2135
2154
|
seq(
|
|
2136
2155
|
preprocessor('elif'),
|
|
2137
2156
|
field('condition', $._preproc_expression),
|
|
2138
|
-
directiveNewLine(
|
|
2139
|
-
|
|
2140
|
-
field('alternative', optional(alternativeBlock(
|
|
2157
|
+
directiveNewLine(),
|
|
2158
|
+
contentRule($),
|
|
2159
|
+
field('alternative', optional(alternativeBlock()))
|
|
2141
2160
|
)
|
|
2142
2161
|
),
|
|
2143
2162
|
};
|
|
@@ -2149,9 +2168,9 @@ function preprocIf(suffix, content, precedence = 0, rep = true, required = false
|
|
|
2149
2168
|
* through `expression` would reduce the unary operator or the cast (precedence UNARY or CAST) before `expression`
|
|
2150
2169
|
* (precedence 0) lets the postfix operator apply, reading `&a[0]` as `(&a)[0]` and `*(T*)f()[0]` as `(*(T*)f())[0]`.
|
|
2151
2170
|
*
|
|
2152
|
-
* @param {GrammarSymbols<
|
|
2171
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'expression' | 'invocation_expression' | 'lvalue_expression' | 'parenthesized_expression' | 'postfix_unary_expression'>} $
|
|
2153
2172
|
*
|
|
2154
|
-
* @returns {ChoiceRule}
|
|
2173
|
+
* @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
|
|
2155
2174
|
*/
|
|
2156
2175
|
function postfixOperand($) {
|
|
2157
2176
|
return choice(
|
|
@@ -2164,49 +2183,49 @@ function postfixOperand($) {
|
|
|
2164
2183
|
}
|
|
2165
2184
|
|
|
2166
2185
|
/**
|
|
2167
|
-
* @param {Rule} rule
|
|
2186
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').Rule} rule
|
|
2168
2187
|
*
|
|
2169
|
-
* @returns {SeqRule}
|
|
2188
|
+
* @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
|
|
2170
2189
|
*/
|
|
2171
2190
|
function commaSep1(rule) {
|
|
2172
2191
|
return seq(rule, repeat(seq(',', rule)));
|
|
2173
2192
|
}
|
|
2174
2193
|
|
|
2175
2194
|
/**
|
|
2176
|
-
* @param {Rule} rule
|
|
2195
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').Rule} rule
|
|
2177
2196
|
*
|
|
2178
|
-
* @returns {SeqRule}
|
|
2197
|
+
* @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
|
|
2179
2198
|
*/
|
|
2180
2199
|
function commaSep2(rule) {
|
|
2181
2200
|
return seq(rule, repeat1(seq(',', rule)));
|
|
2182
2201
|
}
|
|
2183
2202
|
|
|
2184
2203
|
/**
|
|
2185
|
-
* @param {Rule} rule
|
|
2204
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').Rule} rule
|
|
2186
2205
|
*
|
|
2187
|
-
* @returns {ChoiceRule}
|
|
2206
|
+
* @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
|
|
2188
2207
|
*/
|
|
2189
2208
|
function commaSep(rule) {
|
|
2190
2209
|
return optional(commaSep1(rule));
|
|
2191
2210
|
}
|
|
2192
2211
|
|
|
2193
2212
|
/**
|
|
2194
|
-
* @param {RuleOrLiteral} rule
|
|
2213
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
|
|
2195
2214
|
*
|
|
2196
|
-
* @param {RuleOrLiteral} separator
|
|
2215
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} separator
|
|
2197
2216
|
*
|
|
2198
|
-
* @returns {SeqRule}
|
|
2217
|
+
* @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
|
|
2199
2218
|
*/
|
|
2200
2219
|
function sep1(rule, separator) {
|
|
2201
2220
|
return seq(rule, repeat(seq(separator, rule)));
|
|
2202
2221
|
}
|
|
2203
2222
|
|
|
2204
2223
|
/**
|
|
2205
|
-
* @param {RuleOrLiteral} rule
|
|
2224
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
|
|
2206
2225
|
*
|
|
2207
|
-
* @param {RuleOrLiteral} separator
|
|
2226
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} separator
|
|
2208
2227
|
*
|
|
2209
|
-
* @returns {ChoiceRule}
|
|
2228
|
+
* @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
|
|
2210
2229
|
*/
|
|
2211
2230
|
function sep(rule, separator) {
|
|
2212
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.
|
|
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",
|
package/tree-sitter-c_sharp.wasm
CHANGED
|
Binary file
|