@willbooster/tree-sitter-c-sharp 1.0.22 → 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 CHANGED
@@ -480,6 +480,7 @@ module.exports = grammar({
480
480
  $.delegate_declaration,
481
481
  $.field_declaration,
482
482
  $.method_declaration,
483
+ $.conditional_method_declaration,
483
484
  $.event_declaration,
484
485
  $.event_field_declaration,
485
486
  $.record_declaration,
@@ -525,7 +526,8 @@ module.exports = grammar({
525
526
 
526
527
  extension_body: ($) => seq('{', repeat($._extension_member_declaration), '}', optional(';')),
527
528
 
528
- _extension_member_declaration: ($) => choice($.method_declaration, $.property_declaration, $.operator_declaration),
529
+ _extension_member_declaration: ($) =>
530
+ choice($.method_declaration, $.conditional_method_declaration, $.property_declaration, $.operator_declaration),
529
531
 
530
532
  field_declaration: ($) => seq(repeat($._attribute_list), repeat($.modifier), $.variable_declaration, ';'),
531
533
 
@@ -553,7 +555,13 @@ module.exports = grammar({
553
555
  $._function_body
554
556
  ),
555
557
 
556
- 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: ($) =>
557
565
  seq(
558
566
  repeat($._attribute_list),
559
567
  repeat($.modifier),
@@ -562,8 +570,7 @@ module.exports = grammar({
562
570
  field('name', $.identifier),
563
571
  field('type_parameters', optional($.type_parameter_list)),
564
572
  field('parameters', $.parameter_list),
565
- repeat($.type_parameter_constraints_clause),
566
- $._function_body
573
+ repeat($.type_parameter_constraints_clause)
567
574
  ),
568
575
 
569
576
  event_declaration: ($) =>
@@ -1717,6 +1724,13 @@ module.exports = grammar({
1717
1724
  'yield'
1718
1725
  ),
1719
1726
 
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
+ ),
1720
1734
  ...preprocIf('', ($) => $.declaration),
1721
1735
  ...preprocIf('_in_top_level', ($) => choice($._top_level_item_no_statement, $.statement)),
1722
1736
  ...preprocIf('_in_expression', ($) => $.expression, -2, false),
@@ -1877,9 +1891,11 @@ function preprocessor(command) {
1877
1891
  *
1878
1892
  * @param {boolean} rep
1879
1893
  *
1894
+ * @param {boolean} required
1895
+ *
1880
1896
  * @returns {RuleBuilders<string, string>}
1881
1897
  */
1882
- function preprocIf(suffix, content, precedence = 0, rep = true) {
1898
+ function preprocIf(suffix, content, precedence = 0, rep = true, required = false) {
1883
1899
  /**
1884
1900
  *
1885
1901
  * @param {GrammarSymbols<string>} $
@@ -1901,14 +1917,17 @@ function preprocIf(suffix, content, precedence = 0, rep = true) {
1901
1917
  preprocessor('if'),
1902
1918
  field('condition', $._preproc_expression),
1903
1919
  /\n/,
1904
- rep ? repeat(content($)) : optional(content($)),
1920
+ rep ? repeat(content($)) : required ? content($) : optional(content($)),
1905
1921
  field('alternative', optional(alternativeBlock($))),
1906
1922
  preprocessor('endif')
1907
1923
  )
1908
1924
  ),
1909
1925
 
1910
1926
  ['preproc_else' + suffix]: ($) =>
1911
- prec(precedence, seq(preprocessor('else'), rep ? repeat(content($)) : optional(content($)))),
1927
+ prec(
1928
+ precedence,
1929
+ seq(preprocessor('else'), rep ? repeat(content($)) : required ? content($) : optional(content($)))
1930
+ ),
1912
1931
 
1913
1932
  ['preproc_elif' + suffix]: ($) =>
1914
1933
  prec(
@@ -1917,7 +1936,7 @@ function preprocIf(suffix, content, precedence = 0, rep = true) {
1917
1936
  preprocessor('elif'),
1918
1937
  field('condition', $._preproc_expression),
1919
1938
  /\n/,
1920
- rep ? repeat(content($)) : optional(content($)),
1939
+ rep ? repeat(content($)) : required ? content($) : optional(content($)),
1921
1940
  field('alternative', optional(alternativeBlock($)))
1922
1941
  )
1923
1942
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c-sharp",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "C# grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -3,6 +3,7 @@
3
3
  ;; Methods
4
4
 
5
5
  (method_declaration name: (identifier) @function)
6
+ (method_signature name: (identifier) @function)
6
7
  (local_function_statement name: (identifier) @function)
7
8
 
8
9
  ;; Types
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
@@ -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
Binary file
package/tree-sitter.json CHANGED
@@ -19,7 +19,7 @@
19
19
  }
20
20
  ],
21
21
  "metadata": {
22
- "version": "1.0.22",
22
+ "version": "1.0.23",
23
23
  "license": "MIT",
24
24
  "description": "C# grammar for tree-sitter",
25
25
  "authors": [