@willbooster/tree-sitter-c-sharp 1.0.21 → 1.0.23
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 +28 -47
- package/package.json +1 -1
- package/queries/highlights.scm +1 -0
- package/queries/tags.scm +2 -0
- package/src/node-types.json +122 -0
- package/tree-sitter-c_sharp.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -435,8 +435,6 @@ module.exports = grammar({
|
|
|
435
435
|
'<',
|
|
436
436
|
'>=',
|
|
437
437
|
'<=',
|
|
438
|
-
// C# 14: user-defined compound assignment operators.
|
|
439
|
-
// https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-14#user-defined-compound-assignment-operators
|
|
440
438
|
'+=',
|
|
441
439
|
'-=',
|
|
442
440
|
'*=',
|
|
@@ -482,6 +480,7 @@ module.exports = grammar({
|
|
|
482
480
|
$.delegate_declaration,
|
|
483
481
|
$.field_declaration,
|
|
484
482
|
$.method_declaration,
|
|
483
|
+
$.conditional_method_declaration,
|
|
485
484
|
$.event_declaration,
|
|
486
485
|
$.event_field_declaration,
|
|
487
486
|
$.record_declaration,
|
|
@@ -502,14 +501,6 @@ module.exports = grammar({
|
|
|
502
501
|
// and operators with a shared receiver inside a non-generic static class.
|
|
503
502
|
// https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-14.0/extensions
|
|
504
503
|
//
|
|
505
|
-
// extension_declaration:
|
|
506
|
-
// 'extension' type_parameter_list? '(' receiver_parameter ')'
|
|
507
|
-
// type_parameter_constraints_clause* extension_body
|
|
508
|
-
// extension_body: '{' extension_member_declaration* '}' ';'?
|
|
509
|
-
// extension_member_declaration:
|
|
510
|
-
// method_declaration | property_declaration | operator_declaration
|
|
511
|
-
// receiver_parameter: attributes? parameter_modifiers? type identifier?
|
|
512
|
-
//
|
|
513
504
|
// `extension` is contextual; it is recognized as the start of an
|
|
514
505
|
// extension declaration when followed by `<` or `(` in declaration
|
|
515
506
|
// position. Use prec.dynamic so an identifier named `extension` in
|
|
@@ -535,7 +526,8 @@ module.exports = grammar({
|
|
|
535
526
|
|
|
536
527
|
extension_body: ($) => seq('{', repeat($._extension_member_declaration), '}', optional(';')),
|
|
537
528
|
|
|
538
|
-
_extension_member_declaration: ($) =>
|
|
529
|
+
_extension_member_declaration: ($) =>
|
|
530
|
+
choice($.method_declaration, $.conditional_method_declaration, $.property_declaration, $.operator_declaration),
|
|
539
531
|
|
|
540
532
|
field_declaration: ($) => seq(repeat($._attribute_list), repeat($.modifier), $.variable_declaration, ';'),
|
|
541
533
|
|
|
@@ -563,7 +555,13 @@ module.exports = grammar({
|
|
|
563
555
|
$._function_body
|
|
564
556
|
),
|
|
565
557
|
|
|
566
|
-
method_declaration: ($) =>
|
|
558
|
+
method_declaration: ($) => seq($._method_signature, $._function_body),
|
|
559
|
+
|
|
560
|
+
conditional_method_declaration: ($) => seq(alias($.preproc_if_in_method_signature, $.preproc_if), $._function_body),
|
|
561
|
+
|
|
562
|
+
method_signature: ($) => $._method_signature,
|
|
563
|
+
|
|
564
|
+
_method_signature: ($) =>
|
|
567
565
|
seq(
|
|
568
566
|
repeat($._attribute_list),
|
|
569
567
|
repeat($.modifier),
|
|
@@ -572,8 +570,7 @@ module.exports = grammar({
|
|
|
572
570
|
field('name', $.identifier),
|
|
573
571
|
field('type_parameters', optional($.type_parameter_list)),
|
|
574
572
|
field('parameters', $.parameter_list),
|
|
575
|
-
repeat($.type_parameter_constraints_clause)
|
|
576
|
-
$._function_body
|
|
573
|
+
repeat($.type_parameter_constraints_clause)
|
|
577
574
|
),
|
|
578
575
|
|
|
579
576
|
event_declaration: ($) =>
|
|
@@ -1018,7 +1015,6 @@ module.exports = grammar({
|
|
|
1018
1015
|
// Invocation with name - creates conflict with recursive_pattern's Name(positional_pattern_clause)
|
|
1019
1016
|
_name_invocation_pattern: ($) => seq(field('function', $._name), field('arguments', $.argument_list)),
|
|
1020
1017
|
|
|
1021
|
-
// Invocation where function is not a simple name
|
|
1022
1018
|
// One above `invocation_expression`, which reads the same tokens where both fit.
|
|
1023
1019
|
_complex_invocation_expression: ($) =>
|
|
1024
1020
|
prec(
|
|
@@ -1067,15 +1063,11 @@ module.exports = grammar({
|
|
|
1067
1063
|
)
|
|
1068
1064
|
),
|
|
1069
1065
|
|
|
1070
|
-
// C# 11 slice pattern: `..` optionally followed by a subpattern that
|
|
1071
|
-
// binds the captured slice. `[a, .. var rest, z]`, `[..]` (bare),
|
|
1072
|
-
// `[.. List<int> rest]` (declaration_pattern), etc.
|
|
1073
1066
|
slice_pattern: ($) => prec.right(seq('..', optional($.pattern))),
|
|
1074
1067
|
|
|
1075
1068
|
recursive_pattern: ($) =>
|
|
1076
1069
|
prec.left(
|
|
1077
1070
|
choice(
|
|
1078
|
-
// name followed by positional pattern WITH variable designation
|
|
1079
1071
|
prec.dynamic(
|
|
1080
1072
|
1,
|
|
1081
1073
|
seq(
|
|
@@ -1085,16 +1077,12 @@ module.exports = grammar({
|
|
|
1085
1077
|
$._simple_designation
|
|
1086
1078
|
)
|
|
1087
1079
|
),
|
|
1088
|
-
// name followed by positional pattern WITHOUT variable designation
|
|
1089
1080
|
prec.dynamic(
|
|
1090
1081
|
-1,
|
|
1091
1082
|
seq(field('type', $._name), $.positional_pattern_clause, optional($.property_pattern_clause))
|
|
1092
1083
|
),
|
|
1093
|
-
// positional pattern with variable designation (no type prefix)
|
|
1094
1084
|
prec.dynamic(1, seq($.positional_pattern_clause, $._simple_designation)),
|
|
1095
|
-
// positional pattern without variable designation (no type prefix)
|
|
1096
1085
|
$.positional_pattern_clause,
|
|
1097
|
-
// other type followed by a property pattern clause
|
|
1098
1086
|
seq(field('type', $.type), $.property_pattern_clause, optional($._simple_designation)),
|
|
1099
1087
|
// A positional clause follows only a name (above), a predefined type, or an array type. Letting any type take
|
|
1100
1088
|
// one reads `Name(A.B)` once more, through `type`; after a syntax error, the extra GLR versions then exceed
|
|
@@ -1166,10 +1154,6 @@ module.exports = grammar({
|
|
|
1166
1154
|
$.typeof_expression,
|
|
1167
1155
|
$.makeref_expression,
|
|
1168
1156
|
$.ref_expression,
|
|
1169
|
-
// Address-of (see `_address_of_expression` below): aliased to
|
|
1170
|
-
// `prefix_unary_expression` to preserve the public AST shape.
|
|
1171
|
-
// Parallels `_pointer_indirection_expression` (the `*` operator),
|
|
1172
|
-
// which is similarly aliased back into `lvalue_expression`.
|
|
1173
1157
|
alias($._address_of_expression, $.prefix_unary_expression),
|
|
1174
1158
|
alias($._value_indirection_expression, $.prefix_unary_expression),
|
|
1175
1159
|
$.reftype_expression,
|
|
@@ -1504,7 +1488,6 @@ module.exports = grammar({
|
|
|
1504
1488
|
)
|
|
1505
1489
|
),
|
|
1506
1490
|
|
|
1507
|
-
// inline
|
|
1508
1491
|
_object_creation_type: ($) => choice($._name, $.nullable_type, $.predefined_type),
|
|
1509
1492
|
|
|
1510
1493
|
parenthesized_expression: ($) => seq('(', $.non_lvalue_expression, ')'),
|
|
@@ -1626,7 +1609,7 @@ module.exports = grammar({
|
|
|
1626
1609
|
seq(
|
|
1627
1610
|
optional(seq(field('name', $.identifier), ':')),
|
|
1628
1611
|
optional(choice('ref', 'out', 'in')),
|
|
1629
|
-
choice($.expression, $.declaration_expression)
|
|
1612
|
+
choice($.expression, prec.dynamic(-1, $.declaration_expression))
|
|
1630
1613
|
)
|
|
1631
1614
|
),
|
|
1632
1615
|
|
|
@@ -1741,8 +1724,13 @@ module.exports = grammar({
|
|
|
1741
1724
|
'yield'
|
|
1742
1725
|
),
|
|
1743
1726
|
|
|
1744
|
-
|
|
1745
|
-
|
|
1727
|
+
...preprocIf(
|
|
1728
|
+
'_in_method_signature',
|
|
1729
|
+
($) => choice($.method_signature, alias($.preproc_if_in_method_signature, $.preproc_if)),
|
|
1730
|
+
0,
|
|
1731
|
+
false,
|
|
1732
|
+
true
|
|
1733
|
+
),
|
|
1746
1734
|
...preprocIf('', ($) => $.declaration),
|
|
1747
1735
|
...preprocIf('_in_top_level', ($) => choice($._top_level_item_no_statement, $.statement)),
|
|
1748
1736
|
...preprocIf('_in_expression', ($) => $.expression, -2, false),
|
|
@@ -1885,8 +1873,6 @@ function directiveEnd($) {
|
|
|
1885
1873
|
}
|
|
1886
1874
|
|
|
1887
1875
|
/**
|
|
1888
|
-
* Creates a preprocessor regex rule
|
|
1889
|
-
*
|
|
1890
1876
|
* @param {string} command
|
|
1891
1877
|
*
|
|
1892
1878
|
* @returns {AliasRule}
|
|
@@ -1905,9 +1891,11 @@ function preprocessor(command) {
|
|
|
1905
1891
|
*
|
|
1906
1892
|
* @param {boolean} rep
|
|
1907
1893
|
*
|
|
1894
|
+
* @param {boolean} required
|
|
1895
|
+
*
|
|
1908
1896
|
* @returns {RuleBuilders<string, string>}
|
|
1909
1897
|
*/
|
|
1910
|
-
function preprocIf(suffix, content, precedence = 0, rep = true) {
|
|
1898
|
+
function preprocIf(suffix, content, precedence = 0, rep = true, required = false) {
|
|
1911
1899
|
/**
|
|
1912
1900
|
*
|
|
1913
1901
|
* @param {GrammarSymbols<string>} $
|
|
@@ -1929,14 +1917,17 @@ function preprocIf(suffix, content, precedence = 0, rep = true) {
|
|
|
1929
1917
|
preprocessor('if'),
|
|
1930
1918
|
field('condition', $._preproc_expression),
|
|
1931
1919
|
/\n/,
|
|
1932
|
-
rep ? repeat(content($)) : optional(content($)),
|
|
1920
|
+
rep ? repeat(content($)) : required ? content($) : optional(content($)),
|
|
1933
1921
|
field('alternative', optional(alternativeBlock($))),
|
|
1934
1922
|
preprocessor('endif')
|
|
1935
1923
|
)
|
|
1936
1924
|
),
|
|
1937
1925
|
|
|
1938
1926
|
['preproc_else' + suffix]: ($) =>
|
|
1939
|
-
prec(
|
|
1927
|
+
prec(
|
|
1928
|
+
precedence,
|
|
1929
|
+
seq(preprocessor('else'), rep ? repeat(content($)) : required ? content($) : optional(content($)))
|
|
1930
|
+
),
|
|
1940
1931
|
|
|
1941
1932
|
['preproc_elif' + suffix]: ($) =>
|
|
1942
1933
|
prec(
|
|
@@ -1945,7 +1936,7 @@ function preprocIf(suffix, content, precedence = 0, rep = true) {
|
|
|
1945
1936
|
preprocessor('elif'),
|
|
1946
1937
|
field('condition', $._preproc_expression),
|
|
1947
1938
|
/\n/,
|
|
1948
|
-
rep ? repeat(content($)) : optional(content($)),
|
|
1939
|
+
rep ? repeat(content($)) : required ? content($) : optional(content($)),
|
|
1949
1940
|
field('alternative', optional(alternativeBlock($)))
|
|
1950
1941
|
)
|
|
1951
1942
|
),
|
|
@@ -1973,8 +1964,6 @@ function postfixOperand($) {
|
|
|
1973
1964
|
}
|
|
1974
1965
|
|
|
1975
1966
|
/**
|
|
1976
|
-
* Creates a rule to match one or more of the rules separated by a comma
|
|
1977
|
-
*
|
|
1978
1967
|
* @param {Rule} rule
|
|
1979
1968
|
*
|
|
1980
1969
|
* @returns {SeqRule}
|
|
@@ -1984,8 +1973,6 @@ function commaSep1(rule) {
|
|
|
1984
1973
|
}
|
|
1985
1974
|
|
|
1986
1975
|
/**
|
|
1987
|
-
* Creates a rule to match two or more of the rules separated by a comma
|
|
1988
|
-
*
|
|
1989
1976
|
* @param {Rule} rule
|
|
1990
1977
|
*
|
|
1991
1978
|
* @returns {SeqRule}
|
|
@@ -1995,8 +1982,6 @@ function commaSep2(rule) {
|
|
|
1995
1982
|
}
|
|
1996
1983
|
|
|
1997
1984
|
/**
|
|
1998
|
-
* Creates a rule to optionally match one or more of the rules separated by a comma
|
|
1999
|
-
*
|
|
2000
1985
|
* @param {Rule} rule
|
|
2001
1986
|
*
|
|
2002
1987
|
* @returns {ChoiceRule}
|
|
@@ -2006,8 +1991,6 @@ function commaSep(rule) {
|
|
|
2006
1991
|
}
|
|
2007
1992
|
|
|
2008
1993
|
/**
|
|
2009
|
-
* Creates a rule to match one or more of the rules separated by `separator`
|
|
2010
|
-
*
|
|
2011
1994
|
* @param {RuleOrLiteral} rule
|
|
2012
1995
|
*
|
|
2013
1996
|
* @param {RuleOrLiteral} separator
|
|
@@ -2019,8 +2002,6 @@ function sep1(rule, separator) {
|
|
|
2019
2002
|
}
|
|
2020
2003
|
|
|
2021
2004
|
/**
|
|
2022
|
-
* Creates a rule to optionally match one or more of the rules separated by `separator`
|
|
2023
|
-
*
|
|
2024
2005
|
* @param {RuleOrLiteral} rule
|
|
2025
2006
|
*
|
|
2026
2007
|
* @param {RuleOrLiteral} separator
|
package/package.json
CHANGED
package/queries/highlights.scm
CHANGED
package/queries/tags.scm
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
(method_declaration name: (identifier) @name) @definition.method
|
|
10
10
|
|
|
11
|
+
(method_signature name: (identifier) @name) @definition.method
|
|
12
|
+
|
|
11
13
|
(object_creation_expression type: (identifier) @name) @reference.class
|
|
12
14
|
|
|
13
15
|
(type_parameter_constraints_clause (identifier) @name) @reference.class
|
package/src/node-types.json
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
"type": "class_declaration",
|
|
8
8
|
"named": true
|
|
9
9
|
},
|
|
10
|
+
{
|
|
11
|
+
"type": "conditional_method_declaration",
|
|
12
|
+
"named": true
|
|
13
|
+
},
|
|
10
14
|
{
|
|
11
15
|
"type": "constructor_declaration",
|
|
12
16
|
"named": true
|
|
@@ -1856,6 +1860,36 @@
|
|
|
1856
1860
|
}
|
|
1857
1861
|
}
|
|
1858
1862
|
},
|
|
1863
|
+
{
|
|
1864
|
+
"type": "conditional_method_declaration",
|
|
1865
|
+
"named": true,
|
|
1866
|
+
"fields": {
|
|
1867
|
+
"body": {
|
|
1868
|
+
"multiple": false,
|
|
1869
|
+
"required": false,
|
|
1870
|
+
"types": [
|
|
1871
|
+
{
|
|
1872
|
+
"type": "arrow_expression_clause",
|
|
1873
|
+
"named": true
|
|
1874
|
+
},
|
|
1875
|
+
{
|
|
1876
|
+
"type": "block",
|
|
1877
|
+
"named": true
|
|
1878
|
+
}
|
|
1879
|
+
]
|
|
1880
|
+
}
|
|
1881
|
+
},
|
|
1882
|
+
"children": {
|
|
1883
|
+
"multiple": false,
|
|
1884
|
+
"required": true,
|
|
1885
|
+
"types": [
|
|
1886
|
+
{
|
|
1887
|
+
"type": "preproc_if",
|
|
1888
|
+
"named": true
|
|
1889
|
+
}
|
|
1890
|
+
]
|
|
1891
|
+
}
|
|
1892
|
+
},
|
|
1859
1893
|
{
|
|
1860
1894
|
"type": "constant_pattern",
|
|
1861
1895
|
"named": true,
|
|
@@ -2657,6 +2691,10 @@
|
|
|
2657
2691
|
"multiple": true,
|
|
2658
2692
|
"required": false,
|
|
2659
2693
|
"types": [
|
|
2694
|
+
{
|
|
2695
|
+
"type": "conditional_method_declaration",
|
|
2696
|
+
"named": true
|
|
2697
|
+
},
|
|
2660
2698
|
{
|
|
2661
2699
|
"type": "method_declaration",
|
|
2662
2700
|
"named": true
|
|
@@ -4038,6 +4076,78 @@
|
|
|
4038
4076
|
]
|
|
4039
4077
|
}
|
|
4040
4078
|
},
|
|
4079
|
+
{
|
|
4080
|
+
"type": "method_signature",
|
|
4081
|
+
"named": true,
|
|
4082
|
+
"fields": {
|
|
4083
|
+
"name": {
|
|
4084
|
+
"multiple": false,
|
|
4085
|
+
"required": true,
|
|
4086
|
+
"types": [
|
|
4087
|
+
{
|
|
4088
|
+
"type": "identifier",
|
|
4089
|
+
"named": true
|
|
4090
|
+
}
|
|
4091
|
+
]
|
|
4092
|
+
},
|
|
4093
|
+
"parameters": {
|
|
4094
|
+
"multiple": false,
|
|
4095
|
+
"required": true,
|
|
4096
|
+
"types": [
|
|
4097
|
+
{
|
|
4098
|
+
"type": "parameter_list",
|
|
4099
|
+
"named": true
|
|
4100
|
+
}
|
|
4101
|
+
]
|
|
4102
|
+
},
|
|
4103
|
+
"returns": {
|
|
4104
|
+
"multiple": false,
|
|
4105
|
+
"required": true,
|
|
4106
|
+
"types": [
|
|
4107
|
+
{
|
|
4108
|
+
"type": "type",
|
|
4109
|
+
"named": true
|
|
4110
|
+
}
|
|
4111
|
+
]
|
|
4112
|
+
},
|
|
4113
|
+
"type_parameters": {
|
|
4114
|
+
"multiple": false,
|
|
4115
|
+
"required": false,
|
|
4116
|
+
"types": [
|
|
4117
|
+
{
|
|
4118
|
+
"type": "type_parameter_list",
|
|
4119
|
+
"named": true
|
|
4120
|
+
}
|
|
4121
|
+
]
|
|
4122
|
+
}
|
|
4123
|
+
},
|
|
4124
|
+
"children": {
|
|
4125
|
+
"multiple": true,
|
|
4126
|
+
"required": false,
|
|
4127
|
+
"types": [
|
|
4128
|
+
{
|
|
4129
|
+
"type": "attribute_list",
|
|
4130
|
+
"named": true
|
|
4131
|
+
},
|
|
4132
|
+
{
|
|
4133
|
+
"type": "explicit_interface_specifier",
|
|
4134
|
+
"named": true
|
|
4135
|
+
},
|
|
4136
|
+
{
|
|
4137
|
+
"type": "modifier",
|
|
4138
|
+
"named": true
|
|
4139
|
+
},
|
|
4140
|
+
{
|
|
4141
|
+
"type": "preproc_if_in_attribute_list",
|
|
4142
|
+
"named": true
|
|
4143
|
+
},
|
|
4144
|
+
{
|
|
4145
|
+
"type": "type_parameter_constraints_clause",
|
|
4146
|
+
"named": true
|
|
4147
|
+
}
|
|
4148
|
+
]
|
|
4149
|
+
}
|
|
4150
|
+
},
|
|
4041
4151
|
{
|
|
4042
4152
|
"type": "modifier",
|
|
4043
4153
|
"named": true,
|
|
@@ -4801,6 +4911,10 @@
|
|
|
4801
4911
|
"type": "global_attribute",
|
|
4802
4912
|
"named": true
|
|
4803
4913
|
},
|
|
4914
|
+
{
|
|
4915
|
+
"type": "method_signature",
|
|
4916
|
+
"named": true
|
|
4917
|
+
},
|
|
4804
4918
|
{
|
|
4805
4919
|
"type": "statement",
|
|
4806
4920
|
"named": true
|
|
@@ -4848,6 +4962,10 @@
|
|
|
4848
4962
|
"type": "global_attribute",
|
|
4849
4963
|
"named": true
|
|
4850
4964
|
},
|
|
4965
|
+
{
|
|
4966
|
+
"type": "method_signature",
|
|
4967
|
+
"named": true
|
|
4968
|
+
},
|
|
4851
4969
|
{
|
|
4852
4970
|
"type": "statement",
|
|
4853
4971
|
"named": true
|
|
@@ -4973,6 +5091,10 @@
|
|
|
4973
5091
|
"type": "global_attribute",
|
|
4974
5092
|
"named": true
|
|
4975
5093
|
},
|
|
5094
|
+
{
|
|
5095
|
+
"type": "method_signature",
|
|
5096
|
+
"named": true
|
|
5097
|
+
},
|
|
4976
5098
|
{
|
|
4977
5099
|
"type": "statement",
|
|
4978
5100
|
"named": true
|
package/tree-sitter-c_sharp.wasm
CHANGED
|
Binary file
|