@willbooster/tree-sitter-zig 1.0.0 → 1.0.2

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
@@ -12,10 +12,10 @@ Zig grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forke
12
12
  [tree-sitter-grammars/tree-sitter-zig](https://github.com/tree-sitter-grammars/tree-sitter-zig). We are grateful
13
13
  to its authors and contributors. This is not an official release of that project.
14
14
 
15
- This fork keeps the grammar of upstream's version 1.1.2 and generates the parser with the
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
17
  number (`0x57420001`) and loads only with that fork's runtime, version 2.0.0 or later: upstream's tree-sitter runtime
18
- rejects it. It parses as the parser in upstream's 1.1.2 packages does, with two exceptions:
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
21
21
  the one before `..`, for example `(`, `[`, `.`, `*`, `&`, `-`, or `!` (as in `for (0..(n)) |i| {}` or
@@ -27,6 +27,12 @@ rejects it. It parses as the parser in upstream's 1.1.2 packages does, with two
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
+ - Boolean negation is a `unary_expression`. Inferred error unions (`!T`) occur only in function return types;
31
+ their payload includes suffixes such as calls and field access (`!List(T)` or `!ns.Result`). Explicit error
32
+ unions (`E!T`) retain their error and payload types.
33
+ - Empty `struct`, `opaque`, `enum`, and `union` declarations have no fields, instead of synthesized zero-width
34
+ `container_field` and `identifier` nodes.
35
+
30
36
  ## Usage
31
37
 
32
38
  The npm package ships `tree-sitter-zig.wasm` for
@@ -106,7 +112,7 @@ well (e.g. `script/tree-sitter parse file.zig`).
106
112
  `bun run generate` records a fresh generation profile from the applicable `test/corpus` cases, then generates
107
113
  compact parser tables. It would also profile files tracked in `examples/`, but this repository tracks none: upstream
108
114
  ships neither examples nor a corpus, so the cases in `test/corpus` were written for this fork, with the trees upstream's
109
- packaged parser gives them, except the NUL case and the `for` range case, which pin this parser's reading. The parser also embeds metadata from `tree-sitter.json`.
115
+ packaged parser gives them, except the NUL, `for` range, and empty-container cases, which pin this parser's reading. The parser also embeds metadata from `tree-sitter.json`.
110
116
  After changing a grammar, `tree-sitter.json`, or a corpus case, regenerate and commit `src/`.
111
117
  Profiles in `.tmp/generation-profiles/` are temporary and must not be committed. `bun run build-wasm`, `bun run build/ci`,
112
118
  and the release build regenerate the parsers before compiling them.
package/grammar.js CHANGED
@@ -208,9 +208,16 @@ module.exports = grammar({
208
208
  optional($.address_space),
209
209
  optional($.link_section),
210
210
  optional($.calling_convention),
211
- field('type', choice($.type_expression, $.if_type_expression, $.comptime_type_expression)),
211
+ field('type', choice(
212
+ $.type_expression,
213
+ $.if_type_expression,
214
+ $.comptime_type_expression,
215
+ alias($._inferred_error_union_type, $.error_union_type),
216
+ )),
212
217
  ),
213
218
 
219
+ _inferred_error_union_type: $ => prec.right(-1, seq('!', field('ok', $.type_expression))),
220
+
214
221
  parameters: $ => seq('(', optionalCommaSep($.parameter), ')'),
215
222
 
216
223
  parameter: $ => choice(
@@ -243,7 +250,7 @@ module.exports = grammar({
243
250
  'struct',
244
251
  optional(seq('(', $.expression, ')')),
245
252
  '{',
246
- $._container_members,
253
+ optional($._container_members),
247
254
  '}',
248
255
  ),
249
256
 
@@ -251,7 +258,7 @@ module.exports = grammar({
251
258
  optional(choice('extern', 'packed')),
252
259
  'opaque',
253
260
  '{',
254
- $._container_members,
261
+ optional($._container_members),
255
262
  '}',
256
263
  ),
257
264
 
@@ -260,7 +267,7 @@ module.exports = grammar({
260
267
  'enum',
261
268
  optional(seq('(', $.expression, ')')),
262
269
  '{',
263
- $._container_members,
270
+ optional($._container_members),
264
271
  '}',
265
272
  ),
266
273
 
@@ -276,7 +283,7 @@ module.exports = grammar({
276
283
  ')',
277
284
  )),
278
285
  '{',
279
- $._container_members,
286
+ optional($._container_members),
280
287
  '}',
281
288
  ),
282
289
 
@@ -698,7 +705,7 @@ module.exports = grammar({
698
705
  )),
699
706
 
700
707
  error_union_type: $ => prec.right(2, seq(
701
- optional(field('error', $.type_expression)),
708
+ field('error', $.type_expression),
702
709
  '!',
703
710
  field('ok', $.type_expression),
704
711
  )),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-zig",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Zig grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -50,8 +50,8 @@
50
50
  "@willbooster/web-tree-sitter": "2.0.1",
51
51
  "conventional-changelog-conventionalcommits": "10.4.0",
52
52
  "lefthook": "2.1.16",
53
- "oxfmt": "0.71.0",
54
- "oxlint": "1.86.0",
53
+ "oxfmt": "0.72.0",
54
+ "oxlint": "1.87.0",
55
55
  "oxlint-tsgolint": "7.0.2003",
56
56
  "playwright": "1.63.0",
57
57
  "semantic-release": "25.0.9",
@@ -1217,7 +1217,7 @@
1217
1217
  "fields": {},
1218
1218
  "children": {
1219
1219
  "multiple": true,
1220
- "required": true,
1220
+ "required": false,
1221
1221
  "types": [
1222
1222
  {
1223
1223
  "type": "comptime_declaration",
@@ -1486,6 +1486,10 @@
1486
1486
  "type": "comptime_type_expression",
1487
1487
  "named": true
1488
1488
  },
1489
+ {
1490
+ "type": "error_union_type",
1491
+ "named": true
1492
+ },
1489
1493
  {
1490
1494
  "type": "if_type_expression",
1491
1495
  "named": true
@@ -1550,6 +1554,10 @@
1550
1554
  "type": "comptime_type_expression",
1551
1555
  "named": true
1552
1556
  },
1557
+ {
1558
+ "type": "error_union_type",
1559
+ "named": true
1560
+ },
1553
1561
  {
1554
1562
  "type": "if_type_expression",
1555
1563
  "named": true
@@ -1910,7 +1918,7 @@
1910
1918
  "fields": {},
1911
1919
  "children": {
1912
1920
  "multiple": true,
1913
- "required": true,
1921
+ "required": false,
1914
1922
  "types": [
1915
1923
  {
1916
1924
  "type": "comptime_declaration",
@@ -2188,7 +2196,7 @@
2188
2196
  "fields": {},
2189
2197
  "children": {
2190
2198
  "multiple": true,
2191
- "required": true,
2199
+ "required": false,
2192
2200
  "types": [
2193
2201
  {
2194
2202
  "type": "comptime_declaration",
@@ -2391,7 +2399,7 @@
2391
2399
  "fields": {},
2392
2400
  "children": {
2393
2401
  "multiple": true,
2394
- "required": true,
2402
+ "required": false,
2395
2403
  "types": [
2396
2404
  {
2397
2405
  "type": "comptime_declaration",
Binary file
package/tree-sitter.json CHANGED
@@ -15,7 +15,7 @@
15
15
  }
16
16
  ],
17
17
  "metadata": {
18
- "version": "1.0.0",
18
+ "version": "1.0.2",
19
19
  "license": "MIT",
20
20
  "description": "Zig grammar for tree-sitter",
21
21
  "authors": [