@willbooster/tree-sitter-zig 5.0.1 → 6.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 -0
- package/grammar.js +16 -2
- package/package.json +2 -1
- package/queries/highlights.scm +6 -2
- package/queries/indents.scm +2 -0
- package/queries/injections.scm +3 -7
- package/src/node-types.json +59 -1
- package/src/scanner.c +41 -0
- package/tree-sitter-zig.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,12 @@ rejects it. It parses as the parser in upstream's 1.1.2 packages does, with thes
|
|
|
26
26
|
`~x`) or only continue one (`+`, `orelse`), and so do ranges outside `for` loops.
|
|
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
|
+
- Multiline strings expose each `\\` line delimiter and nonempty `string_content` children. The delimiters receive
|
|
30
|
+
the `@string.special.symbol` highlight capture. Line endings are outside the content nodes.
|
|
31
|
+
- `///` and `//!` produce `doc_comment` and `container_doc_comment` nodes. Their `doc_comment_content` children
|
|
32
|
+
exclude the prefix and include the line ending when present, so the injection query can combine them as Markdown.
|
|
33
|
+
An empty comment at EOF has no content child. Ordinary comments, including `////`, remain `comment` nodes.
|
|
34
|
+
Queries that need every comment kind must match all three node types.
|
|
29
35
|
|
|
30
36
|
- Error sets are accepted directly as container field types, and pointer and slice element types may be conditional.
|
|
31
37
|
- `async` and `await` are ordinary identifiers. Assembly clobbers use an expression, including an anonymous struct
|
|
@@ -85,6 +91,7 @@ parser.setLanguage(await Language.load(zig));
|
|
|
85
91
|
```
|
|
86
92
|
|
|
87
93
|
The package also ships `grammar.js`, the queries in `queries/`, and the node types in `src/node-types.json`.
|
|
94
|
+
It includes `src/scanner.c`, which must be compiled with a parser regenerated from this grammar.
|
|
88
95
|
|
|
89
96
|
In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-zig) and on
|
|
90
97
|
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
|
package/grammar.js
CHANGED
|
@@ -54,6 +54,8 @@ const builtinTypes = [
|
|
|
54
54
|
module.exports = grammar({
|
|
55
55
|
name: 'zig',
|
|
56
56
|
|
|
57
|
+
externals: $ => [$.doc_comment_content, $._empty_doc_comment_content, $._error_sentinel],
|
|
58
|
+
|
|
57
59
|
conflicts: $ => [
|
|
58
60
|
[$.for_expression],
|
|
59
61
|
[$.while_expression],
|
|
@@ -67,6 +69,8 @@ module.exports = grammar({
|
|
|
67
69
|
|
|
68
70
|
extras: $ => [
|
|
69
71
|
$.comment,
|
|
72
|
+
$.doc_comment,
|
|
73
|
+
$.container_doc_comment,
|
|
70
74
|
/\s/,
|
|
71
75
|
],
|
|
72
76
|
|
|
@@ -798,7 +802,10 @@ module.exports = grammar({
|
|
|
798
802
|
'"',
|
|
799
803
|
),
|
|
800
804
|
|
|
801
|
-
multiline_string:
|
|
805
|
+
multiline_string: $ => prec.right(repeat1(seq(
|
|
806
|
+
'\\\\',
|
|
807
|
+
optional(alias(token.immediate(prec(1, /[^\r\n]+/)), $.string_content)),
|
|
808
|
+
))),
|
|
802
809
|
|
|
803
810
|
escape_sequence: _ => token(prec(1, seq(
|
|
804
811
|
'\\',
|
|
@@ -870,7 +877,14 @@ module.exports = grammar({
|
|
|
870
877
|
'false',
|
|
871
878
|
),
|
|
872
879
|
|
|
873
|
-
|
|
880
|
+
doc_comment: $ => seq('///', choice($.doc_comment_content, $._empty_doc_comment_content)),
|
|
881
|
+
|
|
882
|
+
container_doc_comment: $ => seq('//!', choice($.doc_comment_content, $._empty_doc_comment_content)),
|
|
883
|
+
|
|
884
|
+
comment: _ => token(seq('//', optional(choice(
|
|
885
|
+
seq(/[^!/\n]/, /.*/),
|
|
886
|
+
seq('//', /.*/),
|
|
887
|
+
)))),
|
|
874
888
|
},
|
|
875
889
|
});
|
|
876
890
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-zig",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Zig grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"grammar.js",
|
|
19
19
|
"queries/*.scm",
|
|
20
20
|
"src/node-types.json",
|
|
21
|
+
"src/scanner.c",
|
|
21
22
|
"tree-sitter.json",
|
|
22
23
|
"*.wasm"
|
|
23
24
|
],
|
package/queries/highlights.scm
CHANGED
|
@@ -256,6 +256,8 @@
|
|
|
256
256
|
|
|
257
257
|
(escape_sequence) @string.escape
|
|
258
258
|
|
|
259
|
+
"\\\\" @string.special.symbol
|
|
260
|
+
|
|
259
261
|
; Punctuation
|
|
260
262
|
|
|
261
263
|
[
|
|
@@ -282,5 +284,7 @@
|
|
|
282
284
|
|
|
283
285
|
(comment) @comment @spell
|
|
284
286
|
|
|
285
|
-
|
|
286
|
-
(
|
|
287
|
+
[
|
|
288
|
+
(doc_comment)
|
|
289
|
+
(container_doc_comment)
|
|
290
|
+
] @comment.documentation @spell
|
package/queries/indents.scm
CHANGED
package/queries/injections.scm
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
((comment) @injection.content
|
|
2
2
|
(#set! injection.language "comment"))
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
; (asm_input_item (string) @injection.content
|
|
8
|
-
; (#set! injection.language "asm"))
|
|
9
|
-
; (asm_clobbers (string) @injection.content
|
|
10
|
-
; (#set! injection.language "asm"))
|
|
4
|
+
((doc_comment_content) @injection.content
|
|
5
|
+
(#set! injection.language "markdown")
|
|
6
|
+
(#set! injection.combined))
|
package/src/node-types.json
CHANGED
|
@@ -1018,6 +1018,22 @@
|
|
|
1018
1018
|
]
|
|
1019
1019
|
}
|
|
1020
1020
|
},
|
|
1021
|
+
{
|
|
1022
|
+
"type": "container_doc_comment",
|
|
1023
|
+
"named": true,
|
|
1024
|
+
"extra": true,
|
|
1025
|
+
"fields": {},
|
|
1026
|
+
"children": {
|
|
1027
|
+
"multiple": false,
|
|
1028
|
+
"required": false,
|
|
1029
|
+
"types": [
|
|
1030
|
+
{
|
|
1031
|
+
"type": "doc_comment_content",
|
|
1032
|
+
"named": true
|
|
1033
|
+
}
|
|
1034
|
+
]
|
|
1035
|
+
}
|
|
1036
|
+
},
|
|
1021
1037
|
{
|
|
1022
1038
|
"type": "container_field",
|
|
1023
1039
|
"named": true,
|
|
@@ -1147,6 +1163,22 @@
|
|
|
1147
1163
|
]
|
|
1148
1164
|
}
|
|
1149
1165
|
},
|
|
1166
|
+
{
|
|
1167
|
+
"type": "doc_comment",
|
|
1168
|
+
"named": true,
|
|
1169
|
+
"extra": true,
|
|
1170
|
+
"fields": {},
|
|
1171
|
+
"children": {
|
|
1172
|
+
"multiple": false,
|
|
1173
|
+
"required": false,
|
|
1174
|
+
"types": [
|
|
1175
|
+
{
|
|
1176
|
+
"type": "doc_comment_content",
|
|
1177
|
+
"named": true
|
|
1178
|
+
}
|
|
1179
|
+
]
|
|
1180
|
+
}
|
|
1181
|
+
},
|
|
1150
1182
|
{
|
|
1151
1183
|
"type": "else_clause",
|
|
1152
1184
|
"named": true,
|
|
@@ -1827,7 +1859,17 @@
|
|
|
1827
1859
|
{
|
|
1828
1860
|
"type": "multiline_string",
|
|
1829
1861
|
"named": true,
|
|
1830
|
-
"fields": {}
|
|
1862
|
+
"fields": {},
|
|
1863
|
+
"children": {
|
|
1864
|
+
"multiple": true,
|
|
1865
|
+
"required": false,
|
|
1866
|
+
"types": [
|
|
1867
|
+
{
|
|
1868
|
+
"type": "string_content",
|
|
1869
|
+
"named": true
|
|
1870
|
+
}
|
|
1871
|
+
]
|
|
1872
|
+
}
|
|
1831
1873
|
},
|
|
1832
1874
|
{
|
|
1833
1875
|
"type": "nosuspend_expression",
|
|
@@ -2752,6 +2794,14 @@
|
|
|
2752
2794
|
"type": "/",
|
|
2753
2795
|
"named": false
|
|
2754
2796
|
},
|
|
2797
|
+
{
|
|
2798
|
+
"type": "//!",
|
|
2799
|
+
"named": false
|
|
2800
|
+
},
|
|
2801
|
+
{
|
|
2802
|
+
"type": "///",
|
|
2803
|
+
"named": false
|
|
2804
|
+
},
|
|
2755
2805
|
{
|
|
2756
2806
|
"type": "/=",
|
|
2757
2807
|
"named": false
|
|
@@ -2828,6 +2878,10 @@
|
|
|
2828
2878
|
"type": "[",
|
|
2829
2879
|
"named": false
|
|
2830
2880
|
},
|
|
2881
|
+
{
|
|
2882
|
+
"type": "\\\\",
|
|
2883
|
+
"named": false
|
|
2884
|
+
},
|
|
2831
2885
|
{
|
|
2832
2886
|
"type": "]",
|
|
2833
2887
|
"named": false
|
|
@@ -2969,6 +3023,10 @@
|
|
|
2969
3023
|
"type": "defer",
|
|
2970
3024
|
"named": false
|
|
2971
3025
|
},
|
|
3026
|
+
{
|
|
3027
|
+
"type": "doc_comment_content",
|
|
3028
|
+
"named": true
|
|
3029
|
+
},
|
|
2972
3030
|
{
|
|
2973
3031
|
"type": "else",
|
|
2974
3032
|
"named": false
|
package/src/scanner.c
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#include "tree_sitter/parser.h"
|
|
2
|
+
|
|
3
|
+
enum TokenType {
|
|
4
|
+
DOC_COMMENT_CONTENT,
|
|
5
|
+
EMPTY_DOC_COMMENT_CONTENT,
|
|
6
|
+
ERROR_SENTINEL,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
void *tree_sitter_zig_external_scanner_create(void) { return NULL; }
|
|
10
|
+
|
|
11
|
+
void tree_sitter_zig_external_scanner_destroy(void *payload) { (void)payload; }
|
|
12
|
+
|
|
13
|
+
unsigned tree_sitter_zig_external_scanner_serialize(void *payload, char *buffer) {
|
|
14
|
+
(void)payload;
|
|
15
|
+
(void)buffer;
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
void tree_sitter_zig_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {
|
|
20
|
+
(void)payload;
|
|
21
|
+
(void)buffer;
|
|
22
|
+
(void)length;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
bool tree_sitter_zig_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
|
|
26
|
+
(void)payload;
|
|
27
|
+
if (valid_symbols[ERROR_SENTINEL]) return false;
|
|
28
|
+
if (lexer->eof(lexer)) {
|
|
29
|
+
if (!valid_symbols[EMPTY_DOC_COMMENT_CONTENT]) return false;
|
|
30
|
+
lexer->result_symbol = EMPTY_DOC_COMMENT_CONTENT;
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (!valid_symbols[DOC_COMMENT_CONTENT]) return false;
|
|
34
|
+
do {
|
|
35
|
+
int32_t character = lexer->lookahead;
|
|
36
|
+
lexer->advance(lexer, false);
|
|
37
|
+
if (character == '\n') break;
|
|
38
|
+
} while (!lexer->eof(lexer));
|
|
39
|
+
lexer->result_symbol = DOC_COMMENT_CONTENT;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
package/tree-sitter-zig.wasm
CHANGED
|
Binary file
|