@willbooster/tree-sitter-zig 1.0.2 → 1.0.4
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 +10 -4
- package/grammar.js +6 -12
- package/package.json +4 -5
- 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
|
@@ -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
|
|
@@ -27,6 +27,10 @@ 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.
|
|
33
|
+
- Zero-bit integers `u0` and `i0` are builtin types.
|
|
30
34
|
- Boolean negation is a `unary_expression`. Inferred error unions (`!T`) occur only in function return types;
|
|
31
35
|
their payload includes suffixes such as calls and field access (`!List(T)` or `!ns.Result`). Explicit error
|
|
32
36
|
unions (`E!T`) retain their error and payload types.
|
|
@@ -112,7 +116,8 @@ well (e.g. `script/tree-sitter parse file.zig`).
|
|
|
112
116
|
`bun run generate` records a fresh generation profile from the applicable `test/corpus` cases, then generates
|
|
113
117
|
compact parser tables. It would also profile files tracked in `examples/`, but this repository tracks none: upstream
|
|
114
118
|
ships neither examples nor a corpus, so the cases in `test/corpus` were written for this fork, with the trees upstream's
|
|
115
|
-
packaged parser gives them, except the
|
|
119
|
+
packaged parser gives them, except where the parsing differences listed above apply. Those cases pin this fork's
|
|
120
|
+
reading. The parser also embeds metadata from `tree-sitter.json`.
|
|
116
121
|
After changing a grammar, `tree-sitter.json`, or a corpus case, regenerate and commit `src/`.
|
|
117
122
|
Profiles in `.tmp/generation-profiles/` are temporary and must not be committed. `bun run build-wasm`, `bun run build/ci`,
|
|
118
123
|
and the release build regenerate the parsers before compiling them.
|
|
@@ -124,8 +129,9 @@ and the release build regenerate the parsers before compiling them.
|
|
|
124
129
|
edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
|
|
125
130
|
`TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
|
|
126
131
|
- a check that the real-world Zig files in `examples/` fail to parse exactly as listed in
|
|
127
|
-
`script/known-failures.txt
|
|
128
|
-
|
|
132
|
+
`script/known-failures.txt`, while every library file from the pinned Zig 0.16 release must parse without errors.
|
|
133
|
+
The older Zig corpus retains coverage of unsupported syntax. The first run fetches the repositories and the
|
|
134
|
+
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;
|
|
129
135
|
review its diff before committing;
|
|
130
136
|
- a performance check (`test/unit/performance.test.ts`) that recovering from an error on each line takes linear
|
|
131
137
|
time, since consumers parse files while they are being edited. It loads the Wasm build through
|
package/grammar.js
CHANGED
|
@@ -48,7 +48,7 @@ const builtinTypes = [
|
|
|
48
48
|
'c_longlong',
|
|
49
49
|
'c_ulonglong',
|
|
50
50
|
'c_longdouble',
|
|
51
|
-
/(i|u)[1-9][0-9]
|
|
51
|
+
/(i|u)(0|[1-9][0-9]*)/,
|
|
52
52
|
];
|
|
53
53
|
|
|
54
54
|
module.exports = grammar({
|
|
@@ -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": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Zig grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -46,17 +46,16 @@
|
|
|
46
46
|
"@vitest/browser-playwright": "5.0.3",
|
|
47
47
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
48
48
|
"@willbooster/oxlint-config": "1.4.8",
|
|
49
|
-
"@willbooster/wb": "22.
|
|
49
|
+
"@willbooster/wb": "22.26.1",
|
|
50
50
|
"@willbooster/web-tree-sitter": "2.0.1",
|
|
51
51
|
"conventional-changelog-conventionalcommits": "10.4.0",
|
|
52
|
-
"lefthook": "2.1
|
|
52
|
+
"lefthook": "2.2.1",
|
|
53
53
|
"oxfmt": "0.72.0",
|
|
54
54
|
"oxlint": "1.87.0",
|
|
55
|
-
"oxlint-tsgolint": "7.0.
|
|
55
|
+
"oxlint-tsgolint": "7.0.2004",
|
|
56
56
|
"playwright": "1.63.0",
|
|
57
57
|
"semantic-release": "25.0.9",
|
|
58
58
|
"sort-package-json": "4.0.0",
|
|
59
|
-
"typescript": "7.0.2",
|
|
60
59
|
"vitest": "5.0.3",
|
|
61
60
|
"wrangler": "4.147.0"
|
|
62
61
|
},
|
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
|