@willbooster/tree-sitter-zig 1.0.3 → 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 +11 -6
- package/grammar.js +5 -11
- package/package.json +3 -3
- package/queries/highlights.scm +0 -2
- package/src/node-types.json +19 -53
- package/tree-sitter-zig.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ to its authors and contributors. This is not an official release of that project
|
|
|
14
14
|
|
|
15
15
|
This fork builds on the grammar of upstream's version 1.1.2 and generates the parser with the
|
|
16
16
|
[WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter) generator. The parser carries that fork's own ABI
|
|
17
|
-
number (`
|
|
17
|
+
number (`0x57420006`) and loads only with that fork's runtime, version 7.0.5 or later in the 7.x series: upstream's tree-sitter runtime
|
|
18
18
|
rejects it. It parses as the parser in upstream's 1.1.2 packages does, with these exceptions:
|
|
19
19
|
|
|
20
20
|
- In the ranges a `for` loop iterates over, a range end whose first token can both start an expression and continue
|
|
@@ -27,6 +27,9 @@ rejects it. It parses as the parser in upstream's 1.1.2 packages does, with thes
|
|
|
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
29
|
|
|
30
|
+
- Error sets are accepted directly as container field types, and pointer and slice element types may be conditional.
|
|
31
|
+
- `async` and `await` are ordinary identifiers. Assembly clobbers use an expression, including an anonymous struct
|
|
32
|
+
initializer, as in Zig 0.16.
|
|
30
33
|
- Zero-bit integers `u0` and `i0` are builtin types.
|
|
31
34
|
- Boolean negation is a `unary_expression`. Inferred error unions (`!T`) occur only in function return types;
|
|
32
35
|
their payload includes suffixes such as calls and field access (`!List(T)` or `!ns.Result`). Explicit error
|
|
@@ -37,7 +40,8 @@ rejects it. It parses as the parser in upstream's 1.1.2 packages does, with thes
|
|
|
37
40
|
## Usage
|
|
38
41
|
|
|
39
42
|
The npm package ships `tree-sitter-zig.wasm` for
|
|
40
|
-
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version
|
|
43
|
+
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 7.0.5 or later in the 7.x series, which runs in Node.js, Bun, browsers, and Cloudflare Workers.
|
|
44
|
+
In Node.js and Bun, load the grammar from its path:
|
|
41
45
|
|
|
42
46
|
```js
|
|
43
47
|
import { fileURLToPath } from 'node:url';
|
|
@@ -83,8 +87,8 @@ fuzzed with:
|
|
|
83
87
|
|
|
84
88
|
```toml
|
|
85
89
|
[dependencies]
|
|
86
|
-
tree-sitter = { package = "willbooster-tree-sitter", version = "
|
|
87
|
-
tree-sitter-zig = { package = "willbooster-tree-sitter-zig", version = "
|
|
90
|
+
tree-sitter = { package = "willbooster-tree-sitter", version = "7.0.5" }
|
|
91
|
+
tree-sitter-zig = { package = "willbooster-tree-sitter-zig", version = "2" }
|
|
88
92
|
```
|
|
89
93
|
|
|
90
94
|
```rust
|
|
@@ -126,8 +130,9 @@ and the release build regenerate the parsers before compiling them.
|
|
|
126
130
|
edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
|
|
127
131
|
`TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
|
|
128
132
|
- a check that the real-world Zig files in `examples/` fail to parse exactly as listed in
|
|
129
|
-
`script/known-failures.txt
|
|
130
|
-
|
|
133
|
+
`script/known-failures.txt`, while every library file from the pinned Zig 0.16 release must parse without errors.
|
|
134
|
+
The older Zig corpus retains coverage of unsupported syntax. The first run fetches the repositories and the
|
|
135
|
+
checksum-pinned Zig source archive. Their revisions are pinned in `script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples` rewrites it;
|
|
131
136
|
review its diff before committing;
|
|
132
137
|
- a performance check (`test/unit/performance.test.ts`) that recovering from an error on each line takes linear
|
|
133
138
|
time, since consumers parse files while they are being edited. It loads the Wasm build through
|
package/grammar.js
CHANGED
|
@@ -124,9 +124,9 @@ module.exports = grammar({
|
|
|
124
124
|
seq(
|
|
125
125
|
field('name', choice($.identifier, $._reserved_identifier, alias($.builtin_type, $.identifier))),
|
|
126
126
|
':',
|
|
127
|
-
field('type', choice($.primary_type_expression, $.if_type_expression, $.comptime_type_expression)),
|
|
127
|
+
field('type', choice($.primary_type_expression, $.if_type_expression, $.comptime_type_expression, $.error_set_declaration)),
|
|
128
128
|
),
|
|
129
|
-
field('name', choice($.primary_type_expression, $.if_type_expression, $.comptime_type_expression)),
|
|
129
|
+
field('name', choice($.primary_type_expression, $.if_type_expression, $.comptime_type_expression, $.error_set_declaration)),
|
|
130
130
|
),
|
|
131
131
|
optional($.byte_alignment),
|
|
132
132
|
optional(seq('=', $.expression)),
|
|
@@ -420,8 +420,6 @@ module.exports = grammar({
|
|
|
420
420
|
$.unary_expression,
|
|
421
421
|
$.binary_expression,
|
|
422
422
|
$.comptime_expression,
|
|
423
|
-
$.async_expression,
|
|
424
|
-
$.await_expression,
|
|
425
423
|
$.nosuspend_expression,
|
|
426
424
|
$.continue_expression,
|
|
427
425
|
$.resume_expression,
|
|
@@ -461,7 +459,7 @@ module.exports = grammar({
|
|
|
461
459
|
$.expression,
|
|
462
460
|
')',
|
|
463
461
|
),
|
|
464
|
-
asm_clobbers: $ => seq(':',
|
|
462
|
+
asm_clobbers: $ => seq(':', $.expression),
|
|
465
463
|
|
|
466
464
|
if_expression: $ => prec.right(seq(
|
|
467
465
|
$._if_prefix,
|
|
@@ -545,10 +543,6 @@ module.exports = grammar({
|
|
|
545
543
|
|
|
546
544
|
comptime_expression: $ => prec.right(seq('comptime', $.expression)),
|
|
547
545
|
|
|
548
|
-
async_expression: $ => prec.right(seq('async', $.expression)),
|
|
549
|
-
|
|
550
|
-
await_expression: $ => prec.right(seq('await', $.expression)),
|
|
551
|
-
|
|
552
546
|
nosuspend_expression: $ => prec.right(seq('nosuspend', $.expression)),
|
|
553
547
|
|
|
554
548
|
continue_expression: $ => prec.right(seq(
|
|
@@ -667,7 +661,7 @@ module.exports = grammar({
|
|
|
667
661
|
'volatile',
|
|
668
662
|
'allowzero',
|
|
669
663
|
)),
|
|
670
|
-
$.type_expression,
|
|
664
|
+
choice($.type_expression, $.if_type_expression),
|
|
671
665
|
)),
|
|
672
666
|
|
|
673
667
|
pointer_type: $ => prec.right(1, seq(
|
|
@@ -693,7 +687,7 @@ module.exports = grammar({
|
|
|
693
687
|
'volatile',
|
|
694
688
|
'allowzero',
|
|
695
689
|
)),
|
|
696
|
-
$.type_expression,
|
|
690
|
+
choice($.type_expression, $.if_type_expression),
|
|
697
691
|
)),
|
|
698
692
|
|
|
699
693
|
array_type: $ => prec(1, seq(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-zig",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Zig 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.26.1",
|
|
50
|
-
"@willbooster/web-tree-sitter": "
|
|
50
|
+
"@willbooster/web-tree-sitter": "7.0.5",
|
|
51
51
|
"conventional-changelog-conventionalcommits": "10.4.0",
|
|
52
52
|
"lefthook": "2.2.1",
|
|
53
53
|
"oxfmt": "0.72.0",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"wrangler": "4.147.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@willbooster/web-tree-sitter": "^
|
|
63
|
+
"@willbooster/web-tree-sitter": "^7.0.5"
|
|
64
64
|
},
|
|
65
65
|
"peerDependenciesMeta": {
|
|
66
66
|
"@willbooster/web-tree-sitter": {
|
package/queries/highlights.scm
CHANGED
package/src/node-types.json
CHANGED
|
@@ -11,14 +11,6 @@
|
|
|
11
11
|
"type": "assignment_expression",
|
|
12
12
|
"named": true
|
|
13
13
|
},
|
|
14
|
-
{
|
|
15
|
-
"type": "async_expression",
|
|
16
|
-
"named": true
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"type": "await_expression",
|
|
20
|
-
"named": true
|
|
21
|
-
},
|
|
22
14
|
{
|
|
23
15
|
"type": "binary_expression",
|
|
24
16
|
"named": true
|
|
@@ -379,15 +371,11 @@
|
|
|
379
371
|
"named": true,
|
|
380
372
|
"fields": {},
|
|
381
373
|
"children": {
|
|
382
|
-
"multiple":
|
|
383
|
-
"required":
|
|
374
|
+
"multiple": false,
|
|
375
|
+
"required": true,
|
|
384
376
|
"types": [
|
|
385
377
|
{
|
|
386
|
-
"type": "
|
|
387
|
-
"named": true
|
|
388
|
-
},
|
|
389
|
-
{
|
|
390
|
-
"type": "string",
|
|
378
|
+
"type": "expression",
|
|
391
379
|
"named": true
|
|
392
380
|
}
|
|
393
381
|
]
|
|
@@ -608,36 +596,6 @@
|
|
|
608
596
|
}
|
|
609
597
|
}
|
|
610
598
|
},
|
|
611
|
-
{
|
|
612
|
-
"type": "async_expression",
|
|
613
|
-
"named": true,
|
|
614
|
-
"fields": {},
|
|
615
|
-
"children": {
|
|
616
|
-
"multiple": false,
|
|
617
|
-
"required": true,
|
|
618
|
-
"types": [
|
|
619
|
-
{
|
|
620
|
-
"type": "expression",
|
|
621
|
-
"named": true
|
|
622
|
-
}
|
|
623
|
-
]
|
|
624
|
-
}
|
|
625
|
-
},
|
|
626
|
-
{
|
|
627
|
-
"type": "await_expression",
|
|
628
|
-
"named": true,
|
|
629
|
-
"fields": {},
|
|
630
|
-
"children": {
|
|
631
|
-
"multiple": false,
|
|
632
|
-
"required": true,
|
|
633
|
-
"types": [
|
|
634
|
-
{
|
|
635
|
-
"type": "expression",
|
|
636
|
-
"named": true
|
|
637
|
-
}
|
|
638
|
-
]
|
|
639
|
-
}
|
|
640
|
-
},
|
|
641
599
|
{
|
|
642
600
|
"type": "binary_expression",
|
|
643
601
|
"named": true,
|
|
@@ -1076,6 +1034,10 @@
|
|
|
1076
1034
|
"type": "comptime_type_expression",
|
|
1077
1035
|
"named": true
|
|
1078
1036
|
},
|
|
1037
|
+
{
|
|
1038
|
+
"type": "error_set_declaration",
|
|
1039
|
+
"named": true
|
|
1040
|
+
},
|
|
1079
1041
|
{
|
|
1080
1042
|
"type": "false",
|
|
1081
1043
|
"named": false
|
|
@@ -1102,6 +1064,10 @@
|
|
|
1102
1064
|
"type": "comptime_type_expression",
|
|
1103
1065
|
"named": true
|
|
1104
1066
|
},
|
|
1067
|
+
{
|
|
1068
|
+
"type": "error_set_declaration",
|
|
1069
|
+
"named": true
|
|
1070
|
+
},
|
|
1105
1071
|
{
|
|
1106
1072
|
"type": "if_type_expression",
|
|
1107
1073
|
"named": true
|
|
@@ -2041,6 +2007,10 @@
|
|
|
2041
2007
|
{
|
|
2042
2008
|
"type": "expression",
|
|
2043
2009
|
"named": true
|
|
2010
|
+
},
|
|
2011
|
+
{
|
|
2012
|
+
"type": "if_type_expression",
|
|
2013
|
+
"named": true
|
|
2044
2014
|
}
|
|
2045
2015
|
]
|
|
2046
2016
|
}
|
|
@@ -2128,6 +2098,10 @@
|
|
|
2128
2098
|
"type": "byte_alignment",
|
|
2129
2099
|
"named": true
|
|
2130
2100
|
},
|
|
2101
|
+
{
|
|
2102
|
+
"type": "if_type_expression",
|
|
2103
|
+
"named": true
|
|
2104
|
+
},
|
|
2131
2105
|
{
|
|
2132
2106
|
"type": "type_expression",
|
|
2133
2107
|
"named": true
|
|
@@ -2859,14 +2833,6 @@
|
|
|
2859
2833
|
"type": "asm",
|
|
2860
2834
|
"named": false
|
|
2861
2835
|
},
|
|
2862
|
-
{
|
|
2863
|
-
"type": "async",
|
|
2864
|
-
"named": false
|
|
2865
|
-
},
|
|
2866
|
-
{
|
|
2867
|
-
"type": "await",
|
|
2868
|
-
"named": false
|
|
2869
|
-
},
|
|
2870
2836
|
{
|
|
2871
2837
|
"type": "bool",
|
|
2872
2838
|
"named": false
|
package/tree-sitter-zig.wasm
CHANGED
|
Binary file
|