@willbooster/tree-sitter-zig 7.0.0 → 9.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
@@ -5,7 +5,7 @@
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-zig/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-zig/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-zig/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-zig/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.48.9-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-21.3.0-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
9
  [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-zig.svg)](https://crates.io/crates/willbooster-tree-sitter-zig)
10
10
 
11
11
  Zig grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
@@ -26,19 +26,20 @@ rejects it. It parses as the parser in upstream's 1.1.2 packages does, with thes
26
26
  `~x`) or only continue one (`+`, `orelse`), and so do ranges outside `for` loops.
27
27
  - A NUL character inside a token such as a string or a comment is part of that token, where upstream's lexer reports
28
28
  an error.
29
- - Multiline strings expose each `\\` line delimiter and nonempty `string_content` children. The delimiters receive
30
- the `@string.special.symbol` highlight capture. Line endings are outside the content nodes.
29
+ - Multiline strings expose each `\\` line delimiter and nonempty `string_content` children. Line endings are outside
30
+ the content nodes.
31
31
  - `///` and `//!` produce `doc_comment` and `container_doc_comment` nodes. Their `doc_comment_content` children
32
- exclude the prefix and include the line ending when present, so the injection query can combine them as Markdown.
32
+ exclude the prefix and include the line ending when present.
33
33
  An empty comment at EOF has no content child. Ordinary comments, including `////`, remain `comment` nodes.
34
- Queries that need every comment kind must match all three node types.
34
+ Code that handles every comment kind must match all three node types.
35
35
 
36
36
  - Error sets are accepted directly as container field types, and pointer, slice and array element types may be conditional.
37
- - `async` and `await` are ordinary identifiers. Assembly clobbers use an expression, including an anonymous struct
37
+ - `async`, `await`, and `usingnamespace` are ordinary identifiers. Removed `usingnamespace` declarations produce syntax
38
+ errors. Assembly clobbers use an expression, including an anonymous struct
38
39
  initializer, as in Zig 0.16.
39
40
  - Zero-bit integers `u0` and `i0` are builtin types.
40
41
  - Quoted identifiers such as `@"hello world"` expose their content directly inside `identifier`, without a nested
41
- `string` node, so string highlighting applies only to literals.
42
+ `string` node.
42
43
  - Boolean negation is a `unary_expression`. Inferred error unions (`!T`) occur only in function return types;
43
44
  their payload includes suffixes such as calls and field access (`!List(T)` or `!ns.Result`). Explicit error
44
45
  unions (`E!T`) retain their error and payload types.
@@ -49,6 +50,13 @@ rejects it. It parses as the parser in upstream's 1.1.2 packages does, with thes
49
50
  `assignment_expression` nodes expose `left`, `operator`, and `right` fields.
50
51
  Struct field initializers produce `field_initializer` nodes with `name` and `value` fields.
51
52
 
53
+ ## Support Scope
54
+
55
+ This fork maintains only full parsing: valid input yields a correct tree, and invalid input yields `ERROR` or `MISSING`
56
+ nodes without crashing, hanging, or taking more than linear time. Incremental parsing works as in upstream tree-sitter
57
+ but is not tested here, and no queries (highlights, locals, injections, tags) are shipped. Node types, field names, and
58
+ the trees that error recovery produces may change; such changes are released as new major versions.
59
+
52
60
  ## Usage
53
61
 
54
62
  The npm package ships `tree-sitter-zig.wasm` for
@@ -92,17 +100,16 @@ const parser = new Parser();
92
100
  parser.setLanguage(await Language.load(zig));
93
101
  ```
94
102
 
95
- The package also ships `grammar.js`, the queries in `queries/`, and the node types in `src/node-types.json`.
103
+ The package also ships `grammar.js` and the node types in `src/node-types.json`.
96
104
  It includes `src/scanner.c`, which must be compiled with a parser regenerated from this grammar.
97
105
 
98
106
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-zig) and on
99
107
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
100
108
  fuzzed with:
101
109
 
102
- ```toml
103
- [dependencies]
104
- tree-sitter = { package = "willbooster-tree-sitter", version = "15.0.0" }
105
- tree-sitter-zig = { package = "willbooster-tree-sitter-zig", version = "6" }
110
+ ```sh
111
+ cargo add willbooster-tree-sitter@15.0.0 --rename tree-sitter
112
+ cargo add willbooster-tree-sitter-zig --rename tree-sitter-zig
106
113
  ```
107
114
 
108
115
  ```rust
@@ -140,9 +147,6 @@ and the release build regenerate the parsers before compiling them.
140
147
  `bun run test` runs:
141
148
 
142
149
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
143
- - an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
144
- edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
145
- `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
146
150
  - a check that the real-world Zig files in `examples/` fail to parse exactly as listed in
147
151
  `script/known-failures.txt`, while every library file from the pinned Zig 0.16 release must parse without errors.
148
152
  The older Zig corpus retains coverage of unsupported syntax. The first run fetches the repositories and the
@@ -158,8 +162,7 @@ and the release build regenerate the parsers before compiling them.
158
162
  Cloudflare Workers with and without Node.js compatibility (`test/e2e/workers.test.ts`).
159
163
 
160
164
  The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
161
- by every checkout; `script/fuzz-corpus` builds a parser of its own in `.tmp/fuzz` for each run and deletes it
162
- afterwards.
165
+ by every checkout.
163
166
 
164
167
  CI also runs these tests on Linux arm64 and macOS, where the CLI compiles the parser natively, and fuzzes the parser
165
168
  with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
package/grammar.js CHANGED
@@ -103,7 +103,6 @@ module.exports = grammar({
103
103
  $.comptime_declaration,
104
104
  $.variable_declaration,
105
105
  $.function_declaration,
106
- $.using_namespace_declaration,
107
106
  seq($.container_field, ','),
108
107
  )),
109
108
  optional($.container_field),
@@ -234,13 +233,6 @@ module.exports = grammar({
234
233
  '...',
235
234
  ),
236
235
 
237
- using_namespace_declaration: $ => seq(
238
- optional('pub'),
239
- 'usingnamespace',
240
- $.expression,
241
- ';',
242
- ),
243
-
244
236
  block: $ => seq(
245
237
  '{',
246
238
  repeat($.statement),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-zig",
3
- "version": "7.0.0",
3
+ "version": "9.0.0",
4
4
  "description": "Zig grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -16,7 +16,6 @@
16
16
  },
17
17
  "files": [
18
18
  "grammar.js",
19
- "queries/*.scm",
20
19
  "src/node-types.json",
21
20
  "src/scanner.c",
22
21
  "tree-sitter.json",
@@ -47,19 +46,19 @@
47
46
  },
48
47
  "devDependencies": {
49
48
  "@tsconfig/bun": "1.0.11",
50
- "@types/bun": "1.4.3",
49
+ "@types/bun": "1.4.4",
51
50
  "@vitest/browser-playwright": "5.0.5",
52
51
  "@willbooster/oxlint-config": "1.4.9",
53
- "@willbooster/wb": "22.29.3",
52
+ "@willbooster/wb": "23.0.2",
54
53
  "@willbooster/web-tree-sitter": "15.0.0",
55
54
  "conventional-changelog-conventionalcommits": "10.4.1",
56
55
  "lefthook": "2.2.2",
57
- "oxlint": "1.88.0",
58
- "oxlint-tsgolint": "7.0.2004",
56
+ "oxlint": "1.89.0",
57
+ "oxlint-tsgolint": "7.0.2005",
59
58
  "playwright": "1.64.1",
60
59
  "semantic-release": "25.0.9",
61
60
  "vitest": "5.0.5",
62
- "wrangler": "4.151.1"
61
+ "wrangler": "4.152.0"
63
62
  },
64
63
  "peerDependencies": {
65
64
  "@willbooster/web-tree-sitter": "^15.0.0"
@@ -1237,10 +1237,6 @@
1237
1237
  "type": "test_declaration",
1238
1238
  "named": true
1239
1239
  },
1240
- {
1241
- "type": "using_namespace_declaration",
1242
- "named": true
1243
- },
1244
1240
  {
1245
1241
  "type": "variable_declaration",
1246
1242
  "named": true
@@ -1979,10 +1975,6 @@
1979
1975
  "type": "test_declaration",
1980
1976
  "named": true
1981
1977
  },
1982
- {
1983
- "type": "using_namespace_declaration",
1984
- "named": true
1985
- },
1986
1978
  {
1987
1979
  "type": "variable_declaration",
1988
1980
  "named": true
@@ -2211,10 +2203,6 @@
2211
2203
  "type": "test_declaration",
2212
2204
  "named": true
2213
2205
  },
2214
- {
2215
- "type": "using_namespace_declaration",
2216
- "named": true
2217
- },
2218
2206
  {
2219
2207
  "type": "variable_declaration",
2220
2208
  "named": true
@@ -2269,10 +2257,6 @@
2269
2257
  "type": "test_declaration",
2270
2258
  "named": true
2271
2259
  },
2272
- {
2273
- "type": "using_namespace_declaration",
2274
- "named": true
2275
- },
2276
2260
  {
2277
2261
  "type": "variable_declaration",
2278
2262
  "named": true
@@ -2476,10 +2460,6 @@
2476
2460
  "type": "test_declaration",
2477
2461
  "named": true
2478
2462
  },
2479
- {
2480
- "type": "using_namespace_declaration",
2481
- "named": true
2482
- },
2483
2463
  {
2484
2464
  "type": "variable_declaration",
2485
2465
  "named": true
@@ -2487,21 +2467,6 @@
2487
2467
  ]
2488
2468
  }
2489
2469
  },
2490
- {
2491
- "type": "using_namespace_declaration",
2492
- "named": true,
2493
- "fields": {},
2494
- "children": {
2495
- "multiple": false,
2496
- "required": true,
2497
- "types": [
2498
- {
2499
- "type": "expression",
2500
- "named": true
2501
- }
2502
- ]
2503
- }
2504
- },
2505
2470
  {
2506
2471
  "type": "variable_declaration",
2507
2472
  "named": true,
@@ -3211,10 +3176,6 @@
3211
3176
  "type": "unreachable",
3212
3177
  "named": false
3213
3178
  },
3214
- {
3215
- "type": "usingnamespace",
3216
- "named": false
3217
- },
3218
3179
  {
3219
3180
  "type": "usize",
3220
3181
  "named": false
Binary file
package/tree-sitter.json CHANGED
@@ -9,13 +9,11 @@
9
9
  "file-types": [
10
10
  "zig"
11
11
  ],
12
- "highlights": "queries/highlights.scm",
13
- "injections": "queries/injections.scm",
14
12
  "injection-regex": "^zig$"
15
13
  }
16
14
  ],
17
15
  "metadata": {
18
- "version": "7.0.0",
16
+ "version": "9.0.0",
19
17
  "license": "MIT",
20
18
  "description": "Zig grammar for tree-sitter",
21
19
  "authors": [
package/queries/folds.scm DELETED
@@ -1,23 +0,0 @@
1
- [
2
- (block)
3
- (switch_expression)
4
- (initializer_list)
5
- (asm_expression)
6
- (multiline_string)
7
- (if_statement)
8
- (while_statement)
9
- (for_statement)
10
- (if_expression)
11
- (else_clause)
12
- (for_expression)
13
- (while_expression)
14
- (if_type_expression)
15
- (function_signature)
16
- (parameters)
17
- (struct_declaration)
18
- (opaque_declaration)
19
- (enum_declaration)
20
- (union_declaration)
21
- (error_set_declaration)
22
- ] @fold
23
-
@@ -1,293 +0,0 @@
1
- ; Variables
2
-
3
- (identifier) @variable
4
-
5
- ; Parameters
6
-
7
- (parameter
8
- name: (identifier) @variable.parameter)
9
-
10
- ; Types
11
-
12
- (parameter
13
- type: (identifier) @type)
14
-
15
- ((identifier) @type
16
- (#match? @type "^[A-Z_][a-zA-Z0-9_]*"))
17
-
18
- (variable_declaration
19
- (identifier) @type
20
- "="
21
- [
22
- (struct_declaration)
23
- (enum_declaration)
24
- (union_declaration)
25
- (opaque_declaration)
26
- ])
27
-
28
- [
29
- (builtin_type)
30
- "anyframe"
31
- ] @type.builtin
32
-
33
- ; Constants
34
-
35
- ((identifier) @constant
36
- (#match? @constant "^[A-Z][A-Z_0-9]+$"))
37
-
38
- [
39
- "null"
40
- "unreachable"
41
- "undefined"
42
- ] @constant.builtin
43
-
44
- (field_expression
45
- .
46
- member: (identifier) @constant)
47
-
48
- (enum_declaration
49
- (container_field
50
- type: (identifier) @constant))
51
-
52
- ; Labels
53
-
54
- (block_label (identifier) @label)
55
-
56
- (break_label (identifier) @label)
57
-
58
- ; Fields
59
-
60
- (field_initializer
61
- name: (identifier) @variable.member)
62
-
63
- (field_expression
64
- (_)
65
- member: (identifier) @variable.member)
66
-
67
- (container_field
68
- name: (identifier) @variable.member)
69
-
70
- (parameter
71
- type: (field_expression
72
- member: (identifier) @type))
73
-
74
- ; Functions
75
-
76
- (builtin_identifier) @function.builtin
77
-
78
- (call_expression
79
- function: (identifier) @function.call)
80
-
81
- (call_expression
82
- function: (field_expression
83
- member: (identifier) @function.call))
84
-
85
- (function_declaration
86
- name: (identifier) @function)
87
-
88
- ; Modules
89
-
90
- (variable_declaration
91
- (identifier) @module
92
- (builtin_function
93
- (builtin_identifier) @keyword.import
94
- (#any-of? @keyword.import "@import" "@cImport")))
95
-
96
- ; Builtins
97
-
98
- [
99
- "c"
100
- "..."
101
- ] @variable.builtin
102
-
103
- ((identifier) @variable.builtin
104
- (#eq? @variable.builtin "_"))
105
-
106
- (calling_convention
107
- (identifier) @variable.builtin)
108
-
109
- ; Keywords
110
-
111
- [
112
- "asm"
113
- "defer"
114
- "errdefer"
115
- "test"
116
- "error"
117
- "const"
118
- "var"
119
- ] @keyword
120
-
121
- [
122
- "struct"
123
- "union"
124
- "enum"
125
- "opaque"
126
- ] @keyword.type
127
-
128
- [
129
- "suspend"
130
- "nosuspend"
131
- "resume"
132
- ] @keyword.coroutine
133
-
134
- "fn" @keyword.function
135
-
136
- [
137
- "and"
138
- "or"
139
- "orelse"
140
- ] @keyword.operator
141
-
142
- "return" @keyword.return
143
-
144
- [
145
- "if"
146
- "else"
147
- "switch"
148
- ] @keyword.conditional
149
-
150
- [
151
- "for"
152
- "while"
153
- "break"
154
- "continue"
155
- ] @keyword.repeat
156
-
157
- [
158
- "usingnamespace"
159
- "export"
160
- ] @keyword.import
161
-
162
- [
163
- "try"
164
- "catch"
165
- ] @keyword.exception
166
-
167
- [
168
- "volatile"
169
- "allowzero"
170
- "noalias"
171
- "addrspace"
172
- "align"
173
- "callconv"
174
- "linksection"
175
- "pub"
176
- "inline"
177
- "noinline"
178
- "extern"
179
- "comptime"
180
- "packed"
181
- "threadlocal"
182
- ] @keyword.modifier
183
-
184
- ; Operator
185
-
186
- [
187
- "="
188
- "*="
189
- "*%="
190
- "*|="
191
- "/="
192
- "%="
193
- "+="
194
- "+%="
195
- "+|="
196
- "-="
197
- "-%="
198
- "-|="
199
- "<<="
200
- "<<|="
201
- ">>="
202
- "&="
203
- "^="
204
- "|="
205
- "!"
206
- "~"
207
- "-"
208
- "-%"
209
- "&"
210
- "=="
211
- "!="
212
- ">"
213
- ">="
214
- "<="
215
- "<"
216
- "&"
217
- "^"
218
- "|"
219
- "<<"
220
- ">>"
221
- "<<|"
222
- "+"
223
- "++"
224
- "+%"
225
- "-%"
226
- "+|"
227
- "-|"
228
- "*"
229
- "/"
230
- "%"
231
- "**"
232
- "*%"
233
- "*|"
234
- "||"
235
- ".*"
236
- ".?"
237
- "?"
238
- ".."
239
- ] @operator
240
-
241
- ; Literals
242
-
243
- (character) @character
244
-
245
- ([
246
- (string)
247
- (multiline_string)
248
- ] @string
249
- (#set! "priority" 95))
250
-
251
- (integer) @number
252
-
253
- (float) @number.float
254
-
255
- (boolean) @boolean
256
-
257
- [
258
- (string (escape_sequence) @string.escape)
259
- (character (escape_sequence) @string.escape)
260
- ]
261
-
262
- "\\\\" @string.special.symbol
263
-
264
- ; Punctuation
265
-
266
- [
267
- "["
268
- "]"
269
- "("
270
- ")"
271
- "{"
272
- "}"
273
- ] @punctuation.bracket
274
-
275
- [
276
- ";"
277
- "."
278
- ","
279
- ":"
280
- "=>"
281
- "->"
282
- ] @punctuation.delimiter
283
-
284
- (payload "|" @punctuation.bracket)
285
-
286
- ; Comments
287
-
288
- (comment) @comment @spell
289
-
290
- [
291
- (doc_comment)
292
- (container_doc_comment)
293
- ] @comment.documentation @spell
@@ -1,24 +0,0 @@
1
- [
2
- (block)
3
- (switch_expression)
4
- (initializer_list)
5
- ] @indent.begin
6
-
7
- (block
8
- "}" @indent.end)
9
-
10
- [
11
- "("
12
- ")"
13
- "["
14
- "]"
15
- "{"
16
- "}"
17
- ] @indent.branch
18
-
19
- [
20
- (comment)
21
- (doc_comment)
22
- (container_doc_comment)
23
- (multiline_string)
24
- ] @indent.ignore
@@ -1,6 +0,0 @@
1
- ((comment) @injection.content
2
- (#set! injection.language "comment"))
3
-
4
- ((doc_comment_content) @injection.content
5
- (#set! injection.language "markdown")
6
- (#set! injection.combined))