@willbooster/tree-sitter-c-sharp 1.0.13 → 1.0.14

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
@@ -5,14 +5,15 @@
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-c-sharp/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-c-sharp/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-c-sharp/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-c-sharp/actions/workflows/test-rust.yml)
7
7
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
8
- [![wbfy](https://img.shields.io/badge/wbfy-20.26.0-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.28.6-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
9
  [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-c-sharp.svg)](https://crates.io/crates/willbooster-tree-sitter-c-sharp)
10
10
 
11
11
  C# grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
12
12
  [tree-sitter/tree-sitter-c-sharp](https://github.com/tree-sitter/tree-sitter-c-sharp). We are grateful
13
13
  to its authors and contributors. This is not an official release of that project.
14
14
 
15
- This fork fixes parsing bugs and raises conformance with the [C# language specification](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/readme).
15
+ This fork fixes parsing bugs and raises conformance with the
16
+ [C# language specification](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/readme).
16
17
 
17
18
  The grammar is based upon the Roslyn grammar with changes in order to:
18
19
 
@@ -75,7 +76,7 @@ const parser = new Parser();
75
76
  parser.setLanguage(await Language.load(cSharp));
76
77
  ```
77
78
 
78
- The package also ships the node types in `src/node-types.json`.
79
+ The package also ships the queries in `queries/` and the node types in `src/node-types.json`.
79
80
 
80
81
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-c-sharp) and on
81
82
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
@@ -107,22 +108,29 @@ cargo test
107
108
  `bun run test` runs:
108
109
 
109
110
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
110
- - an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case at random,
111
- reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
112
- `TREE_SITTER_EDITS` run other or more edits;
111
+ - an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
112
+ edits each corpus case at random, reparses it, undoes the edits, and reparses again, on the WillBooster/tree-sitter
113
+ runtime version locked in `Cargo.lock` (the first run downloads that CLI from its GitHub Release, or builds it with
114
+ `cargo` when the download fails or the release has no binary that runs here). `TREE_SITTER_SEED`,
115
+ `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
113
116
  - a check that the real-world C# files cloned into `examples/` fail to parse exactly as listed in
114
117
  `script/known-failures.txt`. The first run clones them. The example repositories are pinned to commits in
115
118
  `script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples` rewrites
116
119
  it; review its diff before committing;
117
- - a performance check (`test/unit/performance.test.ts`) that recovering from an error on each of 10,000 lines takes
118
- linear time, since consumers parse files while they are being edited. It loads the Wasm build through
119
- @willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after regenerating the parser;
120
+ - a performance check (`test/unit/performance.test.ts`) that recovering from an error on each line takes linear time
121
+ (ten times the lines take about ten times the CPU time, under a ceiling), since consumers parse files while they are
122
+ being edited. It loads the Wasm build through @willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after
123
+ regenerating the parser;
124
+ - a check that `package.json` and `Cargo.lock` test the same runtime version (`test/unit/runtimeVersion.test.ts`);
120
125
  - checks that the Wasm build parses C# with @willbooster/web-tree-sitter in Chromium (`test/unit/browser.test.ts`,
121
126
  which needs Chromium installed once by `bunx playwright install chromium`) and in Cloudflare Workers with and without
122
127
  `nodejs_compat` (`test/unit/workers.test.ts`).
123
128
 
124
- `cargo test` also replays edits that `tree-sitter fuzz` found to break incremental parsing, with the
125
- willbooster-tree-sitter runtime that fixes them; `tree-sitter fuzz` itself runs the runtime built into tree-sitter-cli.
129
+ The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
130
+ by every checkout; `script/fuzz-corpus` builds a per-run parser in `.tmp/fuzz` and deletes it afterwards.
131
+
132
+ `cargo test` also replays edits that `tree-sitter fuzz` found to break incremental parsing on runtimes without the
133
+ fixes of willbooster-tree-sitter.
126
134
 
127
135
  CI also runs these tests on Linux arm64 and macOS, where the Rust binding compiles the parser natively, and fuzzes the
128
136
  parser with libFuzzer and sanitizers on the willbooster-tree-sitter runtime locked in `Cargo.lock`
@@ -131,6 +139,7 @@ parser with libFuzzer and sanitizers on the willbooster-tree-sitter runtime lock
131
139
  ### References
132
140
 
133
141
  - [C# language specification](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/readme)
134
- - [Official C# 8 Draft Language Spec](https://github.com/dotnet/csharpstandard/tree/draft-v8/standard) provides chapters that formally define the language grammar.
142
+ - [Official C# 8 Draft Language Spec](https://github.com/dotnet/csharpstandard/tree/draft-v8/standard) provides
143
+ chapters that formally define the language grammar.
135
144
  - [Roslyn C# language grammar export](https://github.com/dotnet/roslyn/blob/master/src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4)
136
145
  - [SharpLab](https://sharplab.io) (web-based syntax tree playground based on Roslyn)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c-sharp",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "C# grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -16,6 +16,7 @@
16
16
  "author": "WillBooster Inc.",
17
17
  "files": [
18
18
  "grammar.js",
19
+ "queries/*.scm",
19
20
  "tree-sitter.json",
20
21
  "src/node-types.json",
21
22
  "*.wasm"
@@ -44,13 +45,13 @@
44
45
  "@vitest/browser-playwright": "5.0.1",
45
46
  "@willbooster/oxfmt-config": "1.2.2",
46
47
  "@willbooster/oxlint-config": "1.4.8",
47
- "@willbooster/wb": "22.13.0",
48
- "@willbooster/web-tree-sitter": "1.0.7",
48
+ "@willbooster/wb": "22.13.1",
49
+ "@willbooster/web-tree-sitter": "1.0.12",
49
50
  "conventional-changelog-conventionalcommits": "10.4.0",
50
51
  "lefthook": "2.1.14",
51
52
  "oxfmt": "0.70.0",
52
53
  "oxlint": "1.85.0",
53
- "oxlint-tsgolint": "7.0.2002",
54
+ "oxlint-tsgolint": "7.0.2003",
54
55
  "playwright": "1.63.0",
55
56
  "semantic-release": "25.0.9",
56
57
  "sort-package-json": "4.0.0",
@@ -0,0 +1,214 @@
1
+ (identifier) @variable
2
+
3
+ ;; Methods
4
+
5
+ (method_declaration name: (identifier) @function)
6
+ (local_function_statement name: (identifier) @function)
7
+
8
+ ;; Types
9
+
10
+ (interface_declaration name: (identifier) @type)
11
+ (class_declaration name: (identifier) @type)
12
+ (enum_declaration name: (identifier) @type)
13
+ (struct_declaration (identifier) @type)
14
+ (record_declaration (identifier) @type)
15
+ (namespace_declaration name: (identifier) @module)
16
+
17
+ (generic_name (identifier) @type)
18
+ (type_parameter (identifier) @property.definition)
19
+ (parameter type: (identifier) @type)
20
+ (type_argument_list (identifier) @type)
21
+ (as_expression right: (identifier) @type)
22
+ (is_expression right: (identifier) @type)
23
+
24
+ (constructor_declaration name: (identifier) @constructor)
25
+ (destructor_declaration name: (identifier) @constructor)
26
+
27
+ (_ type: (identifier) @type)
28
+
29
+ (base_list (identifier) @type)
30
+
31
+ (predefined_type) @type.builtin
32
+
33
+ ;; Enum
34
+ (enum_member_declaration (identifier) @property.definition)
35
+
36
+ ;; Literals
37
+
38
+ [
39
+ (real_literal)
40
+ (integer_literal)
41
+ ] @number
42
+
43
+ [
44
+ (character_literal)
45
+ (string_literal)
46
+ (raw_string_literal)
47
+ (verbatim_string_literal)
48
+ (interpolated_string_expression)
49
+ (interpolation_start)
50
+ (interpolation_quote)
51
+ ] @string
52
+
53
+ (escape_sequence) @string.escape
54
+
55
+ [
56
+ (boolean_literal)
57
+ (null_literal)
58
+ ] @constant.builtin
59
+
60
+ ;; Comments
61
+
62
+ (comment) @comment
63
+
64
+ ;; Tokens
65
+
66
+ [
67
+ ";"
68
+ "."
69
+ ","
70
+ ] @punctuation.delimiter
71
+
72
+ [
73
+ "--"
74
+ "-"
75
+ "-="
76
+ "&"
77
+ "&="
78
+ "&&"
79
+ "+"
80
+ "++"
81
+ "+="
82
+ "<"
83
+ "<="
84
+ "<<"
85
+ "<<="
86
+ "="
87
+ "=="
88
+ "!"
89
+ "!="
90
+ "=>"
91
+ ">"
92
+ ">="
93
+ ">>"
94
+ ">>="
95
+ ">>>"
96
+ ">>>="
97
+ "|"
98
+ "|="
99
+ "||"
100
+ "?"
101
+ "??"
102
+ "??="
103
+ "^"
104
+ "^="
105
+ "~"
106
+ "*"
107
+ "*="
108
+ "/"
109
+ "/="
110
+ "%"
111
+ "%="
112
+ ":"
113
+ ".."
114
+ ] @operator
115
+
116
+ [
117
+ "("
118
+ ")"
119
+ "["
120
+ "]"
121
+ "{"
122
+ "}"
123
+ (interpolation_brace)
124
+ ] @punctuation.bracket
125
+
126
+ ;; Keywords
127
+
128
+ [
129
+ (modifier)
130
+ "this"
131
+ (implicit_type)
132
+ ] @keyword
133
+
134
+ [
135
+ "add"
136
+ "alias"
137
+ "as"
138
+ "base"
139
+ "break"
140
+ "case"
141
+ "catch"
142
+ "checked"
143
+ "class"
144
+ "continue"
145
+ "default"
146
+ "delegate"
147
+ "do"
148
+ "else"
149
+ "enum"
150
+ "event"
151
+ "explicit"
152
+ "extern"
153
+ "finally"
154
+ "for"
155
+ "foreach"
156
+ "global"
157
+ "goto"
158
+ "if"
159
+ "implicit"
160
+ "interface"
161
+ "is"
162
+ "lock"
163
+ "namespace"
164
+ "notnull"
165
+ "operator"
166
+ "params"
167
+ "return"
168
+ "remove"
169
+ "sizeof"
170
+ "stackalloc"
171
+ "static"
172
+ "struct"
173
+ "switch"
174
+ "throw"
175
+ "try"
176
+ "typeof"
177
+ "unchecked"
178
+ "using"
179
+ "while"
180
+ "new"
181
+ "await"
182
+ "in"
183
+ "yield"
184
+ "get"
185
+ "set"
186
+ "when"
187
+ "out"
188
+ "ref"
189
+ "from"
190
+ "where"
191
+ "select"
192
+ "record"
193
+ "init"
194
+ "with"
195
+ "let"
196
+ "unsafe"
197
+ ] @keyword
198
+
199
+ ;; Attribute
200
+
201
+ (attribute name: (identifier) @attribute)
202
+
203
+ ;; Parameters
204
+
205
+ (parameter
206
+ name: (identifier) @variable.parameter)
207
+
208
+ ;; Type constraints
209
+
210
+ (type_parameter_constraints_clause (identifier) @property.definition)
211
+
212
+ ;; Method calls
213
+
214
+ (invocation_expression (member_access_expression name: (identifier) @function))
@@ -0,0 +1,23 @@
1
+ (class_declaration name: (identifier) @name) @definition.class
2
+
3
+ (class_declaration (base_list (_) @name)) @reference.class
4
+
5
+ (interface_declaration name: (identifier) @name) @definition.interface
6
+
7
+ (interface_declaration (base_list (_) @name)) @reference.interface
8
+
9
+ (method_declaration name: (identifier) @name) @definition.method
10
+
11
+ (object_creation_expression type: (identifier) @name) @reference.class
12
+
13
+ (type_parameter_constraints_clause (identifier) @name) @reference.class
14
+
15
+ (type_parameter_constraint type: (identifier) @name) @reference.class
16
+
17
+ (variable_declaration type: (identifier) @name) @reference.class
18
+
19
+ (invocation_expression function: (member_access_expression name: (identifier) @name)) @reference.send
20
+
21
+ (namespace_declaration name: (identifier) @name) @definition.module
22
+
23
+ (namespace_declaration name: (identifier) @name) @module
Binary file
package/tree-sitter.json CHANGED
@@ -19,7 +19,7 @@
19
19
  }
20
20
  ],
21
21
  "metadata": {
22
- "version": "1.0.13",
22
+ "version": "1.0.14",
23
23
  "license": "MIT",
24
24
  "description": "C# grammar for tree-sitter",
25
25
  "authors": [