@willbooster/tree-sitter-c-sharp 1.0.25 → 2.0.0

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
@@ -31,13 +31,16 @@ Known gaps:
31
31
  - A pointer dereference can be assigned to only when its operand is a variable, an address, a parenthesized or
32
32
  postfix expression, or a cast of one of these or of an invocation (`*p = 1`, `*(p + 1) = 1`, `*(int*)p = 1`,
33
33
  `*dst++ = 1`); `*++p = 1` and `*f() = 1` are not recognized
34
- - File-based apps preprocessor directives (`#:property`, `#:package`, `#:sdk`, `#:project`) are not yet recognized
35
34
 
36
35
  ## Usage
37
36
 
38
37
  The npm package ships `tree-sitter-c_sharp.wasm` for
39
38
  [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter), which runs in Node.js, Bun,
40
- browsers, and Cloudflare Workers. In Node.js and Bun, load it from the package:
39
+ browsers, and Cloudflare Workers. Use runtime version 1.1.2 or later: browser loading requires its asynchronous
40
+ instantiation support for this grammar. Install the runtime alongside the grammar when using the Wasm parser; it
41
+ remains an optional peer for consumers that only use the grammar source or queries.
42
+
43
+ In Node.js and Bun, load it from the package:
41
44
 
42
45
  ```js
43
46
  import { fileURLToPath } from 'node:url';
@@ -85,8 +88,8 @@ fuzzed with, whose fixes keep incremental reparses consistent with fresh parses
85
88
 
86
89
  ```toml
87
90
  [dependencies]
88
- tree-sitter = { package = "willbooster-tree-sitter", version = "1.0.4" }
89
- tree-sitter-c-sharp = { package = "willbooster-tree-sitter-c-sharp", version = "1" }
91
+ tree-sitter = { package = "willbooster-tree-sitter", version = "1.1.2" }
92
+ tree-sitter-c-sharp = { package = "willbooster-tree-sitter-c-sharp", version = "2" }
90
93
  ```
91
94
 
92
95
  ```rust
package/grammar.js CHANGED
@@ -36,6 +36,10 @@ const PREC = {
36
36
  SELECT: 0,
37
37
  };
38
38
 
39
+ const directiveHorizontal = String.raw` \t\v\f\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF`;
40
+ const directiveLineBreak = String.raw`\r\n\u0085\u2028\u2029`;
41
+ const directiveWhitespace = directiveHorizontal + directiveLineBreak;
42
+
39
43
  const decimalDigitSequence = /([0-9][0-9_]*[0-9]|[0-9])/;
40
44
 
41
45
  const stringEncoding = /(u|U)8/;
@@ -147,6 +151,7 @@ module.exports = grammar({
147
151
  $._lambda_paren_open,
148
152
  $._end_of_input,
149
153
  $._directive_crlf,
154
+ $._file_directive_preproc_arg,
150
155
  ],
151
156
 
152
157
  extras: ($) => [
@@ -161,6 +166,7 @@ module.exports = grammar({
161
166
  $.preproc_warning,
162
167
  $.preproc_define,
163
168
  $.preproc_undef,
169
+ $.file_directive,
164
170
  ],
165
171
 
166
172
  inline: ($) => [
@@ -1628,9 +1634,9 @@ module.exports = grammar({
1628
1634
 
1629
1635
  null_literal: () => 'null',
1630
1636
 
1631
- character_literal: ($) => seq("'", choice($.character_literal_content, $.escape_sequence), "'"),
1637
+ character_literal: ($) => seq("'", choice($.character_literal_content, $.escape_sequence), token.immediate("'")),
1632
1638
 
1633
- character_literal_content: () => token.immediate(/[^'\\]/),
1639
+ character_literal_content: () => token.immediate(/[^'\\\r\n\u0085\u2028\u2029]/),
1634
1640
 
1635
1641
  integer_literal: () =>
1636
1642
  token(
@@ -1658,12 +1664,17 @@ module.exports = grammar({
1658
1664
  },
1659
1665
 
1660
1666
  string_literal: ($) =>
1661
- seq('"', repeat(choice($.string_literal_content, $.escape_sequence)), '"', optional($.string_literal_encoding)),
1667
+ seq(
1668
+ '"',
1669
+ repeat(choice($.string_literal_content, $.escape_sequence)),
1670
+ token.immediate('"'),
1671
+ optional($.string_literal_encoding)
1672
+ ),
1662
1673
 
1663
- string_literal_content: () => token.immediate(prec(1, /[^"\\\n]+/)),
1674
+ string_literal_content: () => token.immediate(prec(1, /[^"\\\r\n\u0085\u2028\u2029]+/)),
1664
1675
 
1665
1676
  escape_sequence: () =>
1666
- token(choice(/\\x[0-9a-fA-F]{1,4}/, /\\u[0-9a-fA-F]{4}/, /\\U[0-9a-fA-F]{8}/, /\\[abefnrtv'"\\?0]/)),
1677
+ token.immediate(choice(/\\x[0-9a-fA-F]{1,4}/, /\\u[0-9a-fA-F]{4}/, /\\U[0-9a-fA-F]{8}/, /\\[abefnrtv'"\\?0]/)),
1667
1678
 
1668
1679
  string_literal_encoding: () => token.immediate(stringEncoding),
1669
1680
 
@@ -1743,6 +1754,7 @@ module.exports = grammar({
1743
1754
  token(prec(-1, /[^\s\u0085\u2028\u2029]([^/\r\n\u0085\u2028\u2029]|\/[^*\r\n\u0085\u2028\u2029])*/)),
1744
1755
  optional($._preproc_arg_slash)
1745
1756
  ),
1757
+ _file_directive_argument: ($) => seq($._file_directive_preproc_arg, optional($._preproc_arg_slash)),
1746
1758
  _preproc_arg_slash: () => token.immediate(/\//),
1747
1759
  preproc_directive: () => /#[ \t]*[a-zA-Z0-9]\w*/,
1748
1760
 
@@ -1785,10 +1797,19 @@ module.exports = grammar({
1785
1797
  );
1786
1798
  },
1787
1799
 
1788
- preproc_region: ($) => seq(preprocessor('region'), optional(field('content', $.preproc_arg)), directiveEnd($)),
1800
+ preproc_region: ($) =>
1801
+ seq(
1802
+ preprocessor('region'),
1803
+ optional(field('content', choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)))),
1804
+ directiveEnd($)
1805
+ ),
1789
1806
 
1790
1807
  preproc_endregion: ($) =>
1791
- seq(preprocessor('endregion'), optional(field('content', $.preproc_arg)), directiveEnd($)),
1808
+ seq(
1809
+ preprocessor('endregion'),
1810
+ optional(field('content', choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)))),
1811
+ directiveEnd($)
1812
+ ),
1792
1813
 
1793
1814
  preproc_line: ($) =>
1794
1815
  seq(
@@ -1821,7 +1842,7 @@ module.exports = grammar({
1821
1842
  '"',
1822
1843
  repeat(
1823
1844
  choice(
1824
- alias(token.immediate(prec(1, /[^"\\\r\n\u0085\u2028\u2029]+/)), $.string_literal_content),
1845
+ $.string_literal_content,
1825
1846
  alias(token.immediate(prec(-1, '\\')), $.string_literal_content),
1826
1847
  alias(
1827
1848
  token.immediate(
@@ -1852,13 +1873,92 @@ module.exports = grammar({
1852
1873
  directiveEnd($)
1853
1874
  ),
1854
1875
 
1855
- preproc_error: ($) => seq(preprocessor('error'), $.preproc_arg, directiveEnd($)),
1876
+ preproc_error: ($) =>
1877
+ seq(
1878
+ preprocessor('error'),
1879
+ choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)),
1880
+ directiveEnd($)
1881
+ ),
1856
1882
 
1857
- preproc_warning: ($) => seq(preprocessor('warning'), $.preproc_arg, directiveEnd($)),
1883
+ preproc_warning: ($) =>
1884
+ seq(
1885
+ preprocessor('warning'),
1886
+ choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)),
1887
+ directiveEnd($)
1888
+ ),
1889
+
1890
+ preproc_define: ($) =>
1891
+ seq(
1892
+ preprocessor('define'),
1893
+ choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)),
1894
+ directiveEnd($)
1895
+ ),
1896
+
1897
+ preproc_undef: ($) =>
1898
+ seq(
1899
+ preprocessor('undef'),
1900
+ choice($.preproc_arg, alias($._file_directive_argument, $.preproc_arg)),
1901
+ directiveEnd($)
1902
+ ),
1903
+
1904
+ file_directive: ($) =>
1905
+ seq(
1906
+ choice(
1907
+ fileDirectiveArguments(
1908
+ $,
1909
+ choice(
1910
+ alias(token(prec(-2, /#:[sS][dD][kK]/)), '#:sdk'),
1911
+ alias(token(prec(-2, /#:[pP][aA][cC][kK][aA][gG][eE]/)), '#:package')
1912
+ ),
1913
+ '@',
1914
+ 'metadata'
1915
+ ),
1916
+ fileDirectiveArguments(
1917
+ $,
1918
+ alias(token(prec(-2, /#:[pP][rR][oO][pP][eE][rR][tT][yY]/)), '#:property'),
1919
+ '=',
1920
+ 'value'
1921
+ ),
1922
+ seq(
1923
+ choice(
1924
+ alias(token(prec(-2, /#:[pP][rR][oO][jJ][eE][cC][tT]/)), '#:project'),
1925
+ alias(token(prec(-2, /#:[rR][eE][fF]/)), '#:ref'),
1926
+ alias(token(prec(-2, /#:[iI][nN][cC][lL][uU][dD][eE]/)), '#:include'),
1927
+ alias(token(prec(-2, /#:[eE][xX][cC][lL][uU][dD][eE]/)), '#:exclude')
1928
+ ),
1929
+ optional(seq($._file_directive_spacing, field('value', $.file_directive_value)))
1930
+ ),
1931
+ seq(
1932
+ $.file_directive_kind,
1933
+ optional(seq($._file_directive_spacing, optional(field('value', $.file_directive_value))))
1934
+ )
1935
+ ),
1936
+ optional($._file_directive_spacing),
1937
+ choice(token.immediate(new RegExp(String.raw`\r\n|[${directiveLineBreak}]`)), $._end_of_input)
1938
+ ),
1858
1939
 
1859
- preproc_define: ($) => seq(preprocessor('define'), $.preproc_arg, directiveEnd($)),
1940
+ file_directive_kind: () => token(prec(-2, new RegExp(`#:[^${directiveWhitespace}]*`))),
1860
1941
 
1861
- preproc_undef: ($) => seq(preprocessor('undef'), $.preproc_arg, directiveEnd($)),
1942
+ _file_directive_spacing: () => token.immediate(prec(1, new RegExp(`[${directiveHorizontal}]+`))),
1943
+ file_directive_name: () =>
1944
+ token.immediate(
1945
+ prec(
1946
+ 2,
1947
+ choice(
1948
+ new RegExp(`[^${directiveWhitespace}@="]+`),
1949
+ new RegExp(String.raw`"([^"\\${directiveLineBreak}]|\\[^${directiveLineBreak}])*"`)
1950
+ )
1951
+ )
1952
+ ),
1953
+ file_directive_value: () =>
1954
+ token.immediate(
1955
+ prec(
1956
+ 1,
1957
+ new RegExp(
1958
+ `[^${directiveWhitespace}]([^${directiveLineBreak}]*[^${directiveWhitespace}])?|//[^${directiveLineBreak}]*`
1959
+ )
1960
+ )
1961
+ ),
1862
1962
 
1863
1963
  shebang_directive: () => token(seq('#!', /[^\r\n\u0085\u2028\u2029]*/)),
1864
1964
 
@@ -1866,6 +1966,41 @@ module.exports = grammar({
1866
1966
  },
1867
1967
  });
1868
1968
 
1969
+ /**
1970
+ * @param {GrammarSymbols<string>} $
1971
+ * @param {Rule} kind
1972
+ * @param {string} separator
1973
+ * @param {string} extraField
1974
+ * @returns {SeqRule}
1975
+ */
1976
+ function fileDirectiveArguments($, kind, separator, extraField) {
1977
+ return seq(
1978
+ kind,
1979
+ optional(
1980
+ seq(
1981
+ $._file_directive_spacing,
1982
+ choice(
1983
+ seq(
1984
+ field('name', $.file_directive_name),
1985
+ optional(
1986
+ choice(
1987
+ seq(
1988
+ optional($._file_directive_spacing),
1989
+ token.immediate(prec(2, separator)),
1990
+ optional($._file_directive_spacing),
1991
+ optional(field('value', $.file_directive_value))
1992
+ ),
1993
+ seq(optional($._file_directive_spacing), field(extraField, $.file_directive_value))
1994
+ )
1995
+ )
1996
+ ),
1997
+ field('value', $.file_directive_value)
1998
+ )
1999
+ )
2000
+ )
2001
+ );
2002
+ }
2003
+
1869
2004
  /**
1870
2005
  * Ends a directive that opens no conditional section: at a line break, or at the end of the input, which a file may
1871
2006
  * reach without a final line break.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c-sharp",
3
- "version": "1.0.25",
3
+ "version": "2.0.0",
4
4
  "description": "C# grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -47,7 +47,7 @@
47
47
  "@willbooster/oxfmt-config": "1.2.2",
48
48
  "@willbooster/oxlint-config": "1.4.8",
49
49
  "@willbooster/wb": "22.13.1",
50
- "@willbooster/web-tree-sitter": "1.0.17",
50
+ "@willbooster/web-tree-sitter": "1.1.2",
51
51
  "conventional-changelog-conventionalcommits": "10.4.0",
52
52
  "lefthook": "2.1.14",
53
53
  "oxfmt": "0.70.0",
@@ -63,7 +63,7 @@
63
63
  "wrangler": "4.135.0"
64
64
  },
65
65
  "peerDependencies": {
66
- "@willbooster/web-tree-sitter": "^1.0.0"
66
+ "@willbooster/web-tree-sitter": "^1.1.2"
67
67
  },
68
68
  "peerDependenciesMeta": {
69
69
  "@willbooster/web-tree-sitter": {
@@ -213,3 +213,9 @@
213
213
  ;; Method calls
214
214
 
215
215
  (invocation_expression (member_access_expression name: (identifier) @function))
216
+
217
+ ["#:sdk" "#:package" "#:property" "#:project" "#:ref" "#:include" "#:exclude"] @keyword.directive
218
+ (file_directive_name) @property
219
+ (file_directive_value) @string
220
+
221
+ (file_directive_kind) @keyword.directive
@@ -2788,6 +2788,53 @@
2788
2788
  ]
2789
2789
  }
2790
2790
  },
2791
+ {
2792
+ "type": "file_directive",
2793
+ "named": true,
2794
+ "extra": true,
2795
+ "fields": {
2796
+ "metadata": {
2797
+ "multiple": false,
2798
+ "required": false,
2799
+ "types": [
2800
+ {
2801
+ "type": "file_directive_value",
2802
+ "named": true
2803
+ }
2804
+ ]
2805
+ },
2806
+ "name": {
2807
+ "multiple": false,
2808
+ "required": false,
2809
+ "types": [
2810
+ {
2811
+ "type": "file_directive_name",
2812
+ "named": true
2813
+ }
2814
+ ]
2815
+ },
2816
+ "value": {
2817
+ "multiple": false,
2818
+ "required": false,
2819
+ "types": [
2820
+ {
2821
+ "type": "file_directive_value",
2822
+ "named": true
2823
+ }
2824
+ ]
2825
+ }
2826
+ },
2827
+ "children": {
2828
+ "multiple": false,
2829
+ "required": false,
2830
+ "types": [
2831
+ {
2832
+ "type": "file_directive_kind",
2833
+ "named": true
2834
+ }
2835
+ ]
2836
+ }
2837
+ },
2791
2838
  {
2792
2839
  "type": "file_scoped_namespace_declaration",
2793
2840
  "named": true,
@@ -6711,6 +6758,34 @@
6711
6758
  "type": "\"",
6712
6759
  "named": false
6713
6760
  },
6761
+ {
6762
+ "type": "#:exclude",
6763
+ "named": false
6764
+ },
6765
+ {
6766
+ "type": "#:include",
6767
+ "named": false
6768
+ },
6769
+ {
6770
+ "type": "#:package",
6771
+ "named": false
6772
+ },
6773
+ {
6774
+ "type": "#:project",
6775
+ "named": false
6776
+ },
6777
+ {
6778
+ "type": "#:property",
6779
+ "named": false
6780
+ },
6781
+ {
6782
+ "type": "#:ref",
6783
+ "named": false
6784
+ },
6785
+ {
6786
+ "type": "#:sdk",
6787
+ "named": false
6788
+ },
6714
6789
  {
6715
6790
  "type": "#define",
6716
6791
  "named": false
@@ -6927,6 +7002,10 @@
6927
7002
  "type": "??=",
6928
7003
  "named": false
6929
7004
  },
7005
+ {
7006
+ "type": "@",
7007
+ "named": false
7008
+ },
6930
7009
  {
6931
7010
  "type": "Cdecl",
6932
7011
  "named": false
@@ -7132,6 +7211,18 @@
7132
7211
  "type": "file",
7133
7212
  "named": false
7134
7213
  },
7214
+ {
7215
+ "type": "file_directive_kind",
7216
+ "named": true
7217
+ },
7218
+ {
7219
+ "type": "file_directive_name",
7220
+ "named": true
7221
+ },
7222
+ {
7223
+ "type": "file_directive_value",
7224
+ "named": true
7225
+ },
7135
7226
  {
7136
7227
  "type": "finally",
7137
7228
  "named": false
Binary file
package/tree-sitter.json CHANGED
@@ -19,7 +19,7 @@
19
19
  }
20
20
  ],
21
21
  "metadata": {
22
- "version": "1.0.25",
22
+ "version": "2.0.0",
23
23
  "license": "MIT",
24
24
  "description": "C# grammar for tree-sitter",
25
25
  "authors": [