@willbooster/tree-sitter-zig 12.0.0 → 14.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 +7 -6
- package/grammar.js +5 -27
- package/package.json +9 -9
- package/src/scanner.c +15 -2
- package/tree-sitter-zig.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -13,9 +13,9 @@ Zig grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forke
|
|
|
13
13
|
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
|
-
[WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter) generator. The parser carries ABI `
|
|
16
|
+
[WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter) generator. The parser carries ABI `0x5742000d`,
|
|
17
17
|
which upstream's tree-sitter runtimes reject, and is tested and supported with the WillBooster/tree-sitter runtime,
|
|
18
|
-
version
|
|
18
|
+
version 23.0.0 or later in the 23.x series. It parses as the parser in upstream's 1.1.2 packages does, with these
|
|
19
19
|
exceptions:
|
|
20
20
|
|
|
21
21
|
- In the ranges a `for` loop iterates over, a range end whose first token can both start an expression and continue
|
|
@@ -23,8 +23,9 @@ exceptions:
|
|
|
23
23
|
`for (0..&x) |i| {}`), is the right operand of a `range_expression`. Upstream's packaged parser, generated by
|
|
24
24
|
tree-sitter CLI 0.24, lets that token continue the expression instead, on a range without an end: a call, an index,
|
|
25
25
|
a field access, a binary expression, and so on. tree-sitter CLI 0.27 generates this fork's reading from the same
|
|
26
|
-
grammar.
|
|
27
|
-
|
|
26
|
+
grammar. This generator difference applies only to those `for`-loop range ends.
|
|
27
|
+
- Labeled blocks used as indices or slice bounds retain their `block_label` inside the expression,
|
|
28
|
+
instead of splitting the label colon into an index and a sentinel.
|
|
28
29
|
- A NUL character inside a token such as a string or a comment is part of that token, where upstream's lexer reports
|
|
29
30
|
an error.
|
|
30
31
|
- Multiline strings expose each `\\` line delimiter and nonempty `string_content` children. Line endings are outside
|
|
@@ -61,7 +62,7 @@ may change; such changes are released as new major versions.
|
|
|
61
62
|
## Usage
|
|
62
63
|
|
|
63
64
|
The npm package ships `tree-sitter-zig.wasm` for
|
|
64
|
-
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version
|
|
65
|
+
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 23.0.0 or later in the 23.x series, which runs in Node.js, Bun, browsers, and Cloudflare Workers.
|
|
65
66
|
In Node.js and Bun, load the grammar from its path:
|
|
66
67
|
|
|
67
68
|
```js
|
|
@@ -109,7 +110,7 @@ In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-
|
|
|
109
110
|
fuzzed with:
|
|
110
111
|
|
|
111
112
|
```sh
|
|
112
|
-
cargo add willbooster-tree-sitter@
|
|
113
|
+
cargo add willbooster-tree-sitter@23.0.0 --rename tree-sitter
|
|
113
114
|
cargo add willbooster-tree-sitter-zig --rename tree-sitter-zig
|
|
114
115
|
```
|
|
115
116
|
|
package/grammar.js
CHANGED
|
@@ -54,9 +54,10 @@ const builtinTypes = [
|
|
|
54
54
|
module.exports = grammar({
|
|
55
55
|
name: 'zig',
|
|
56
56
|
|
|
57
|
-
externals: $ => [$.doc_comment_content, $._empty_doc_comment_content, $._error_sentinel],
|
|
57
|
+
externals: $ => [$.doc_comment_content, $._empty_doc_comment_content, $._error_sentinel, $._declaration_name_colon],
|
|
58
58
|
|
|
59
59
|
conflicts: $ => [
|
|
60
|
+
[$.block_label, $.primary_type_expression],
|
|
60
61
|
[$.for_expression],
|
|
61
62
|
[$.while_expression],
|
|
62
63
|
|
|
@@ -128,7 +129,7 @@ module.exports = grammar({
|
|
|
128
129
|
choice(
|
|
129
130
|
seq(
|
|
130
131
|
field('name', choice($.identifier, $._reserved_identifier, alias($.builtin_type, $.identifier))),
|
|
131
|
-
':',
|
|
132
|
+
alias($._declaration_name_colon, ':'),
|
|
132
133
|
field('type', choice($.primary_type_expression, $.if_type_expression, $.comptime_type_expression, $.error_set_declaration)),
|
|
133
134
|
),
|
|
134
135
|
field('name', choice($.primary_type_expression, $.if_type_expression, $.comptime_type_expression, $.error_set_declaration)),
|
|
@@ -226,7 +227,7 @@ module.exports = grammar({
|
|
|
226
227
|
optional(choice('noalias', 'comptime')),
|
|
227
228
|
optional(seq(
|
|
228
229
|
field('name', choice($.identifier, alias($.builtin_type, $.identifier))),
|
|
229
|
-
':',
|
|
230
|
+
alias($._declaration_name_colon, ':'),
|
|
230
231
|
)),
|
|
231
232
|
field('type', choice($.type_expression, $.if_type_expression, $.comptime_type_expression)),
|
|
232
233
|
),
|
|
@@ -772,7 +773,7 @@ module.exports = grammar({
|
|
|
772
773
|
|
|
773
774
|
parenthesized_expression: $ => seq('(', $.expression, ')'),
|
|
774
775
|
|
|
775
|
-
block_label: $ => prec(
|
|
776
|
+
block_label: $ => prec.dynamic(1, seq(
|
|
776
777
|
choice($.identifier, alias($.builtin_type, $.identifier)),
|
|
777
778
|
':',
|
|
778
779
|
)),
|
|
@@ -882,37 +883,14 @@ module.exports = grammar({
|
|
|
882
883
|
},
|
|
883
884
|
});
|
|
884
885
|
|
|
885
|
-
/**
|
|
886
|
-
* Creates a rule to match optionally match one or more of the rules
|
|
887
|
-
* separated by a comma and optionally ending with a comma
|
|
888
|
-
*
|
|
889
|
-
* @param {RuleOrLiteral} rule
|
|
890
|
-
*
|
|
891
|
-
* @returns {ChoiceRule}
|
|
892
|
-
*/
|
|
893
886
|
function optionalCommaSep(rule) {
|
|
894
887
|
return optional(optionalCommaSep1(rule));
|
|
895
888
|
}
|
|
896
889
|
|
|
897
|
-
/**
|
|
898
|
-
* Creates a rule to match one or more of the rules separated by a comma
|
|
899
|
-
* and optionally ending with a comma
|
|
900
|
-
*
|
|
901
|
-
* @param {RuleOrLiteral} rule
|
|
902
|
-
*
|
|
903
|
-
* @returns {SeqRule}
|
|
904
|
-
*/
|
|
905
890
|
function optionalCommaSep1(rule) {
|
|
906
891
|
return seq(commaSep1(rule), optional(','));
|
|
907
892
|
}
|
|
908
893
|
|
|
909
|
-
/**
|
|
910
|
-
* Creates a rule to match one or more of the rules separated by a comma
|
|
911
|
-
*
|
|
912
|
-
* @param {RuleOrLiteral} rule
|
|
913
|
-
*
|
|
914
|
-
* @returns {SeqRule}
|
|
915
|
-
*/
|
|
916
894
|
function commaSep1(rule) {
|
|
917
895
|
return seq(rule, repeat(seq(',', rule)));
|
|
918
896
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-zig",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"description": "Zig grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"parsing",
|
|
@@ -46,21 +46,21 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@tsconfig/bun": "1.0.11",
|
|
48
48
|
"@types/bun": "1.4.4",
|
|
49
|
-
"@vitest/browser-playwright": "5.0
|
|
49
|
+
"@vitest/browser-playwright": "5.1.0",
|
|
50
50
|
"@willbooster/oxlint-config": "1.4.9",
|
|
51
|
-
"@willbooster/wb": "23.3.
|
|
52
|
-
"@willbooster/web-tree-sitter": "
|
|
51
|
+
"@willbooster/wb": "23.3.4",
|
|
52
|
+
"@willbooster/web-tree-sitter": "23.0.0",
|
|
53
53
|
"conventional-changelog-conventionalcommits": "10.4.1",
|
|
54
54
|
"lefthook": "2.2.2",
|
|
55
|
-
"oxlint": "1.
|
|
56
|
-
"oxlint-tsgolint": "7.0.
|
|
57
|
-
"playwright": "1.
|
|
55
|
+
"oxlint": "1.92.0",
|
|
56
|
+
"oxlint-tsgolint": "7.0.2006",
|
|
57
|
+
"playwright": "1.65.0",
|
|
58
58
|
"semantic-release": "25.0.9",
|
|
59
|
-
"vitest": "5.0
|
|
59
|
+
"vitest": "5.1.0",
|
|
60
60
|
"wrangler": "4.156.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@willbooster/web-tree-sitter": "^
|
|
63
|
+
"@willbooster/web-tree-sitter": "^23.0.0"
|
|
64
64
|
},
|
|
65
65
|
"peerDependenciesMeta": {
|
|
66
66
|
"@willbooster/web-tree-sitter": {
|
package/src/scanner.c
CHANGED
|
@@ -4,6 +4,7 @@ enum TokenType {
|
|
|
4
4
|
DOC_COMMENT_CONTENT,
|
|
5
5
|
EMPTY_DOC_COMMENT_CONTENT,
|
|
6
6
|
ERROR_SENTINEL,
|
|
7
|
+
DECLARATION_NAME_COLON,
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
void *tree_sitter_zig_external_scanner_create(void) { return NULL; }
|
|
@@ -24,10 +25,22 @@ void tree_sitter_zig_external_scanner_deserialize(void *payload, const char *buf
|
|
|
24
25
|
|
|
25
26
|
static inline bool at_eof(const TSLexer *lexer) { return lexer->lookahead == 0 && lexer->eof(lexer); }
|
|
26
27
|
|
|
28
|
+
static bool scan_declaration_name_colon(TSLexer *lexer) {
|
|
29
|
+
while (lexer->lookahead == ' ' || lexer->lookahead == '\t' || lexer->lookahead == '\n' ||
|
|
30
|
+
lexer->lookahead == '\r' || lexer->lookahead == '\f') {
|
|
31
|
+
lexer->advance(lexer, true);
|
|
32
|
+
}
|
|
33
|
+
if (lexer->lookahead != ':') return false;
|
|
34
|
+
lexer->advance(lexer, false);
|
|
35
|
+
lexer->result_symbol = DECLARATION_NAME_COLON;
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
27
39
|
bool tree_sitter_zig_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
|
|
28
40
|
(void)payload;
|
|
29
|
-
if (valid_symbols[ERROR_SENTINEL]
|
|
30
|
-
|
|
41
|
+
if (valid_symbols[ERROR_SENTINEL]) return false;
|
|
42
|
+
if (valid_symbols[DECLARATION_NAME_COLON]) return scan_declaration_name_colon(lexer);
|
|
43
|
+
if (!valid_symbols[DOC_COMMENT_CONTENT] && !valid_symbols[EMPTY_DOC_COMMENT_CONTENT]) {
|
|
31
44
|
return false;
|
|
32
45
|
}
|
|
33
46
|
if (at_eof(lexer)) {
|
package/tree-sitter-zig.wasm
CHANGED
|
Binary file
|