@willbooster/tree-sitter-zig 19.0.0 → 21.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 +22 -19
- package/grammar.js +133 -240
- package/package.json +6 -7
- package/src/node-types.json +2654 -523
- package/src/scanner.c +11 -121
- 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
|
|
@@ -15,7 +15,7 @@ to its authors and contributors. This is not an official release of that project
|
|
|
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 ABI `0x5742000e`,
|
|
17
17
|
which upstream's tree-sitter runtimes reject, and is tested and supported with the WillBooster/tree-sitter runtime,
|
|
18
|
-
version
|
|
18
|
+
version 26.3.0 or later in the 26.x series. It parses as the parser in upstream's 1.1.2 packages does, with these
|
|
19
19
|
exceptions:
|
|
20
20
|
|
|
21
21
|
- A range outside slice brackets or a `for` operand is a syntax error. A sentinel also requires a range,
|
|
@@ -32,22 +32,23 @@ exceptions:
|
|
|
32
32
|
- `///` and `//!` produce `doc_comment` and `container_doc_comment` nodes. Their `doc_comment_content` children
|
|
33
33
|
exclude the prefix and include the line ending when present.
|
|
34
34
|
An empty comment at EOF has no content child. Ordinary comments, including `////`, remain `comment` nodes.
|
|
35
|
-
|
|
36
|
-
also appear inside expressions. Code that handles every comment kind must match all three node types.
|
|
35
|
+
Code that handles every comment kind must match all three node types.
|
|
37
36
|
|
|
38
37
|
- Error sets are accepted directly as container field types, and pointer, slice and array element types may be conditional.
|
|
39
38
|
- `async`, `await`, and `usingnamespace` are ordinary identifiers. Removed `usingnamespace` declarations produce syntax
|
|
40
39
|
errors. Assembly clobbers use an expression, including an anonymous struct
|
|
41
40
|
initializer, as in Zig 0.16.
|
|
42
41
|
- Zero-bit integers `u0` and `i0` are builtin types.
|
|
43
|
-
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
-
|
|
50
|
-
|
|
42
|
+
- Container declarations accept the `extern`, `packed`, or `bitpack` layout modifier, the last from Zig 0.18
|
|
43
|
+
development builds. `bitpack` is a keyword wherever an expression can start, so a variable or parameter named
|
|
44
|
+
`bitpack` must be written as the quoted identifier `@"bitpack"` there.
|
|
45
|
+
- Declaration modifiers (`pub`, `export`, `extern`, `threadlocal`, `inline`, `noinline`) and the `align`, `addrspace`,
|
|
46
|
+
`linksection`, and `callconv` attributes of declarations and function types are accepted in any order and
|
|
47
|
+
combination. Pointer alignment, including bit ranges such as `align(4:2:8)`, produces a `byte_alignment` node.
|
|
48
|
+
- `comptime` before a type is accepted only on parameters and container fields.
|
|
49
|
+
- Quoted identifiers such as `@"hello world"` are `identifier` nodes without children.
|
|
50
|
+
- Types are not grouped under `type_expression` or `primary_type_expression` supertypes; `expression` lists them
|
|
51
|
+
directly.
|
|
51
52
|
- `catch` groups to the left like `orelse`, so `a catch b catch c` and `a catch b orelse c` nest the leftmost
|
|
52
53
|
operation innermost.
|
|
53
54
|
- Boolean negation is a `unary_expression`. Inferred error unions (`!T`) occur only in function return types;
|
|
@@ -62,15 +63,17 @@ exceptions:
|
|
|
62
63
|
|
|
63
64
|
## Support Scope
|
|
64
65
|
|
|
65
|
-
This fork maintains only full parsing
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
This fork maintains only full parsing, optimized for binary size and parse speed: valid code as found in real-world
|
|
67
|
+
projects yields a correct tree, other valid code yields a correct tree or one with `ERROR` or `MISSING` nodes, and any
|
|
68
|
+
input parses without crashing, hanging, or taking more than linear time. Invalid input may parse without `ERROR` or
|
|
69
|
+
`MISSING` nodes. Incremental parsing is not supported, and no queries (highlights, locals, injections, tags) are
|
|
70
|
+
shipped. Node types, field names, and the trees that error recovery produces may change; such changes are released as
|
|
71
|
+
new major versions.
|
|
69
72
|
|
|
70
73
|
## Usage
|
|
71
74
|
|
|
72
75
|
The npm package ships `tree-sitter-zig.wasm` for
|
|
73
|
-
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version
|
|
76
|
+
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 26.3.0 or later in the 26.x series, which runs in Node.js, Bun, browsers, and Cloudflare Workers.
|
|
74
77
|
In Node.js and Bun, load the grammar from its path:
|
|
75
78
|
|
|
76
79
|
```js
|
|
@@ -118,7 +121,7 @@ In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-
|
|
|
118
121
|
fuzzed with:
|
|
119
122
|
|
|
120
123
|
```sh
|
|
121
|
-
cargo add willbooster-tree-sitter@
|
|
124
|
+
cargo add willbooster-tree-sitter@26.3.0 --rename tree-sitter
|
|
122
125
|
cargo add willbooster-tree-sitter-zig --rename tree-sitter-zig
|
|
123
126
|
```
|
|
124
127
|
|
|
@@ -141,7 +144,7 @@ cargo test --locked
|
|
|
141
144
|
|
|
142
145
|
Run tree-sitter CLI commands through `script/tree-sitter`, such as `script/tree-sitter parse file.zig`. It runs the `WillBooster/tree-sitter` CLI at the runtime version locked in `Cargo.lock`. `@willbooster/web-tree-sitter` in `package.json` and `willbooster-tree-sitter` in `Cargo.lock` must stay at the same version (`test/unit/runtimeVersion.test.ts`).
|
|
143
146
|
|
|
144
|
-
After changing `grammar.js
|
|
147
|
+
After changing `grammar.js` or `tree-sitter.json`, run `bun run build/ci` and commit `src/`. Run `script/tree-sitter test` after editing a corpus fixture. When a grammar change or a moved pin in `script/parse-examples` alters which real-world Zig files fail to parse, run `script/parse-examples` to update `script/known-failures.txt` and review its diff before committing.
|
|
145
148
|
|
|
146
149
|
### References
|
|
147
150
|
|