@willbooster/tree-sitter-zig 2.0.2 → 3.0.1
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 +9 -5
- package/grammar.js +28 -19
- package/package.json +8 -8
- package/queries/highlights.scm +1 -8
- package/src/node-types.json +50 -19
- 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
|
|
@@ -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 (`0x57420007`) and loads only with that fork's runtime, version 10.0.2 or later in the 10.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
|
|
@@ -36,11 +36,15 @@ rejects it. It parses as the parser in upstream's 1.1.2 packages does, with thes
|
|
|
36
36
|
unions (`E!T`) retain their error and payload types.
|
|
37
37
|
- Empty `struct`, `opaque`, `enum`, and `union` declarations have no fields, instead of synthesized zero-width
|
|
38
38
|
`container_field` and `identifier` nodes.
|
|
39
|
+
- Assignments occur in statement positions, loop continuations, and single-assignment switch prongs.
|
|
40
|
+
Plain block assignments, `else` alternatives, and `comptime` assignments retain `variable_declaration` nodes.
|
|
41
|
+
`assignment_expression` nodes expose `left`, `operator`, and `right` fields.
|
|
42
|
+
Struct field initializers produce `field_initializer` nodes with `name` and `value` fields.
|
|
39
43
|
|
|
40
44
|
## Usage
|
|
41
45
|
|
|
42
46
|
The npm package ships `tree-sitter-zig.wasm` for
|
|
43
|
-
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version
|
|
47
|
+
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 10.0.2 or later in the 10.x series, which runs in Node.js, Bun, browsers, and Cloudflare Workers.
|
|
44
48
|
In Node.js and Bun, load the grammar from its path:
|
|
45
49
|
|
|
46
50
|
```js
|
|
@@ -87,8 +91,8 @@ fuzzed with:
|
|
|
87
91
|
|
|
88
92
|
```toml
|
|
89
93
|
[dependencies]
|
|
90
|
-
tree-sitter = { package = "willbooster-tree-sitter", version = "
|
|
91
|
-
tree-sitter-zig = { package = "willbooster-tree-sitter-zig", version = "
|
|
94
|
+
tree-sitter = { package = "willbooster-tree-sitter", version = "10.0.2" }
|
|
95
|
+
tree-sitter-zig = { package = "willbooster-tree-sitter-zig", version = "3" }
|
|
92
96
|
```
|
|
93
97
|
|
|
94
98
|
```rust
|
package/grammar.js
CHANGED
|
@@ -76,6 +76,8 @@ module.exports = grammar({
|
|
|
76
76
|
|
|
77
77
|
precedences: $ => [
|
|
78
78
|
[$.container_field, $.type_expression],
|
|
79
|
+
[$._variable_declaration_expression_statement, $.assignment_expression],
|
|
80
|
+
[$._variable_declaration_expression_statement, $._single_assignment_expression],
|
|
79
81
|
],
|
|
80
82
|
|
|
81
83
|
supertypes: $ => [
|
|
@@ -156,11 +158,7 @@ module.exports = grammar({
|
|
|
156
158
|
$.expression,
|
|
157
159
|
choice(
|
|
158
160
|
seq(
|
|
159
|
-
|
|
160
|
-
'=', '*=', '*%=', '*|=', '/=', '%=',
|
|
161
|
-
'+=', '+%=', '+|=', '-=', '-%=', '-|=',
|
|
162
|
-
'<<=', '<<|=', '>>=', '&=', '^=', '|=',
|
|
163
|
-
),
|
|
161
|
+
$._assignment_operator,
|
|
164
162
|
$.expression,
|
|
165
163
|
),
|
|
166
164
|
seq(
|
|
@@ -337,7 +335,7 @@ module.exports = grammar({
|
|
|
337
335
|
choice($.block, $.for_statement, $.while_statement),
|
|
338
336
|
)),
|
|
339
337
|
|
|
340
|
-
expression_statement: $ => seq($.expression, ';'),
|
|
338
|
+
expression_statement: $ => seq(choice($.expression, $.assignment_expression), ';'),
|
|
341
339
|
|
|
342
340
|
if_statement: $ => seq(
|
|
343
341
|
$._if_prefix,
|
|
@@ -387,7 +385,7 @@ module.exports = grammar({
|
|
|
387
385
|
field('condition', $.expression),
|
|
388
386
|
')',
|
|
389
387
|
optional($.payload),
|
|
390
|
-
optional(seq(':', '(', $.expression, ')')),
|
|
388
|
+
optional(seq(':', '(', choice($.expression, $.assignment_expression), ')')),
|
|
391
389
|
),
|
|
392
390
|
|
|
393
391
|
_conditional_body: $ => choice(
|
|
@@ -396,7 +394,7 @@ module.exports = grammar({
|
|
|
396
394
|
optional($.else_clause),
|
|
397
395
|
),
|
|
398
396
|
seq(
|
|
399
|
-
field('body', $.expression),
|
|
397
|
+
field('body', choice($.expression, $.assignment_expression)),
|
|
400
398
|
choice(';', $.else_clause),
|
|
401
399
|
),
|
|
402
400
|
),
|
|
@@ -416,7 +414,6 @@ module.exports = grammar({
|
|
|
416
414
|
$.if_expression,
|
|
417
415
|
$.for_expression,
|
|
418
416
|
$.while_expression,
|
|
419
|
-
$.assignment_expression,
|
|
420
417
|
$.unary_expression,
|
|
421
418
|
$.binary_expression,
|
|
422
419
|
$.comptime_expression,
|
|
@@ -483,15 +480,27 @@ module.exports = grammar({
|
|
|
483
480
|
optional(seq('else', optional($.payload), $.expression)),
|
|
484
481
|
)),
|
|
485
482
|
|
|
486
|
-
assignment_expression: $ =>
|
|
483
|
+
assignment_expression: $ => choice(
|
|
484
|
+
$._single_assignment_expression,
|
|
485
|
+
seq(
|
|
486
|
+
field('left', $.expression),
|
|
487
|
+
repeat1(seq(',', field('left', $.expression))),
|
|
488
|
+
field('operator', '='),
|
|
489
|
+
field('right', $.expression),
|
|
490
|
+
),
|
|
491
|
+
),
|
|
492
|
+
|
|
493
|
+
_single_assignment_expression: $ => seq(
|
|
487
494
|
field('left', $.expression),
|
|
488
|
-
field('operator',
|
|
489
|
-
'=', '*=', '*%=', '*|=', '/=', '%=',
|
|
490
|
-
'+=', '+%=', '+|=', '-=', '-%=', '-|=',
|
|
491
|
-
'<<=', '<<|=', '>>=', '&=', '^=', '|=',
|
|
492
|
-
)),
|
|
495
|
+
field('operator', $._assignment_operator),
|
|
493
496
|
field('right', $.expression),
|
|
494
|
-
)
|
|
497
|
+
),
|
|
498
|
+
|
|
499
|
+
_assignment_operator: _ => choice(
|
|
500
|
+
'=', '*=', '*%=', '*|=', '/=', '%=',
|
|
501
|
+
'+=', '+%=', '+|=', '-=', '-%=', '-|=',
|
|
502
|
+
'<<=', '<<|=', '>>=', '&=', '^=', '|=',
|
|
503
|
+
),
|
|
495
504
|
|
|
496
505
|
unary_expression: $ => prec.left(PREC.UNARY, seq(
|
|
497
506
|
field('operator', choice('!', '~', '-', '-%', '&')),
|
|
@@ -582,7 +591,7 @@ module.exports = grammar({
|
|
|
582
591
|
$._switch_case_exp,
|
|
583
592
|
'=>',
|
|
584
593
|
optional($.payload),
|
|
585
|
-
choice($.expression),
|
|
594
|
+
choice($.expression, alias($._single_assignment_expression, $.assignment_expression)),
|
|
586
595
|
),
|
|
587
596
|
_switch_case_exp: $ => seq(
|
|
588
597
|
optional('inline'),
|
|
@@ -750,9 +759,9 @@ module.exports = grammar({
|
|
|
750
759
|
|
|
751
760
|
field_initializer: $ => seq(
|
|
752
761
|
'.',
|
|
753
|
-
$.identifier,
|
|
762
|
+
field('name', $.identifier),
|
|
754
763
|
'=',
|
|
755
|
-
$.expression,
|
|
764
|
+
field('value', $.expression),
|
|
756
765
|
),
|
|
757
766
|
|
|
758
767
|
labeled_type_expression: $ => seq($.block_label, $.block),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-zig",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Zig grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -42,16 +42,16 @@
|
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@tsconfig/bun": "1.0.11",
|
|
45
|
-
"@types/bun": "1.4.
|
|
45
|
+
"@types/bun": "1.4.3",
|
|
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.26.
|
|
50
|
-
"@willbooster/web-tree-sitter": "
|
|
49
|
+
"@willbooster/wb": "22.26.2",
|
|
50
|
+
"@willbooster/web-tree-sitter": "10.0.2",
|
|
51
51
|
"conventional-changelog-conventionalcommits": "10.4.0",
|
|
52
|
-
"lefthook": "2.2.
|
|
53
|
-
"oxfmt": "0.
|
|
54
|
-
"oxlint": "1.
|
|
52
|
+
"lefthook": "2.2.2",
|
|
53
|
+
"oxfmt": "0.73.0",
|
|
54
|
+
"oxlint": "1.88.0",
|
|
55
55
|
"oxlint-tsgolint": "7.0.2004",
|
|
56
56
|
"playwright": "1.63.0",
|
|
57
57
|
"semantic-release": "25.0.9",
|
|
@@ -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": "^10.0.2"
|
|
64
64
|
},
|
|
65
65
|
"peerDependenciesMeta": {
|
|
66
66
|
"@willbooster/web-tree-sitter": {
|
package/queries/highlights.scm
CHANGED
|
@@ -58,8 +58,7 @@
|
|
|
58
58
|
; Fields
|
|
59
59
|
|
|
60
60
|
(field_initializer
|
|
61
|
-
.
|
|
62
|
-
(identifier) @variable.member)
|
|
61
|
+
name: (identifier) @variable.member)
|
|
63
62
|
|
|
64
63
|
(field_expression
|
|
65
64
|
(_)
|
|
@@ -68,12 +67,6 @@
|
|
|
68
67
|
(container_field
|
|
69
68
|
name: (identifier) @variable.member)
|
|
70
69
|
|
|
71
|
-
(initializer_list
|
|
72
|
-
(assignment_expression
|
|
73
|
-
left: (field_expression
|
|
74
|
-
.
|
|
75
|
-
member: (identifier) @variable.member)))
|
|
76
|
-
|
|
77
70
|
(parameter
|
|
78
71
|
type: (field_expression
|
|
79
72
|
member: (identifier) @type))
|
package/src/node-types.json
CHANGED
|
@@ -7,10 +7,6 @@
|
|
|
7
7
|
"type": "asm_expression",
|
|
8
8
|
"named": true
|
|
9
9
|
},
|
|
10
|
-
{
|
|
11
|
-
"type": "assignment_expression",
|
|
12
|
-
"named": true
|
|
13
|
-
},
|
|
14
10
|
{
|
|
15
11
|
"type": "binary_expression",
|
|
16
12
|
"named": true
|
|
@@ -497,7 +493,7 @@
|
|
|
497
493
|
"named": true,
|
|
498
494
|
"fields": {
|
|
499
495
|
"left": {
|
|
500
|
-
"multiple":
|
|
496
|
+
"multiple": true,
|
|
501
497
|
"required": true,
|
|
502
498
|
"types": [
|
|
503
499
|
{
|
|
@@ -1307,6 +1303,10 @@
|
|
|
1307
1303
|
"multiple": false,
|
|
1308
1304
|
"required": true,
|
|
1309
1305
|
"types": [
|
|
1306
|
+
{
|
|
1307
|
+
"type": "assignment_expression",
|
|
1308
|
+
"named": true
|
|
1309
|
+
},
|
|
1310
1310
|
{
|
|
1311
1311
|
"type": "expression",
|
|
1312
1312
|
"named": true
|
|
@@ -1343,20 +1343,27 @@
|
|
|
1343
1343
|
{
|
|
1344
1344
|
"type": "field_initializer",
|
|
1345
1345
|
"named": true,
|
|
1346
|
-
"fields": {
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1346
|
+
"fields": {
|
|
1347
|
+
"name": {
|
|
1348
|
+
"multiple": false,
|
|
1349
|
+
"required": true,
|
|
1350
|
+
"types": [
|
|
1351
|
+
{
|
|
1352
|
+
"type": "identifier",
|
|
1353
|
+
"named": true
|
|
1354
|
+
}
|
|
1355
|
+
]
|
|
1356
|
+
},
|
|
1357
|
+
"value": {
|
|
1358
|
+
"multiple": false,
|
|
1359
|
+
"required": true,
|
|
1360
|
+
"types": [
|
|
1361
|
+
{
|
|
1362
|
+
"type": "expression",
|
|
1363
|
+
"named": true
|
|
1364
|
+
}
|
|
1365
|
+
]
|
|
1366
|
+
}
|
|
1360
1367
|
}
|
|
1361
1368
|
},
|
|
1362
1369
|
{
|
|
@@ -1390,6 +1397,10 @@
|
|
|
1390
1397
|
"multiple": false,
|
|
1391
1398
|
"required": true,
|
|
1392
1399
|
"types": [
|
|
1400
|
+
{
|
|
1401
|
+
"type": "assignment_expression",
|
|
1402
|
+
"named": true
|
|
1403
|
+
},
|
|
1393
1404
|
{
|
|
1394
1405
|
"type": "block_expression",
|
|
1395
1406
|
"named": true
|
|
@@ -1615,6 +1626,10 @@
|
|
|
1615
1626
|
"multiple": false,
|
|
1616
1627
|
"required": true,
|
|
1617
1628
|
"types": [
|
|
1629
|
+
{
|
|
1630
|
+
"type": "assignment_expression",
|
|
1631
|
+
"named": true
|
|
1632
|
+
},
|
|
1618
1633
|
{
|
|
1619
1634
|
"type": "block_expression",
|
|
1620
1635
|
"named": true
|
|
@@ -2253,6 +2268,10 @@
|
|
|
2253
2268
|
"multiple": true,
|
|
2254
2269
|
"required": true,
|
|
2255
2270
|
"types": [
|
|
2271
|
+
{
|
|
2272
|
+
"type": "assignment_expression",
|
|
2273
|
+
"named": true
|
|
2274
|
+
},
|
|
2256
2275
|
{
|
|
2257
2276
|
"type": "expression",
|
|
2258
2277
|
"named": true
|
|
@@ -2494,6 +2513,10 @@
|
|
|
2494
2513
|
"multiple": true,
|
|
2495
2514
|
"required": true,
|
|
2496
2515
|
"types": [
|
|
2516
|
+
{
|
|
2517
|
+
"type": "assignment_expression",
|
|
2518
|
+
"named": true
|
|
2519
|
+
},
|
|
2497
2520
|
{
|
|
2498
2521
|
"type": "block_label",
|
|
2499
2522
|
"named": true
|
|
@@ -2517,6 +2540,10 @@
|
|
|
2517
2540
|
"multiple": false,
|
|
2518
2541
|
"required": true,
|
|
2519
2542
|
"types": [
|
|
2543
|
+
{
|
|
2544
|
+
"type": "assignment_expression",
|
|
2545
|
+
"named": true
|
|
2546
|
+
},
|
|
2520
2547
|
{
|
|
2521
2548
|
"type": "block_expression",
|
|
2522
2549
|
"named": true
|
|
@@ -2542,6 +2569,10 @@
|
|
|
2542
2569
|
"multiple": true,
|
|
2543
2570
|
"required": false,
|
|
2544
2571
|
"types": [
|
|
2572
|
+
{
|
|
2573
|
+
"type": "assignment_expression",
|
|
2574
|
+
"named": true
|
|
2575
|
+
},
|
|
2545
2576
|
{
|
|
2546
2577
|
"type": "else_clause",
|
|
2547
2578
|
"named": true
|
package/tree-sitter-zig.wasm
CHANGED
|
Binary file
|