@willbooster/tree-sitter-zig 6.0.3 → 8.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 +16 -11
- package/grammar.js +4 -2
- package/package.json +5 -6
- package/src/node-types.json +6 -2
- package/tree-sitter-zig.wasm +0 -0
- package/tree-sitter.json +1 -3
- package/queries/folds.scm +0 -23
- package/queries/highlights.scm +0 -290
- package/queries/indents.scm +0 -24
- package/queries/injections.scm +0 -6
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/WillBooster/tree-sitter-zig/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/WillBooster/tree-sitter-zig/actions/workflows/test-rust.yml)
|
|
7
7
|
[](https://github.com/semantic-release/semantic-release)
|
|
8
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
9
9
|
[](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,17 +26,19 @@ 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.
|
|
30
|
-
the
|
|
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
|
|
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
|
-
|
|
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
37
|
- `async` and `await` are ordinary identifiers. Assembly clobbers use an expression, including an anonymous struct
|
|
38
38
|
initializer, as in Zig 0.16.
|
|
39
39
|
- Zero-bit integers `u0` and `i0` are builtin types.
|
|
40
|
+
- Quoted identifiers such as `@"hello world"` expose their content directly inside `identifier`, without a nested
|
|
41
|
+
`string` node.
|
|
40
42
|
- Boolean negation is a `unary_expression`. Inferred error unions (`!T`) occur only in function return types;
|
|
41
43
|
their payload includes suffixes such as calls and field access (`!List(T)` or `!ns.Result`). Explicit error
|
|
42
44
|
unions (`E!T`) retain their error and payload types.
|
|
@@ -47,6 +49,13 @@ rejects it. It parses as the parser in upstream's 1.1.2 packages does, with thes
|
|
|
47
49
|
`assignment_expression` nodes expose `left`, `operator`, and `right` fields.
|
|
48
50
|
Struct field initializers produce `field_initializer` nodes with `name` and `value` fields.
|
|
49
51
|
|
|
52
|
+
## Support Scope
|
|
53
|
+
|
|
54
|
+
This fork maintains only full parsing: valid input yields a correct tree, and invalid input yields `ERROR` or `MISSING`
|
|
55
|
+
nodes without crashing, hanging, or taking more than linear time. Incremental parsing works as in upstream tree-sitter
|
|
56
|
+
but is not tested here, and no queries (highlights, locals, injections, tags) are shipped. Node types, field names, and
|
|
57
|
+
the trees that error recovery produces may change; such changes are released as new major versions.
|
|
58
|
+
|
|
50
59
|
## Usage
|
|
51
60
|
|
|
52
61
|
The npm package ships `tree-sitter-zig.wasm` for
|
|
@@ -90,7 +99,7 @@ const parser = new Parser();
|
|
|
90
99
|
parser.setLanguage(await Language.load(zig));
|
|
91
100
|
```
|
|
92
101
|
|
|
93
|
-
The package also ships `grammar.js
|
|
102
|
+
The package also ships `grammar.js` and the node types in `src/node-types.json`.
|
|
94
103
|
It includes `src/scanner.c`, which must be compiled with a parser regenerated from this grammar.
|
|
95
104
|
|
|
96
105
|
In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-zig) and on
|
|
@@ -138,9 +147,6 @@ and the release build regenerate the parsers before compiling them.
|
|
|
138
147
|
`bun run test` runs:
|
|
139
148
|
|
|
140
149
|
- the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
|
|
141
|
-
- an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
|
|
142
|
-
edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
|
|
143
|
-
`TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
|
|
144
150
|
- a check that the real-world Zig files in `examples/` fail to parse exactly as listed in
|
|
145
151
|
`script/known-failures.txt`, while every library file from the pinned Zig 0.16 release must parse without errors.
|
|
146
152
|
The older Zig corpus retains coverage of unsupported syntax. The first run fetches the repositories and the
|
|
@@ -156,8 +162,7 @@ and the release build regenerate the parsers before compiling them.
|
|
|
156
162
|
Cloudflare Workers with and without Node.js compatibility (`test/e2e/workers.test.ts`).
|
|
157
163
|
|
|
158
164
|
The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
|
|
159
|
-
by every checkout
|
|
160
|
-
afterwards.
|
|
165
|
+
by every checkout.
|
|
161
166
|
|
|
162
167
|
CI also runs these tests on Linux arm64 and macOS, where the CLI compiles the parser natively, and fuzzes the parser
|
|
163
168
|
with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
|
package/grammar.js
CHANGED
|
@@ -793,7 +793,9 @@ module.exports = grammar({
|
|
|
793
793
|
$.arguments,
|
|
794
794
|
),
|
|
795
795
|
|
|
796
|
-
string: $ =>
|
|
796
|
+
string: $ => $._string,
|
|
797
|
+
|
|
798
|
+
_string: $ => seq(
|
|
797
799
|
'"',
|
|
798
800
|
repeat(choice(
|
|
799
801
|
alias(token.immediate(prec(1, /[^\\"\n]+/)), $.string_content),
|
|
@@ -868,7 +870,7 @@ module.exports = grammar({
|
|
|
868
870
|
|
|
869
871
|
builtin_identifier: _ => /@[A-Za-z_][A-Za-z0-9_]*/,
|
|
870
872
|
|
|
871
|
-
identifier: $ => choice($._identifier, seq('@', $.
|
|
873
|
+
identifier: $ => choice($._identifier, seq('@', $._string)),
|
|
872
874
|
_identifier: _ => /[A-Za-z_][A-Za-z0-9_]*/,
|
|
873
875
|
_reserved_identifier: _ => choice(
|
|
874
876
|
'undefined',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-zig",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.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,15 +46,15 @@
|
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"@tsconfig/bun": "1.0.11",
|
|
50
|
-
"@types/bun": "1.4.
|
|
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.
|
|
52
|
+
"@willbooster/wb": "22.32.3",
|
|
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.
|
|
58
|
-
"oxlint-tsgolint": "7.0.
|
|
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",
|
package/src/node-types.json
CHANGED
|
@@ -1626,11 +1626,15 @@
|
|
|
1626
1626
|
"named": true,
|
|
1627
1627
|
"fields": {},
|
|
1628
1628
|
"children": {
|
|
1629
|
-
"multiple":
|
|
1629
|
+
"multiple": true,
|
|
1630
1630
|
"required": false,
|
|
1631
1631
|
"types": [
|
|
1632
1632
|
{
|
|
1633
|
-
"type": "
|
|
1633
|
+
"type": "escape_sequence",
|
|
1634
|
+
"named": true
|
|
1635
|
+
},
|
|
1636
|
+
{
|
|
1637
|
+
"type": "string_content",
|
|
1634
1638
|
"named": true
|
|
1635
1639
|
}
|
|
1636
1640
|
]
|
package/tree-sitter-zig.wasm
CHANGED
|
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": "
|
|
16
|
+
"version": "8.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
|
-
|
package/queries/highlights.scm
DELETED
|
@@ -1,290 +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
|
-
(escape_sequence) @string.escape
|
|
258
|
-
|
|
259
|
-
"\\\\" @string.special.symbol
|
|
260
|
-
|
|
261
|
-
; Punctuation
|
|
262
|
-
|
|
263
|
-
[
|
|
264
|
-
"["
|
|
265
|
-
"]"
|
|
266
|
-
"("
|
|
267
|
-
")"
|
|
268
|
-
"{"
|
|
269
|
-
"}"
|
|
270
|
-
] @punctuation.bracket
|
|
271
|
-
|
|
272
|
-
[
|
|
273
|
-
";"
|
|
274
|
-
"."
|
|
275
|
-
","
|
|
276
|
-
":"
|
|
277
|
-
"=>"
|
|
278
|
-
"->"
|
|
279
|
-
] @punctuation.delimiter
|
|
280
|
-
|
|
281
|
-
(payload "|" @punctuation.bracket)
|
|
282
|
-
|
|
283
|
-
; Comments
|
|
284
|
-
|
|
285
|
-
(comment) @comment @spell
|
|
286
|
-
|
|
287
|
-
[
|
|
288
|
-
(doc_comment)
|
|
289
|
-
(container_doc_comment)
|
|
290
|
-
] @comment.documentation @spell
|
package/queries/indents.scm
DELETED
|
@@ -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
|