@willbooster/tree-sitter-zig 5.1.0 → 6.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 CHANGED
@@ -28,6 +28,10 @@ rejects it. It parses as the parser in upstream's 1.1.2 packages does, with thes
28
28
  an error.
29
29
  - Multiline strings expose each `\\` line delimiter and nonempty `string_content` children. The delimiters receive
30
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.
31
35
 
32
36
  - Error sets are accepted directly as container field types, and pointer and slice element types may be conditional.
33
37
  - `async` and `await` are ordinary identifiers. Assembly clobbers use an expression, including an anonymous struct
@@ -87,6 +91,7 @@ parser.setLanguage(await Language.load(zig));
87
91
  ```
88
92
 
89
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.
90
95
 
91
96
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-zig) and on
92
97
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
@@ -159,4 +164,4 @@ with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
159
164
 
160
165
  ### References
161
166
 
162
- - [Zig Grammar](https://github.com/ziglang/zig-spec/blob/master/grammar/grammar.peg)
167
+ - [Zig Grammar](https://ziglang.org/documentation/master/#Grammar)
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
 
@@ -873,7 +877,14 @@ module.exports = grammar({
873
877
  'false',
874
878
  ),
875
879
 
876
- comment: _ => token(seq('//', /.*/)),
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
+ )))),
877
888
  },
878
889
  });
879
890
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-zig",
3
- "version": "5.1.0",
3
+ "version": "6.0.1",
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
  ],
@@ -284,5 +284,7 @@
284
284
 
285
285
  (comment) @comment @spell
286
286
 
287
- ((comment) @comment.documentation
288
- (#match? @comment.documentation "^//!"))
287
+ [
288
+ (doc_comment)
289
+ (container_doc_comment)
290
+ ] @comment.documentation @spell
@@ -18,5 +18,7 @@
18
18
 
19
19
  [
20
20
  (comment)
21
+ (doc_comment)
22
+ (container_doc_comment)
21
23
  (multiline_string)
22
24
  ] @indent.ignore
@@ -1,10 +1,6 @@
1
1
  ((comment) @injection.content
2
2
  (#set! injection.language "comment"))
3
3
 
4
- ; TODO: add when asm is added
5
- ; (asm_output_item (string) @injection.content
6
- ; (#set! injection.language "asm"))
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))
@@ -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,
@@ -2762,6 +2794,14 @@
2762
2794
  "type": "/",
2763
2795
  "named": false
2764
2796
  },
2797
+ {
2798
+ "type": "//!",
2799
+ "named": false
2800
+ },
2801
+ {
2802
+ "type": "///",
2803
+ "named": false
2804
+ },
2765
2805
  {
2766
2806
  "type": "/=",
2767
2807
  "named": false
@@ -2983,6 +3023,10 @@
2983
3023
  "type": "defer",
2984
3024
  "named": false
2985
3025
  },
3026
+ {
3027
+ "type": "doc_comment_content",
3028
+ "named": true
3029
+ },
2986
3030
  {
2987
3031
  "type": "else",
2988
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
+ }
Binary file
package/tree-sitter.json CHANGED
@@ -15,7 +15,7 @@
15
15
  }
16
16
  ],
17
17
  "metadata": {
18
- "version": "5.1.0",
18
+ "version": "6.0.1",
19
19
  "license": "MIT",
20
20
  "description": "Zig grammar for tree-sitter",
21
21
  "authors": [