@willbooster/tree-sitter-c-sharp 14.1.0 → 14.1.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/grammar.js +49 -13
- package/package.json +1 -1
- package/src/node-types.json +10 -0
- package/tree-sitter-c_sharp.wasm +0 -0
- package/tree-sitter.json +2 -1
package/grammar.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
const { alias, choice, field, grammar, optional, prec, repeat, repeat1, seq, sym, token } =
|
|
12
12
|
/** @type {typeof globalThis & import('@willbooster/web-tree-sitter/dsl').DSL} */ (globalThis);
|
|
13
13
|
|
|
14
|
-
/** @typedef {'_preproc_expression' | '_top_level_item_no_statement' | '_namespace_body_item' | '_base_list_mixed_type' | '_base_list_mixed_suffix' | '_base_list_trivia' | '_base_list' | '_base_list_type' | '_base_list_suffix' | '_base_list_prefix' | '_base_list_separator' | '_base_list_separator_path' | '_enum_base_clause' | '_enum_base_type' | 'attribute_list' | 'declaration' | 'enum_member_declaration' | 'expression' | 'method_signature' | 'statement'} PreprocContentRule */
|
|
14
|
+
/** @typedef {'_preproc_expression' | '_top_level_item_no_statement' | '_namespace_body_item' | '_base_list_mixed_type' | '_base_list_mixed_suffix' | '_base_list_trivia' | '_base_list' | '_base_list_type' | '_base_list_suffix' | '_base_list_prefix' | '_base_list_separator' | '_base_list_separator_path' | '_enum_base_clause' | '_enum_base_type' | '_dangling_else_if_statement' | 'attribute_list' | 'declaration' | 'enum_member_declaration' | 'expression' | 'if_statement' | 'method_signature' | 'statement'} PreprocContentRule */
|
|
15
15
|
|
|
16
16
|
const PREC = {
|
|
17
17
|
GENERIC: 19,
|
|
@@ -218,6 +218,7 @@ module.exports = grammar({
|
|
|
218
218
|
[$.type_pattern, $.declaration_pattern],
|
|
219
219
|
[$.tuple_element, $.using_variable_declarator],
|
|
220
220
|
[$.tuple_pattern, $.parameter],
|
|
221
|
+
[$.variable_declaration, $.type],
|
|
221
222
|
[$.tuple_pattern, $._simple_name],
|
|
222
223
|
[$.type, $.attribute],
|
|
223
224
|
[$.type, $.nullable_type],
|
|
@@ -347,6 +348,7 @@ module.exports = grammar({
|
|
|
347
348
|
sym('_pragma_text'),
|
|
348
349
|
sym('_expression_generic_end'),
|
|
349
350
|
sym('_definite_expression_generic_end'),
|
|
351
|
+
sym('_if_alternative_directive'),
|
|
350
352
|
],
|
|
351
353
|
|
|
352
354
|
extras: ($) => [
|
|
@@ -997,17 +999,29 @@ module.exports = grammar({
|
|
|
997
999
|
_function_body: ($) =>
|
|
998
1000
|
choice(field('body', $.block), seq(field('body', $.arrow_expression_clause), statementEnd()), statementEnd()),
|
|
999
1001
|
|
|
1000
|
-
variable_declaration: ($) =>
|
|
1002
|
+
variable_declaration: ($) =>
|
|
1003
|
+
choice(
|
|
1004
|
+
seq(field('type', $.type), commaSep1($.variable_declarator)),
|
|
1005
|
+
seq(field('type', $.implicit_type), alias($._deconstruction_declarator, $.variable_declarator))
|
|
1006
|
+
),
|
|
1007
|
+
|
|
1008
|
+
_deconstruction_declarator: ($) =>
|
|
1009
|
+
prec.dynamic(1, seq(alias($._deconstruction_tuple_pattern, $.tuple_pattern), '=', $.expression)),
|
|
1010
|
+
|
|
1011
|
+
_deconstruction_tuple_pattern: ($) =>
|
|
1012
|
+
seq(
|
|
1013
|
+
'(',
|
|
1014
|
+
commaSep2(
|
|
1015
|
+
choice(field('name', $.identifier), $.discard, alias($._deconstruction_tuple_pattern, $.tuple_pattern))
|
|
1016
|
+
),
|
|
1017
|
+
')'
|
|
1018
|
+
),
|
|
1001
1019
|
|
|
1002
1020
|
using_variable_declaration: ($) =>
|
|
1003
1021
|
seq(field('type', $.type), commaSep1(alias($.using_variable_declarator, $.variable_declarator))),
|
|
1004
1022
|
|
|
1005
1023
|
variable_declarator: ($) =>
|
|
1006
|
-
seq(
|
|
1007
|
-
choice(field('name', $.identifier), prec.dynamic(-1, $.tuple_pattern)),
|
|
1008
|
-
optional($.bracketed_argument_list),
|
|
1009
|
-
optional(seq('=', $.expression))
|
|
1010
|
-
),
|
|
1024
|
+
seq(field('name', $.identifier), optional($.bracketed_argument_list), optional(seq('=', $.expression))),
|
|
1011
1025
|
|
|
1012
1026
|
using_variable_declarator: ($) => seq(field('name', $.identifier), optional(seq('=', $.expression))),
|
|
1013
1027
|
|
|
@@ -1443,15 +1457,23 @@ module.exports = grammar({
|
|
|
1443
1457
|
if_statement: ($) =>
|
|
1444
1458
|
prec.right(
|
|
1445
1459
|
seq(
|
|
1446
|
-
|
|
1447
|
-
'(',
|
|
1448
|
-
field('condition', $.expression),
|
|
1449
|
-
')',
|
|
1450
|
-
field('consequence', $.statement),
|
|
1460
|
+
$._if_statement_head,
|
|
1461
|
+
repeat(seq(sym('_if_alternative_directive'), alias(sym('preproc_if_in_if_alternative'), sym('preproc_if')))),
|
|
1451
1462
|
optional(seq('else', field('alternative', $.statement)))
|
|
1452
1463
|
)
|
|
1453
1464
|
),
|
|
1454
1465
|
|
|
1466
|
+
_if_statement_head: ($) => seq('if', '(', field('condition', $.expression), ')', field('consequence', $.statement)),
|
|
1467
|
+
|
|
1468
|
+
// An `else` directly before a conditional directive takes the statement after the directive as its body, which a
|
|
1469
|
+
// tree cannot attach across the directive boundary.
|
|
1470
|
+
_dangling_else_if_statement: ($) =>
|
|
1471
|
+
seq(
|
|
1472
|
+
$._if_statement_head,
|
|
1473
|
+
'else',
|
|
1474
|
+
optional(field('alternative', alias($._dangling_else_if_statement, $.if_statement)))
|
|
1475
|
+
),
|
|
1476
|
+
|
|
1455
1477
|
while_statement: ($) => seq('while', '(', field('condition', $.expression), ')', field('body', $.statement)),
|
|
1456
1478
|
|
|
1457
1479
|
local_declaration_statement: ($) =>
|
|
@@ -2686,7 +2708,9 @@ module.exports = grammar({
|
|
|
2686
2708
|
...preprocIf('_in_base_list_separator', ($) => $._base_list_separator_path, 0, false, true),
|
|
2687
2709
|
...preprocIf('_in_base_list_suffix', ($) => $._base_list_suffix, 0, false),
|
|
2688
2710
|
...preprocIf('', ($) => $.declaration),
|
|
2689
|
-
...preprocIf('_in_top_level', ($) =>
|
|
2711
|
+
...preprocIf('_in_top_level', ($) => conditionalStatements($), 0, false, true),
|
|
2712
|
+
...preprocIf('_in_if_alternative', ($) => seq(optional('else'), conditionalStatements($)), 0, false),
|
|
2713
|
+
|
|
2690
2714
|
...preprocIf('_in_expression', ($) => $.expression, -2, false),
|
|
2691
2715
|
...preprocIf('_in_enum_member_declaration', ($) => $.enum_member_declaration, 0, false),
|
|
2692
2716
|
...preprocIf('_in_attribute_list', ($) => $.attribute_list, -1, false),
|
|
@@ -3097,6 +3121,18 @@ function preprocIf(suffix, content, precedence = 0, rep = true, required = false
|
|
|
3097
3121
|
};
|
|
3098
3122
|
}
|
|
3099
3123
|
|
|
3124
|
+
/**
|
|
3125
|
+
* Statements of a conditional branch, where the last may be an if statement whose `else` body follows the directive.
|
|
3126
|
+
*
|
|
3127
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<PreprocContentRule>} $
|
|
3128
|
+
*/
|
|
3129
|
+
function conditionalStatements($) {
|
|
3130
|
+
return seq(
|
|
3131
|
+
repeat(choice($._top_level_item_no_statement, $.statement)),
|
|
3132
|
+
optional(alias($._dangling_else_if_statement, $.if_statement))
|
|
3133
|
+
);
|
|
3134
|
+
}
|
|
3135
|
+
|
|
3100
3136
|
/**
|
|
3101
3137
|
* @param {'if' | 'elif'} command
|
|
3102
3138
|
* @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<PreprocContentRule>} $
|
package/package.json
CHANGED
package/src/node-types.json
CHANGED
package/tree-sitter-c_sharp.wasm
CHANGED
|
Binary file
|
package/tree-sitter.json
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"external-files": [
|
|
20
20
|
"src/genericExpressions.h",
|
|
21
21
|
"src/identifierCharacters.h",
|
|
22
|
+
"src/ifAlternativeDirective.h",
|
|
22
23
|
"src/nullableRank.h",
|
|
23
24
|
"src/nullableTypes.h",
|
|
24
25
|
"src/questionContext.h",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
}
|
|
31
32
|
],
|
|
32
33
|
"metadata": {
|
|
33
|
-
"version": "14.1.
|
|
34
|
+
"version": "14.1.2",
|
|
34
35
|
"license": "MIT",
|
|
35
36
|
"description": "C# grammar for tree-sitter",
|
|
36
37
|
"authors": [
|