@willbooster/tree-sitter-zig 17.0.0 → 19.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 +10 -1
- package/grammar.js +172 -112
- package/package.json +1 -1
- package/src/node-types.json +238 -22
- package/src/scanner.c +121 -11
- package/tree-sitter-zig.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -32,15 +32,24 @@ 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
|
-
|
|
35
|
+
Declaration documentation starts on its own line in member, parameter, and error-set lists. Ordinary comments can
|
|
36
|
+
also appear inside expressions. Code that handles every comment kind must match all three node types.
|
|
36
37
|
|
|
37
38
|
- Error sets are accepted directly as container field types, and pointer, slice and array element types may be conditional.
|
|
38
39
|
- `async`, `await`, and `usingnamespace` are ordinary identifiers. Removed `usingnamespace` declarations produce syntax
|
|
39
40
|
errors. Assembly clobbers use an expression, including an anonymous struct
|
|
40
41
|
initializer, as in Zig 0.16.
|
|
41
42
|
- Zero-bit integers `u0` and `i0` are builtin types.
|
|
43
|
+
- Structs and unions accept `packed`, `extern`, or the `bitpack` layout modifier from Zig 0.18 development builds.
|
|
44
|
+
Packed and bitpack containers accept an optional parenthesized backing type and one contiguous group of named fields
|
|
45
|
+
without `comptime` or alignment overrides. Packed and bitpack structs accept field defaults. This grammar uses
|
|
46
|
+
the Zig 0.18 keyword set. Use quoted identifiers such as `@"bitpack"` for names that match keywords. An unmodified
|
|
47
|
+
union accepts a parenthesized tag. Enums accept an optional backing type. Enums and opaque declarations have no
|
|
48
|
+
layout modifier, and opaque declarations have no backing type.
|
|
42
49
|
- Quoted identifiers such as `@"hello world"` expose their content directly inside `identifier`, without a nested
|
|
43
50
|
`string` node.
|
|
51
|
+
- `catch` groups to the left like `orelse`, so `a catch b catch c` and `a catch b orelse c` nest the leftmost
|
|
52
|
+
operation innermost.
|
|
44
53
|
- Boolean negation is a `unary_expression`. Inferred error unions (`!T`) occur only in function return types;
|
|
45
54
|
their payload includes suffixes such as calls and field access (`!List(T)` or `!ns.Result`). Explicit error
|
|
46
55
|
unions (`E!T`) retain their error and payload types.
|
package/grammar.js
CHANGED
|
@@ -33,7 +33,6 @@ const builtinTypes = [
|
|
|
33
33
|
'type',
|
|
34
34
|
'anyerror',
|
|
35
35
|
'anyopaque',
|
|
36
|
-
'anytype',
|
|
37
36
|
'noreturn',
|
|
38
37
|
'isize',
|
|
39
38
|
'usize',
|
|
@@ -54,7 +53,18 @@ const builtinTypes = [
|
|
|
54
53
|
module.exports = grammar({
|
|
55
54
|
name: 'zig',
|
|
56
55
|
|
|
57
|
-
externals: $ => [
|
|
56
|
+
externals: $ => [
|
|
57
|
+
$.doc_comment_content,
|
|
58
|
+
$._empty_doc_comment_content,
|
|
59
|
+
$._error_sentinel,
|
|
60
|
+
$._declaration_name_colon,
|
|
61
|
+
$._union_backing_open,
|
|
62
|
+
$.comment,
|
|
63
|
+
$._string_content_guard,
|
|
64
|
+
$._division,
|
|
65
|
+
$._division_assignment,
|
|
66
|
+
$._declaration_doc_open,
|
|
67
|
+
],
|
|
58
68
|
|
|
59
69
|
conflicts: $ => [
|
|
60
70
|
[$.block_label, $.primary_type_expression],
|
|
@@ -62,17 +72,11 @@ module.exports = grammar({
|
|
|
62
72
|
[$.for_expression],
|
|
63
73
|
[$.while_expression],
|
|
64
74
|
|
|
65
|
-
[$.expression, $._function_prototype],
|
|
66
|
-
[$.expression, $.if_type_expression],
|
|
67
|
-
|
|
68
|
-
[$.comptime_type_expression, $.expression],
|
|
69
75
|
[$.comptime_type_expression, $.parameter],
|
|
70
76
|
],
|
|
71
77
|
|
|
72
78
|
extras: $ => [
|
|
73
79
|
$.comment,
|
|
74
|
-
$.doc_comment,
|
|
75
|
-
$.container_doc_comment,
|
|
76
80
|
/\s/,
|
|
77
81
|
],
|
|
78
82
|
|
|
@@ -82,6 +86,7 @@ module.exports = grammar({
|
|
|
82
86
|
|
|
83
87
|
precedences: $ => [
|
|
84
88
|
[$.container_field, $.type_expression],
|
|
89
|
+
[$.container_field, $.comptime_type_expression],
|
|
85
90
|
[$._variable_declaration_expression_statement, $.assignment_expression],
|
|
86
91
|
[$._variable_declaration_expression_statement, $._single_assignment_expression],
|
|
87
92
|
],
|
|
@@ -95,22 +100,27 @@ module.exports = grammar({
|
|
|
95
100
|
|
|
96
101
|
word: $ => $._identifier,
|
|
97
102
|
|
|
103
|
+
reserved: {
|
|
104
|
+
global: _ => [
|
|
105
|
+
'addrspace', 'align', 'allowzero', 'and', 'anyframe', 'anytype',
|
|
106
|
+
'asm', 'bitpack', 'break', 'callconv', 'catch', 'comptime',
|
|
107
|
+
'const', 'continue', 'defer', 'else', 'enum', 'errdefer',
|
|
108
|
+
'error', 'export', 'extern', 'fn', 'for', 'if',
|
|
109
|
+
'inline', 'linksection', 'noalias', 'noinline', 'nosuspend', 'opaque',
|
|
110
|
+
'or', 'orelse', 'packed', 'pub', 'resume', 'return',
|
|
111
|
+
'struct', 'suspend', 'switch', 'test', 'threadlocal', 'try',
|
|
112
|
+
'union', 'unreachable', 'var', 'volatile', 'while',
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
|
|
98
116
|
rules: {
|
|
99
|
-
source_file: $ => optional($._container_members),
|
|
117
|
+
source_file: $ => seq(repeat($.container_doc_comment), optional(choice($._container_members, repeat1($.doc_comment)))),
|
|
100
118
|
|
|
101
|
-
_container_members: $ =>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
$.variable_declaration,
|
|
107
|
-
$.function_declaration,
|
|
108
|
-
seq($.container_field, ','),
|
|
109
|
-
)),
|
|
110
|
-
optional($.container_field),
|
|
111
|
-
),
|
|
112
|
-
$.container_field,
|
|
113
|
-
),
|
|
119
|
+
_container_members: $ => containerMembers($, $.container_field),
|
|
120
|
+
|
|
121
|
+
_packed_struct_members: $ => packedContainerMembers($, alias($._packed_struct_field, $.container_field)),
|
|
122
|
+
|
|
123
|
+
_packed_union_members: $ => packedContainerMembers($, alias($._packed_union_field, $.container_field)),
|
|
114
124
|
|
|
115
125
|
test_declaration: $ => seq(
|
|
116
126
|
optional('pub'),
|
|
@@ -127,18 +137,15 @@ module.exports = grammar({
|
|
|
127
137
|
|
|
128
138
|
container_field: $ => prec.right(prec.dynamic(1, seq(
|
|
129
139
|
optional('comptime'),
|
|
130
|
-
choice(
|
|
131
|
-
seq(
|
|
132
|
-
field('name', choice($.identifier, $._reserved_identifier, alias($.builtin_type, $.identifier))),
|
|
133
|
-
alias($._declaration_name_colon, ':'),
|
|
134
|
-
field('type', choice($.primary_type_expression, $.if_type_expression, $.comptime_type_expression, $.error_set_declaration)),
|
|
135
|
-
),
|
|
136
|
-
field('name', choice($.primary_type_expression, $.if_type_expression, $.comptime_type_expression, $.error_set_declaration)),
|
|
137
|
-
),
|
|
140
|
+
choice(namedContainerField($), field('name', typeExpression($))),
|
|
138
141
|
optional($.byte_alignment),
|
|
139
142
|
optional(seq('=', $.expression)),
|
|
140
143
|
))),
|
|
141
144
|
|
|
145
|
+
_packed_struct_field: $ => packedField($, optional(seq('=', $.expression))),
|
|
146
|
+
|
|
147
|
+
_packed_union_field: $ => packedField($),
|
|
148
|
+
|
|
142
149
|
variable_declaration: $ => seq(
|
|
143
150
|
optional('pub'),
|
|
144
151
|
optional(choice(
|
|
@@ -181,7 +188,7 @@ module.exports = grammar({
|
|
|
181
188
|
$.identifier,
|
|
182
189
|
optional(seq(
|
|
183
190
|
':',
|
|
184
|
-
field('type',
|
|
191
|
+
field('type', typeExpression($)),
|
|
185
192
|
)),
|
|
186
193
|
optional($.byte_alignment),
|
|
187
194
|
optional($.address_space),
|
|
@@ -212,25 +219,24 @@ module.exports = grammar({
|
|
|
212
219
|
optional($.link_section),
|
|
213
220
|
optional($.calling_convention),
|
|
214
221
|
field('type', choice(
|
|
215
|
-
|
|
216
|
-
$.if_type_expression,
|
|
217
|
-
$.comptime_type_expression,
|
|
222
|
+
typeExpression($),
|
|
218
223
|
alias($._inferred_error_union_type, $.error_union_type),
|
|
219
224
|
)),
|
|
220
225
|
),
|
|
221
226
|
|
|
222
|
-
_inferred_error_union_type: $ => prec.right(-1, seq('!', field('ok',
|
|
227
|
+
_inferred_error_union_type: $ => prec.right(-1, seq('!', field('ok', typeExpression($)))),
|
|
223
228
|
|
|
224
229
|
parameters: $ => seq('(', optionalCommaSep($.parameter), ')'),
|
|
225
230
|
|
|
226
231
|
parameter: $ => choice(
|
|
227
232
|
seq(
|
|
233
|
+
repeat($.doc_comment),
|
|
228
234
|
optional(choice('noalias', 'comptime')),
|
|
229
235
|
optional(seq(
|
|
230
236
|
field('name', choice($.identifier, alias(choice($.builtin_type, $._reserved_identifier), $.identifier))),
|
|
231
237
|
alias($._declaration_name_colon, ':'),
|
|
232
238
|
)),
|
|
233
|
-
field('type', choice(
|
|
239
|
+
field('type', choice(alias('anytype', $.builtin_type), typeExpression($))),
|
|
234
240
|
),
|
|
235
241
|
'...',
|
|
236
242
|
),
|
|
@@ -241,52 +247,46 @@ module.exports = grammar({
|
|
|
241
247
|
'}',
|
|
242
248
|
),
|
|
243
249
|
|
|
244
|
-
|
|
245
|
-
optional(choice('extern', 'packed')),
|
|
246
|
-
'struct',
|
|
247
|
-
optional(seq('(', $.expression, ')')),
|
|
248
|
-
'{',
|
|
249
|
-
optional($._container_members),
|
|
250
|
-
'}',
|
|
251
|
-
),
|
|
250
|
+
_packed_layout: _ => choice('packed', 'bitpack'),
|
|
252
251
|
|
|
253
|
-
|
|
254
|
-
optional(
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
252
|
+
struct_declaration: $ => choice(
|
|
253
|
+
containerBody($, seq($._packed_layout, 'struct', optional(seq('(', $.expression, ')'))), $._packed_struct_members),
|
|
254
|
+
containerBody(
|
|
255
|
+
$,
|
|
256
|
+
seq(optional('extern'), 'struct'),
|
|
257
|
+
$._container_members,
|
|
258
|
+
),
|
|
259
259
|
),
|
|
260
260
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
'
|
|
266
|
-
|
|
267
|
-
'}',
|
|
261
|
+
opaque_declaration: $ => containerBody($, 'opaque', $._container_members),
|
|
262
|
+
|
|
263
|
+
enum_declaration: $ => containerBody(
|
|
264
|
+
$,
|
|
265
|
+
seq('enum', optional(seq('(', $.expression, ')'))),
|
|
266
|
+
$._container_members,
|
|
268
267
|
),
|
|
269
268
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
269
|
+
_union_backing: $ => seq(alias($._union_backing_open, '('), $.expression, ')'),
|
|
270
|
+
|
|
271
|
+
union_declaration: $ => choice(
|
|
272
|
+
containerBody($, seq($._packed_layout, 'union', optional($._union_backing)), $._packed_union_members),
|
|
273
|
+
containerBody(
|
|
274
|
+
$,
|
|
275
275
|
choice(
|
|
276
|
-
seq('
|
|
277
|
-
|
|
276
|
+
seq('extern', 'union'),
|
|
277
|
+
seq('union', optional(choice(
|
|
278
|
+
$._union_backing,
|
|
279
|
+
seq('(', 'enum', optional(seq('(', $.expression, ')')), ')'),
|
|
280
|
+
))),
|
|
278
281
|
),
|
|
279
|
-
|
|
280
|
-
)
|
|
281
|
-
'{',
|
|
282
|
-
optional($._container_members),
|
|
283
|
-
'}',
|
|
282
|
+
$._container_members,
|
|
283
|
+
),
|
|
284
284
|
),
|
|
285
285
|
|
|
286
286
|
error_set_declaration: $ => seq(
|
|
287
287
|
'error',
|
|
288
288
|
'{',
|
|
289
|
-
optionalCommaSep($.identifier),
|
|
289
|
+
optionalCommaSep(seq(repeat($.doc_comment), $.identifier)),
|
|
290
290
|
'}',
|
|
291
291
|
),
|
|
292
292
|
|
|
@@ -419,6 +419,7 @@ module.exports = grammar({
|
|
|
419
419
|
$.break_expression,
|
|
420
420
|
$.try_expression,
|
|
421
421
|
$.catch_expression,
|
|
422
|
+
$.struct_initializer,
|
|
422
423
|
$.type_expression,
|
|
423
424
|
$.block,
|
|
424
425
|
)),
|
|
@@ -438,7 +439,7 @@ module.exports = grammar({
|
|
|
438
439
|
']',
|
|
439
440
|
choice($.string, $.multiline_string),
|
|
440
441
|
'(',
|
|
441
|
-
choice(seq('->',
|
|
442
|
+
choice(seq('->', typeExpression($)), $.identifier),
|
|
442
443
|
')',
|
|
443
444
|
),
|
|
444
445
|
asm_input: $ => seq(':', optionalCommaSep($.asm_input_item), optional($.asm_clobbers)),
|
|
@@ -459,21 +460,16 @@ module.exports = grammar({
|
|
|
459
460
|
optional(seq('else', optional($.payload), $.expression)),
|
|
460
461
|
)),
|
|
461
462
|
|
|
462
|
-
for_expression: $ =>
|
|
463
|
-
optional($.block_label),
|
|
464
|
-
optional('inline'),
|
|
465
|
-
$._for_prefix,
|
|
466
|
-
$.expression,
|
|
467
|
-
optional(seq('else', $.expression)),
|
|
468
|
-
)),
|
|
463
|
+
for_expression: $ => loopExpression($, $._for_prefix, $.expression),
|
|
469
464
|
|
|
470
|
-
while_expression: $ =>
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
465
|
+
while_expression: $ => loopExpression($, $._while_prefix, $.expression, seq(optional($.payload), $.expression)),
|
|
466
|
+
|
|
467
|
+
_for_type_expression: $ => loopExpression($, $._for_prefix, typeExpression($)),
|
|
468
|
+
|
|
469
|
+
_while_type_expression: $ => {
|
|
470
|
+
const type = typeExpression($);
|
|
471
|
+
return loopExpression($, $._while_prefix, type, seq(optional($.payload), type));
|
|
472
|
+
},
|
|
477
473
|
|
|
478
474
|
assignment_expression: $ => choice(
|
|
479
475
|
$._single_assignment_expression,
|
|
@@ -491,8 +487,8 @@ module.exports = grammar({
|
|
|
491
487
|
field('right', $.expression),
|
|
492
488
|
),
|
|
493
489
|
|
|
494
|
-
_assignment_operator:
|
|
495
|
-
'=', '*=', '*%=', '*|=', '/=', '%=',
|
|
490
|
+
_assignment_operator: $ => choice(
|
|
491
|
+
'=', '*=', '*%=', '*|=', alias($._division_assignment, '/='), '%=',
|
|
496
492
|
'+=', '+%=', '+|=', '-=', '-%=', '-|=',
|
|
497
493
|
'<<=', '<<|=', '>>=', '&=', '^=', '|=',
|
|
498
494
|
),
|
|
@@ -527,7 +523,7 @@ module.exports = grammar({
|
|
|
527
523
|
['+|', PREC.ADD],
|
|
528
524
|
['-|', PREC.ADD],
|
|
529
525
|
['*', PREC.MULTIPLY],
|
|
530
|
-
['/', PREC.MULTIPLY],
|
|
526
|
+
[alias($._division, '/'), PREC.MULTIPLY],
|
|
531
527
|
['%', PREC.MULTIPLY],
|
|
532
528
|
['**', PREC.MULTIPLY],
|
|
533
529
|
['*%', PREC.MULTIPLY],
|
|
@@ -567,7 +563,7 @@ module.exports = grammar({
|
|
|
567
563
|
|
|
568
564
|
try_expression: $ => prec.left(PREC.UNARY, seq('try', $.expression)),
|
|
569
565
|
|
|
570
|
-
catch_expression: $ => prec.
|
|
566
|
+
catch_expression: $ => prec.left(PREC.BITWISE, seq(
|
|
571
567
|
$.expression,
|
|
572
568
|
'catch',
|
|
573
569
|
optional($.payload),
|
|
@@ -598,7 +594,6 @@ module.exports = grammar({
|
|
|
598
594
|
|
|
599
595
|
type_expression: $ => prec.right(choice(
|
|
600
596
|
$.anonymous_struct_initializer,
|
|
601
|
-
$.struct_initializer,
|
|
602
597
|
$.labeled_type_expression,
|
|
603
598
|
$.error_set_declaration,
|
|
604
599
|
$.parenthesized_expression,
|
|
@@ -641,13 +636,13 @@ module.exports = grammar({
|
|
|
641
636
|
|
|
642
637
|
nullable_type: $ => prec(1, seq(
|
|
643
638
|
'?',
|
|
644
|
-
|
|
639
|
+
typeExpression($),
|
|
645
640
|
)),
|
|
646
641
|
|
|
647
642
|
anyframe_type: $ => prec(1, seq(
|
|
648
643
|
'anyframe',
|
|
649
644
|
'->',
|
|
650
|
-
|
|
645
|
+
typeExpression($),
|
|
651
646
|
)),
|
|
652
647
|
|
|
653
648
|
slice_type: $ => prec.right(1, seq(
|
|
@@ -664,7 +659,7 @@ module.exports = grammar({
|
|
|
664
659
|
'volatile',
|
|
665
660
|
'allowzero',
|
|
666
661
|
)),
|
|
667
|
-
|
|
662
|
+
typeExpression($),
|
|
668
663
|
)),
|
|
669
664
|
|
|
670
665
|
pointer_type: $ => prec.right(1, seq(
|
|
@@ -690,7 +685,7 @@ module.exports = grammar({
|
|
|
690
685
|
'volatile',
|
|
691
686
|
'allowzero',
|
|
692
687
|
)),
|
|
693
|
-
|
|
688
|
+
typeExpression($),
|
|
694
689
|
)),
|
|
695
690
|
|
|
696
691
|
array_type: $ => prec(1, seq(
|
|
@@ -698,23 +693,23 @@ module.exports = grammar({
|
|
|
698
693
|
$.expression,
|
|
699
694
|
optional(seq(':', $.expression)),
|
|
700
695
|
']',
|
|
701
|
-
|
|
696
|
+
typeExpression($),
|
|
702
697
|
)),
|
|
703
698
|
|
|
704
699
|
error_union_type: $ => prec.right(2, seq(
|
|
705
700
|
field('error', $.type_expression),
|
|
706
701
|
'!',
|
|
707
|
-
field('ok',
|
|
702
|
+
field('ok', typeExpression($)),
|
|
708
703
|
)),
|
|
709
704
|
|
|
710
705
|
field_expression: $ => prec(PREC.MEMBER, seq(
|
|
711
|
-
optional(field('object', $.
|
|
706
|
+
optional(field('object', $.type_expression)),
|
|
712
707
|
'.',
|
|
713
708
|
field('member', $.identifier),
|
|
714
709
|
)),
|
|
715
710
|
|
|
716
711
|
index_expression: $ => prec(PREC.MEMBER, seq(
|
|
717
|
-
field('object', $.
|
|
712
|
+
field('object', $.type_expression),
|
|
718
713
|
'[',
|
|
719
714
|
choice(
|
|
720
715
|
field('index', $.expression),
|
|
@@ -726,9 +721,9 @@ module.exports = grammar({
|
|
|
726
721
|
']',
|
|
727
722
|
)),
|
|
728
723
|
|
|
729
|
-
dereference_expression: $ => prec(PREC.MEMBER, seq($.
|
|
724
|
+
dereference_expression: $ => prec(PREC.MEMBER, seq($.type_expression, '.*')),
|
|
730
725
|
|
|
731
|
-
null_coercion_expression: $ => prec(PREC.MEMBER, seq($.
|
|
726
|
+
null_coercion_expression: $ => prec(PREC.MEMBER, seq($.type_expression, '.?')),
|
|
732
727
|
|
|
733
728
|
range_expression: $ => prec.right(PREC.MEMBER, seq(
|
|
734
729
|
field('left', $.expression),
|
|
@@ -737,7 +732,7 @@ module.exports = grammar({
|
|
|
737
732
|
)),
|
|
738
733
|
|
|
739
734
|
call_expression: $ => prec(PREC.MEMBER, seq(
|
|
740
|
-
field('function', $.
|
|
735
|
+
field('function', $.type_expression),
|
|
741
736
|
'(',
|
|
742
737
|
optionalCommaSep($.expression),
|
|
743
738
|
')',
|
|
@@ -745,7 +740,7 @@ module.exports = grammar({
|
|
|
745
740
|
|
|
746
741
|
anonymous_struct_initializer: $ => seq('.', $.initializer_list),
|
|
747
742
|
|
|
748
|
-
struct_initializer: $ => prec(-1, seq($.
|
|
743
|
+
struct_initializer: $ => prec(-1, seq($.type_expression, $.initializer_list)),
|
|
749
744
|
|
|
750
745
|
initializer_list: $ => seq(
|
|
751
746
|
'{',
|
|
@@ -765,12 +760,12 @@ module.exports = grammar({
|
|
|
765
760
|
|
|
766
761
|
labeled_type_expression: $ => seq($.block_label, $.block),
|
|
767
762
|
|
|
768
|
-
comptime_type_expression: $ => seq('comptime',
|
|
763
|
+
comptime_type_expression: $ => seq('comptime', typeExpression($)),
|
|
769
764
|
|
|
770
765
|
if_type_expression: $ => prec.right(seq(
|
|
771
766
|
$._if_prefix,
|
|
772
|
-
|
|
773
|
-
optional(seq('else', optional($.payload),
|
|
767
|
+
typeExpression($),
|
|
768
|
+
optional(seq('else', optional($.payload), typeExpression($))),
|
|
774
769
|
)),
|
|
775
770
|
|
|
776
771
|
parenthesized_expression: $ => seq('(', $.expression, ')'),
|
|
@@ -793,7 +788,7 @@ module.exports = grammar({
|
|
|
793
788
|
_string: $ => seq(
|
|
794
789
|
'"',
|
|
795
790
|
repeat(choice(
|
|
796
|
-
|
|
791
|
+
stringContent($, /[^\\"\n]+/),
|
|
797
792
|
$.escape_sequence,
|
|
798
793
|
)),
|
|
799
794
|
'"',
|
|
@@ -801,7 +796,7 @@ module.exports = grammar({
|
|
|
801
796
|
|
|
802
797
|
multiline_string: $ => prec.right(repeat1(seq(
|
|
803
798
|
'\\\\',
|
|
804
|
-
optional(
|
|
799
|
+
optional(stringContent($, /[^\r\n]+/)),
|
|
805
800
|
))),
|
|
806
801
|
|
|
807
802
|
escape_sequence: _ => token(prec(1, seq(
|
|
@@ -874,14 +869,10 @@ module.exports = grammar({
|
|
|
874
869
|
'false',
|
|
875
870
|
),
|
|
876
871
|
|
|
877
|
-
doc_comment: $ => seq('///', choice($.doc_comment_content, $._empty_doc_comment_content)),
|
|
872
|
+
doc_comment: $ => seq(alias($._declaration_doc_open, '///'), choice($.doc_comment_content, $._empty_doc_comment_content)),
|
|
878
873
|
|
|
879
874
|
container_doc_comment: $ => seq('//!', choice($.doc_comment_content, $._empty_doc_comment_content)),
|
|
880
875
|
|
|
881
|
-
comment: _ => token(seq('//', optional(choice(
|
|
882
|
-
seq(/[^!/\n]/, /.*/),
|
|
883
|
-
seq('//', /.*/),
|
|
884
|
-
)))),
|
|
885
876
|
},
|
|
886
877
|
});
|
|
887
878
|
|
|
@@ -896,3 +887,72 @@ function optionalCommaSep1(rule) {
|
|
|
896
887
|
function commaSep1(rule) {
|
|
897
888
|
return seq(rule, repeat(seq(',', rule)));
|
|
898
889
|
}
|
|
890
|
+
|
|
891
|
+
function containerMembers($, field) {
|
|
892
|
+
const member = seq(repeat($.doc_comment), field);
|
|
893
|
+
return choice(
|
|
894
|
+
seq(
|
|
895
|
+
repeat1(choice(containerDeclaration($), seq(member, ','))),
|
|
896
|
+
optional(member),
|
|
897
|
+
),
|
|
898
|
+
member,
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
function packedContainerMembers($, field) {
|
|
903
|
+
const member = seq(repeat($.doc_comment), field);
|
|
904
|
+
const declaration = containerDeclaration($);
|
|
905
|
+
return choice(
|
|
906
|
+
repeat1(declaration),
|
|
907
|
+
seq(repeat(declaration), commaSep1(member), optional(seq(',', repeat(declaration)))),
|
|
908
|
+
);
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
function containerDeclaration($) {
|
|
912
|
+
return choice(
|
|
913
|
+
$.test_declaration,
|
|
914
|
+
$.comptime_declaration,
|
|
915
|
+
seq(repeat($.doc_comment), choice($.variable_declaration, $.function_declaration)),
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
function containerBody($, header, members) {
|
|
920
|
+
return seq(header, '{', repeat($.container_doc_comment), optional(members), '}');
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
function packedField($, defaultValue = blank()) {
|
|
925
|
+
return prec.right(prec.dynamic(1, seq(namedContainerField($), defaultValue)));
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
function namedContainerField($) {
|
|
929
|
+
return seq(
|
|
930
|
+
field('name', choice($.identifier, alias(choice($.builtin_type, $._reserved_identifier), $.identifier))),
|
|
931
|
+
alias($._declaration_name_colon, ':'),
|
|
932
|
+
field('type', typeExpression($)),
|
|
933
|
+
);
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
function typeExpression($) {
|
|
937
|
+
return choice(
|
|
938
|
+
$.type_expression,
|
|
939
|
+
$.if_type_expression,
|
|
940
|
+
$.comptime_type_expression,
|
|
941
|
+
alias($._for_type_expression, $.for_expression),
|
|
942
|
+
alias($._while_type_expression, $.while_expression),
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
function loopExpression($, prefix, body, otherwise = body) {
|
|
947
|
+
return prec.right(seq(
|
|
948
|
+
optional($.block_label),
|
|
949
|
+
optional('inline'),
|
|
950
|
+
prefix,
|
|
951
|
+
body,
|
|
952
|
+
optional(seq('else', otherwise)),
|
|
953
|
+
));
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
function stringContent($, pattern) {
|
|
957
|
+
return alias(choice($._string_content_guard, token.immediate(prec(1, pattern))), $.string_content);
|
|
958
|
+
}
|
package/package.json
CHANGED
package/src/node-types.json
CHANGED
|
@@ -51,6 +51,10 @@
|
|
|
51
51
|
"type": "return_expression",
|
|
52
52
|
"named": true
|
|
53
53
|
},
|
|
54
|
+
{
|
|
55
|
+
"type": "struct_initializer",
|
|
56
|
+
"named": true
|
|
57
|
+
},
|
|
54
58
|
{
|
|
55
59
|
"type": "try_expression",
|
|
56
60
|
"named": true
|
|
@@ -276,10 +280,6 @@
|
|
|
276
280
|
{
|
|
277
281
|
"type": "primary_type_expression",
|
|
278
282
|
"named": true
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
"type": "struct_initializer",
|
|
282
|
-
"named": true
|
|
283
283
|
}
|
|
284
284
|
]
|
|
285
285
|
},
|
|
@@ -321,9 +321,25 @@
|
|
|
321
321
|
"multiple": false,
|
|
322
322
|
"required": true,
|
|
323
323
|
"types": [
|
|
324
|
+
{
|
|
325
|
+
"type": "comptime_type_expression",
|
|
326
|
+
"named": true
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
"type": "for_expression",
|
|
330
|
+
"named": true
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
"type": "if_type_expression",
|
|
334
|
+
"named": true
|
|
335
|
+
},
|
|
324
336
|
{
|
|
325
337
|
"type": "type_expression",
|
|
326
338
|
"named": true
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
"type": "while_expression",
|
|
342
|
+
"named": true
|
|
327
343
|
}
|
|
328
344
|
]
|
|
329
345
|
}
|
|
@@ -351,6 +367,10 @@
|
|
|
351
367
|
"multiple": true,
|
|
352
368
|
"required": true,
|
|
353
369
|
"types": [
|
|
370
|
+
{
|
|
371
|
+
"type": "comptime_type_expression",
|
|
372
|
+
"named": true
|
|
373
|
+
},
|
|
354
374
|
{
|
|
355
375
|
"type": "expression",
|
|
356
376
|
"named": true
|
|
@@ -469,10 +489,22 @@
|
|
|
469
489
|
"multiple": true,
|
|
470
490
|
"required": true,
|
|
471
491
|
"types": [
|
|
492
|
+
{
|
|
493
|
+
"type": "comptime_type_expression",
|
|
494
|
+
"named": true
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
"type": "for_expression",
|
|
498
|
+
"named": true
|
|
499
|
+
},
|
|
472
500
|
{
|
|
473
501
|
"type": "identifier",
|
|
474
502
|
"named": true
|
|
475
503
|
},
|
|
504
|
+
{
|
|
505
|
+
"type": "if_type_expression",
|
|
506
|
+
"named": true
|
|
507
|
+
},
|
|
476
508
|
{
|
|
477
509
|
"type": "multiline_string",
|
|
478
510
|
"named": true
|
|
@@ -484,6 +516,10 @@
|
|
|
484
516
|
{
|
|
485
517
|
"type": "type_expression",
|
|
486
518
|
"named": true
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
"type": "while_expression",
|
|
522
|
+
"named": true
|
|
487
523
|
}
|
|
488
524
|
]
|
|
489
525
|
}
|
|
@@ -876,7 +912,7 @@
|
|
|
876
912
|
"required": true,
|
|
877
913
|
"types": [
|
|
878
914
|
{
|
|
879
|
-
"type": "
|
|
915
|
+
"type": "type_expression",
|
|
880
916
|
"named": true
|
|
881
917
|
}
|
|
882
918
|
]
|
|
@@ -1011,9 +1047,25 @@
|
|
|
1011
1047
|
"multiple": false,
|
|
1012
1048
|
"required": true,
|
|
1013
1049
|
"types": [
|
|
1050
|
+
{
|
|
1051
|
+
"type": "comptime_type_expression",
|
|
1052
|
+
"named": true
|
|
1053
|
+
},
|
|
1054
|
+
{
|
|
1055
|
+
"type": "for_expression",
|
|
1056
|
+
"named": true
|
|
1057
|
+
},
|
|
1058
|
+
{
|
|
1059
|
+
"type": "if_type_expression",
|
|
1060
|
+
"named": true
|
|
1061
|
+
},
|
|
1014
1062
|
{
|
|
1015
1063
|
"type": "type_expression",
|
|
1016
1064
|
"named": true
|
|
1065
|
+
},
|
|
1066
|
+
{
|
|
1067
|
+
"type": "while_expression",
|
|
1068
|
+
"named": true
|
|
1017
1069
|
}
|
|
1018
1070
|
]
|
|
1019
1071
|
}
|
|
@@ -1021,7 +1073,6 @@
|
|
|
1021
1073
|
{
|
|
1022
1074
|
"type": "container_doc_comment",
|
|
1023
1075
|
"named": true,
|
|
1024
|
-
"extra": true,
|
|
1025
1076
|
"fields": {},
|
|
1026
1077
|
"children": {
|
|
1027
1078
|
"multiple": false,
|
|
@@ -1047,24 +1098,24 @@
|
|
|
1047
1098
|
"named": true
|
|
1048
1099
|
},
|
|
1049
1100
|
{
|
|
1050
|
-
"type": "
|
|
1101
|
+
"type": "for_expression",
|
|
1051
1102
|
"named": true
|
|
1052
1103
|
},
|
|
1053
1104
|
{
|
|
1054
|
-
"type": "
|
|
1055
|
-
"named":
|
|
1105
|
+
"type": "identifier",
|
|
1106
|
+
"named": true
|
|
1056
1107
|
},
|
|
1057
1108
|
{
|
|
1058
1109
|
"type": "if_type_expression",
|
|
1059
1110
|
"named": true
|
|
1060
1111
|
},
|
|
1061
1112
|
{
|
|
1062
|
-
"type": "
|
|
1113
|
+
"type": "type_expression",
|
|
1063
1114
|
"named": true
|
|
1064
1115
|
},
|
|
1065
1116
|
{
|
|
1066
|
-
"type": "
|
|
1067
|
-
"named":
|
|
1117
|
+
"type": "while_expression",
|
|
1118
|
+
"named": true
|
|
1068
1119
|
}
|
|
1069
1120
|
]
|
|
1070
1121
|
},
|
|
@@ -1077,7 +1128,7 @@
|
|
|
1077
1128
|
"named": true
|
|
1078
1129
|
},
|
|
1079
1130
|
{
|
|
1080
|
-
"type": "
|
|
1131
|
+
"type": "for_expression",
|
|
1081
1132
|
"named": true
|
|
1082
1133
|
},
|
|
1083
1134
|
{
|
|
@@ -1085,7 +1136,11 @@
|
|
|
1085
1136
|
"named": true
|
|
1086
1137
|
},
|
|
1087
1138
|
{
|
|
1088
|
-
"type": "
|
|
1139
|
+
"type": "type_expression",
|
|
1140
|
+
"named": true
|
|
1141
|
+
},
|
|
1142
|
+
{
|
|
1143
|
+
"type": "while_expression",
|
|
1089
1144
|
"named": true
|
|
1090
1145
|
}
|
|
1091
1146
|
]
|
|
@@ -1157,7 +1212,7 @@
|
|
|
1157
1212
|
"required": true,
|
|
1158
1213
|
"types": [
|
|
1159
1214
|
{
|
|
1160
|
-
"type": "
|
|
1215
|
+
"type": "type_expression",
|
|
1161
1216
|
"named": true
|
|
1162
1217
|
}
|
|
1163
1218
|
]
|
|
@@ -1166,7 +1221,6 @@
|
|
|
1166
1221
|
{
|
|
1167
1222
|
"type": "doc_comment",
|
|
1168
1223
|
"named": true,
|
|
1169
|
-
"extra": true,
|
|
1170
1224
|
"fields": {},
|
|
1171
1225
|
"children": {
|
|
1172
1226
|
"multiple": false,
|
|
@@ -1217,10 +1271,18 @@
|
|
|
1217
1271
|
"type": "comptime_declaration",
|
|
1218
1272
|
"named": true
|
|
1219
1273
|
},
|
|
1274
|
+
{
|
|
1275
|
+
"type": "container_doc_comment",
|
|
1276
|
+
"named": true
|
|
1277
|
+
},
|
|
1220
1278
|
{
|
|
1221
1279
|
"type": "container_field",
|
|
1222
1280
|
"named": true
|
|
1223
1281
|
},
|
|
1282
|
+
{
|
|
1283
|
+
"type": "doc_comment",
|
|
1284
|
+
"named": true
|
|
1285
|
+
},
|
|
1224
1286
|
{
|
|
1225
1287
|
"type": "expression",
|
|
1226
1288
|
"named": true
|
|
@@ -1275,6 +1337,10 @@
|
|
|
1275
1337
|
"multiple": true,
|
|
1276
1338
|
"required": false,
|
|
1277
1339
|
"types": [
|
|
1340
|
+
{
|
|
1341
|
+
"type": "doc_comment",
|
|
1342
|
+
"named": true
|
|
1343
|
+
},
|
|
1278
1344
|
{
|
|
1279
1345
|
"type": "identifier",
|
|
1280
1346
|
"named": true
|
|
@@ -1315,9 +1381,25 @@
|
|
|
1315
1381
|
"multiple": false,
|
|
1316
1382
|
"required": true,
|
|
1317
1383
|
"types": [
|
|
1384
|
+
{
|
|
1385
|
+
"type": "comptime_type_expression",
|
|
1386
|
+
"named": true
|
|
1387
|
+
},
|
|
1388
|
+
{
|
|
1389
|
+
"type": "for_expression",
|
|
1390
|
+
"named": true
|
|
1391
|
+
},
|
|
1392
|
+
{
|
|
1393
|
+
"type": "if_type_expression",
|
|
1394
|
+
"named": true
|
|
1395
|
+
},
|
|
1318
1396
|
{
|
|
1319
1397
|
"type": "type_expression",
|
|
1320
1398
|
"named": true
|
|
1399
|
+
},
|
|
1400
|
+
{
|
|
1401
|
+
"type": "while_expression",
|
|
1402
|
+
"named": true
|
|
1321
1403
|
}
|
|
1322
1404
|
]
|
|
1323
1405
|
}
|
|
@@ -1361,7 +1443,7 @@
|
|
|
1361
1443
|
"required": false,
|
|
1362
1444
|
"types": [
|
|
1363
1445
|
{
|
|
1364
|
-
"type": "
|
|
1446
|
+
"type": "type_expression",
|
|
1365
1447
|
"named": true
|
|
1366
1448
|
}
|
|
1367
1449
|
]
|
|
@@ -1406,10 +1488,18 @@
|
|
|
1406
1488
|
"type": "block_label",
|
|
1407
1489
|
"named": true
|
|
1408
1490
|
},
|
|
1491
|
+
{
|
|
1492
|
+
"type": "comptime_type_expression",
|
|
1493
|
+
"named": true
|
|
1494
|
+
},
|
|
1409
1495
|
{
|
|
1410
1496
|
"type": "expression",
|
|
1411
1497
|
"named": true
|
|
1412
1498
|
},
|
|
1499
|
+
{
|
|
1500
|
+
"type": "if_type_expression",
|
|
1501
|
+
"named": true
|
|
1502
|
+
},
|
|
1413
1503
|
{
|
|
1414
1504
|
"type": "payload",
|
|
1415
1505
|
"named": true
|
|
@@ -1513,6 +1603,10 @@
|
|
|
1513
1603
|
"type": "error_union_type",
|
|
1514
1604
|
"named": true
|
|
1515
1605
|
},
|
|
1606
|
+
{
|
|
1607
|
+
"type": "for_expression",
|
|
1608
|
+
"named": true
|
|
1609
|
+
},
|
|
1516
1610
|
{
|
|
1517
1611
|
"type": "if_type_expression",
|
|
1518
1612
|
"named": true
|
|
@@ -1520,6 +1614,10 @@
|
|
|
1520
1614
|
{
|
|
1521
1615
|
"type": "type_expression",
|
|
1522
1616
|
"named": true
|
|
1617
|
+
},
|
|
1618
|
+
{
|
|
1619
|
+
"type": "while_expression",
|
|
1620
|
+
"named": true
|
|
1523
1621
|
}
|
|
1524
1622
|
]
|
|
1525
1623
|
}
|
|
@@ -1587,6 +1685,10 @@
|
|
|
1587
1685
|
"type": "error_union_type",
|
|
1588
1686
|
"named": true
|
|
1589
1687
|
},
|
|
1688
|
+
{
|
|
1689
|
+
"type": "for_expression",
|
|
1690
|
+
"named": true
|
|
1691
|
+
},
|
|
1590
1692
|
{
|
|
1591
1693
|
"type": "if_type_expression",
|
|
1592
1694
|
"named": true
|
|
@@ -1594,6 +1696,10 @@
|
|
|
1594
1696
|
{
|
|
1595
1697
|
"type": "type_expression",
|
|
1596
1698
|
"named": true
|
|
1699
|
+
},
|
|
1700
|
+
{
|
|
1701
|
+
"type": "while_expression",
|
|
1702
|
+
"named": true
|
|
1597
1703
|
}
|
|
1598
1704
|
]
|
|
1599
1705
|
}
|
|
@@ -1737,6 +1843,18 @@
|
|
|
1737
1843
|
"multiple": true,
|
|
1738
1844
|
"required": true,
|
|
1739
1845
|
"types": [
|
|
1846
|
+
{
|
|
1847
|
+
"type": "comptime_type_expression",
|
|
1848
|
+
"named": true
|
|
1849
|
+
},
|
|
1850
|
+
{
|
|
1851
|
+
"type": "for_expression",
|
|
1852
|
+
"named": true
|
|
1853
|
+
},
|
|
1854
|
+
{
|
|
1855
|
+
"type": "if_type_expression",
|
|
1856
|
+
"named": true
|
|
1857
|
+
},
|
|
1740
1858
|
{
|
|
1741
1859
|
"type": "payload",
|
|
1742
1860
|
"named": true
|
|
@@ -1744,6 +1862,10 @@
|
|
|
1744
1862
|
{
|
|
1745
1863
|
"type": "type_expression",
|
|
1746
1864
|
"named": true
|
|
1865
|
+
},
|
|
1866
|
+
{
|
|
1867
|
+
"type": "while_expression",
|
|
1868
|
+
"named": true
|
|
1747
1869
|
}
|
|
1748
1870
|
]
|
|
1749
1871
|
}
|
|
@@ -1771,7 +1893,7 @@
|
|
|
1771
1893
|
"required": true,
|
|
1772
1894
|
"types": [
|
|
1773
1895
|
{
|
|
1774
|
-
"type": "
|
|
1896
|
+
"type": "type_expression",
|
|
1775
1897
|
"named": true
|
|
1776
1898
|
}
|
|
1777
1899
|
]
|
|
@@ -1930,7 +2052,7 @@
|
|
|
1930
2052
|
"required": true,
|
|
1931
2053
|
"types": [
|
|
1932
2054
|
{
|
|
1933
|
-
"type": "
|
|
2055
|
+
"type": "type_expression",
|
|
1934
2056
|
"named": true
|
|
1935
2057
|
}
|
|
1936
2058
|
]
|
|
@@ -1948,6 +2070,10 @@
|
|
|
1948
2070
|
"type": "comptime_type_expression",
|
|
1949
2071
|
"named": true
|
|
1950
2072
|
},
|
|
2073
|
+
{
|
|
2074
|
+
"type": "for_expression",
|
|
2075
|
+
"named": true
|
|
2076
|
+
},
|
|
1951
2077
|
{
|
|
1952
2078
|
"type": "if_type_expression",
|
|
1953
2079
|
"named": true
|
|
@@ -1955,6 +2081,10 @@
|
|
|
1955
2081
|
{
|
|
1956
2082
|
"type": "type_expression",
|
|
1957
2083
|
"named": true
|
|
2084
|
+
},
|
|
2085
|
+
{
|
|
2086
|
+
"type": "while_expression",
|
|
2087
|
+
"named": true
|
|
1958
2088
|
}
|
|
1959
2089
|
]
|
|
1960
2090
|
}
|
|
@@ -1971,10 +2101,18 @@
|
|
|
1971
2101
|
"type": "comptime_declaration",
|
|
1972
2102
|
"named": true
|
|
1973
2103
|
},
|
|
2104
|
+
{
|
|
2105
|
+
"type": "container_doc_comment",
|
|
2106
|
+
"named": true
|
|
2107
|
+
},
|
|
1974
2108
|
{
|
|
1975
2109
|
"type": "container_field",
|
|
1976
2110
|
"named": true
|
|
1977
2111
|
},
|
|
2112
|
+
{
|
|
2113
|
+
"type": "doc_comment",
|
|
2114
|
+
"named": true
|
|
2115
|
+
},
|
|
1978
2116
|
{
|
|
1979
2117
|
"type": "function_declaration",
|
|
1980
2118
|
"named": true
|
|
@@ -2008,10 +2146,18 @@
|
|
|
2008
2146
|
"multiple": false,
|
|
2009
2147
|
"required": false,
|
|
2010
2148
|
"types": [
|
|
2149
|
+
{
|
|
2150
|
+
"type": "builtin_type",
|
|
2151
|
+
"named": true
|
|
2152
|
+
},
|
|
2011
2153
|
{
|
|
2012
2154
|
"type": "comptime_type_expression",
|
|
2013
2155
|
"named": true
|
|
2014
2156
|
},
|
|
2157
|
+
{
|
|
2158
|
+
"type": "for_expression",
|
|
2159
|
+
"named": true
|
|
2160
|
+
},
|
|
2015
2161
|
{
|
|
2016
2162
|
"type": "if_type_expression",
|
|
2017
2163
|
"named": true
|
|
@@ -2019,9 +2165,23 @@
|
|
|
2019
2165
|
{
|
|
2020
2166
|
"type": "type_expression",
|
|
2021
2167
|
"named": true
|
|
2168
|
+
},
|
|
2169
|
+
{
|
|
2170
|
+
"type": "while_expression",
|
|
2171
|
+
"named": true
|
|
2022
2172
|
}
|
|
2023
2173
|
]
|
|
2024
2174
|
}
|
|
2175
|
+
},
|
|
2176
|
+
"children": {
|
|
2177
|
+
"multiple": true,
|
|
2178
|
+
"required": false,
|
|
2179
|
+
"types": [
|
|
2180
|
+
{
|
|
2181
|
+
"type": "doc_comment",
|
|
2182
|
+
"named": true
|
|
2183
|
+
}
|
|
2184
|
+
]
|
|
2025
2185
|
}
|
|
2026
2186
|
},
|
|
2027
2187
|
{
|
|
@@ -2081,6 +2241,10 @@
|
|
|
2081
2241
|
"type": "address_space",
|
|
2082
2242
|
"named": true
|
|
2083
2243
|
},
|
|
2244
|
+
{
|
|
2245
|
+
"type": "comptime_type_expression",
|
|
2246
|
+
"named": true
|
|
2247
|
+
},
|
|
2084
2248
|
{
|
|
2085
2249
|
"type": "expression",
|
|
2086
2250
|
"named": true
|
|
@@ -2175,6 +2339,14 @@
|
|
|
2175
2339
|
"type": "byte_alignment",
|
|
2176
2340
|
"named": true
|
|
2177
2341
|
},
|
|
2342
|
+
{
|
|
2343
|
+
"type": "comptime_type_expression",
|
|
2344
|
+
"named": true
|
|
2345
|
+
},
|
|
2346
|
+
{
|
|
2347
|
+
"type": "for_expression",
|
|
2348
|
+
"named": true
|
|
2349
|
+
},
|
|
2178
2350
|
{
|
|
2179
2351
|
"type": "if_type_expression",
|
|
2180
2352
|
"named": true
|
|
@@ -2182,6 +2354,10 @@
|
|
|
2182
2354
|
{
|
|
2183
2355
|
"type": "type_expression",
|
|
2184
2356
|
"named": true
|
|
2357
|
+
},
|
|
2358
|
+
{
|
|
2359
|
+
"type": "while_expression",
|
|
2360
|
+
"named": true
|
|
2185
2361
|
}
|
|
2186
2362
|
]
|
|
2187
2363
|
}
|
|
@@ -2199,10 +2375,18 @@
|
|
|
2199
2375
|
"type": "comptime_declaration",
|
|
2200
2376
|
"named": true
|
|
2201
2377
|
},
|
|
2378
|
+
{
|
|
2379
|
+
"type": "container_doc_comment",
|
|
2380
|
+
"named": true
|
|
2381
|
+
},
|
|
2202
2382
|
{
|
|
2203
2383
|
"type": "container_field",
|
|
2204
2384
|
"named": true
|
|
2205
2385
|
},
|
|
2386
|
+
{
|
|
2387
|
+
"type": "doc_comment",
|
|
2388
|
+
"named": true
|
|
2389
|
+
},
|
|
2206
2390
|
{
|
|
2207
2391
|
"type": "function_declaration",
|
|
2208
2392
|
"named": true
|
|
@@ -2249,10 +2433,18 @@
|
|
|
2249
2433
|
"type": "comptime_declaration",
|
|
2250
2434
|
"named": true
|
|
2251
2435
|
},
|
|
2436
|
+
{
|
|
2437
|
+
"type": "container_doc_comment",
|
|
2438
|
+
"named": true
|
|
2439
|
+
},
|
|
2252
2440
|
{
|
|
2253
2441
|
"type": "container_field",
|
|
2254
2442
|
"named": true
|
|
2255
2443
|
},
|
|
2444
|
+
{
|
|
2445
|
+
"type": "doc_comment",
|
|
2446
|
+
"named": true
|
|
2447
|
+
},
|
|
2256
2448
|
{
|
|
2257
2449
|
"type": "expression",
|
|
2258
2450
|
"named": true
|
|
@@ -2285,7 +2477,7 @@
|
|
|
2285
2477
|
"named": true
|
|
2286
2478
|
},
|
|
2287
2479
|
{
|
|
2288
|
-
"type": "
|
|
2480
|
+
"type": "type_expression",
|
|
2289
2481
|
"named": true
|
|
2290
2482
|
}
|
|
2291
2483
|
]
|
|
@@ -2452,10 +2644,18 @@
|
|
|
2452
2644
|
"type": "comptime_declaration",
|
|
2453
2645
|
"named": true
|
|
2454
2646
|
},
|
|
2647
|
+
{
|
|
2648
|
+
"type": "container_doc_comment",
|
|
2649
|
+
"named": true
|
|
2650
|
+
},
|
|
2455
2651
|
{
|
|
2456
2652
|
"type": "container_field",
|
|
2457
2653
|
"named": true
|
|
2458
2654
|
},
|
|
2655
|
+
{
|
|
2656
|
+
"type": "doc_comment",
|
|
2657
|
+
"named": true
|
|
2658
|
+
},
|
|
2459
2659
|
{
|
|
2460
2660
|
"type": "expression",
|
|
2461
2661
|
"named": true
|
|
@@ -2487,6 +2687,10 @@
|
|
|
2487
2687
|
"type": "comptime_type_expression",
|
|
2488
2688
|
"named": true
|
|
2489
2689
|
},
|
|
2690
|
+
{
|
|
2691
|
+
"type": "for_expression",
|
|
2692
|
+
"named": true
|
|
2693
|
+
},
|
|
2490
2694
|
{
|
|
2491
2695
|
"type": "if_type_expression",
|
|
2492
2696
|
"named": true
|
|
@@ -2494,6 +2698,10 @@
|
|
|
2494
2698
|
{
|
|
2495
2699
|
"type": "type_expression",
|
|
2496
2700
|
"named": true
|
|
2701
|
+
},
|
|
2702
|
+
{
|
|
2703
|
+
"type": "while_expression",
|
|
2704
|
+
"named": true
|
|
2497
2705
|
}
|
|
2498
2706
|
]
|
|
2499
2707
|
}
|
|
@@ -2556,10 +2764,18 @@
|
|
|
2556
2764
|
"type": "block_label",
|
|
2557
2765
|
"named": true
|
|
2558
2766
|
},
|
|
2767
|
+
{
|
|
2768
|
+
"type": "comptime_type_expression",
|
|
2769
|
+
"named": true
|
|
2770
|
+
},
|
|
2559
2771
|
{
|
|
2560
2772
|
"type": "expression",
|
|
2561
2773
|
"named": true
|
|
2562
2774
|
},
|
|
2775
|
+
{
|
|
2776
|
+
"type": "if_type_expression",
|
|
2777
|
+
"named": true
|
|
2778
|
+
},
|
|
2563
2779
|
{
|
|
2564
2780
|
"type": "payload",
|
|
2565
2781
|
"named": true
|
|
@@ -2904,11 +3120,11 @@
|
|
|
2904
3120
|
"named": false
|
|
2905
3121
|
},
|
|
2906
3122
|
{
|
|
2907
|
-
"type": "
|
|
3123
|
+
"type": "asm",
|
|
2908
3124
|
"named": false
|
|
2909
3125
|
},
|
|
2910
3126
|
{
|
|
2911
|
-
"type": "
|
|
3127
|
+
"type": "bitpack",
|
|
2912
3128
|
"named": false
|
|
2913
3129
|
},
|
|
2914
3130
|
{
|
package/src/scanner.c
CHANGED
|
@@ -5,6 +5,12 @@ enum TokenType {
|
|
|
5
5
|
EMPTY_DOC_COMMENT_CONTENT,
|
|
6
6
|
ERROR_SENTINEL,
|
|
7
7
|
DECLARATION_NAME_COLON,
|
|
8
|
+
UNION_BACKING_OPEN,
|
|
9
|
+
COMMENT,
|
|
10
|
+
STRING_CONTENT_GUARD,
|
|
11
|
+
DIVISION,
|
|
12
|
+
DIVISION_ASSIGNMENT,
|
|
13
|
+
DECLARATION_DOC_OPEN,
|
|
8
14
|
};
|
|
9
15
|
|
|
10
16
|
void *tree_sitter_zig_external_scanner_create(void) { return NULL; }
|
|
@@ -25,24 +31,47 @@ void tree_sitter_zig_external_scanner_deserialize(void *payload, const char *buf
|
|
|
25
31
|
|
|
26
32
|
static inline bool at_eof(const TSLexer *lexer) { return lexer->lookahead == 0 && lexer->eof(lexer); }
|
|
27
33
|
|
|
34
|
+
static bool is_whitespace(int32_t character) {
|
|
35
|
+
return character == ' ' || character == '\t' || character == '\n' || character == '\r' ||
|
|
36
|
+
character == '\f';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static bool is_identifier_continue(int32_t character) {
|
|
40
|
+
return (character >= 'A' && character <= 'Z') || (character >= 'a' && character <= 'z') ||
|
|
41
|
+
(character >= '0' && character <= '9') || character == '_';
|
|
42
|
+
}
|
|
43
|
+
|
|
28
44
|
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
45
|
lexer->advance(lexer, false);
|
|
35
46
|
lexer->result_symbol = DECLARATION_NAME_COLON;
|
|
36
47
|
return true;
|
|
37
48
|
}
|
|
38
49
|
|
|
39
|
-
bool
|
|
40
|
-
(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return false;
|
|
50
|
+
static bool union_header_starts_with_enum(TSLexer *lexer) {
|
|
51
|
+
for (;;) {
|
|
52
|
+
while (is_whitespace(lexer->lookahead)) lexer->advance(lexer, false);
|
|
53
|
+
if (lexer->lookahead != '/') break;
|
|
54
|
+
lexer->advance(lexer, false);
|
|
55
|
+
if (lexer->lookahead != '/') return false;
|
|
56
|
+
while (lexer->lookahead != '\n' && !at_eof(lexer)) lexer->advance(lexer, false);
|
|
57
|
+
}
|
|
58
|
+
for (const char *character = "enum"; *character != '\0'; character++) {
|
|
59
|
+
if (lexer->lookahead != *character) return false;
|
|
60
|
+
lexer->advance(lexer, false);
|
|
45
61
|
}
|
|
62
|
+
return !is_identifier_continue(lexer->lookahead);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static bool scan_union_backing_open(TSLexer *lexer) {
|
|
66
|
+
lexer->advance(lexer, false);
|
|
67
|
+
lexer->mark_end(lexer);
|
|
68
|
+
// A leading enum selects the tagged-union header before Zig parses an expression.
|
|
69
|
+
if (union_header_starts_with_enum(lexer)) return false;
|
|
70
|
+
lexer->result_symbol = UNION_BACKING_OPEN;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static bool scan_doc_content(TSLexer *lexer, const bool *valid_symbols) {
|
|
46
75
|
if (at_eof(lexer)) {
|
|
47
76
|
if (!valid_symbols[EMPTY_DOC_COMMENT_CONTENT]) return false;
|
|
48
77
|
lexer->result_symbol = EMPTY_DOC_COMMENT_CONTENT;
|
|
@@ -57,3 +86,84 @@ bool tree_sitter_zig_external_scanner_scan(void *payload, TSLexer *lexer, const
|
|
|
57
86
|
lexer->result_symbol = DOC_COMMENT_CONTENT;
|
|
58
87
|
return true;
|
|
59
88
|
}
|
|
89
|
+
|
|
90
|
+
typedef struct {
|
|
91
|
+
bool starts_line;
|
|
92
|
+
bool may_follow_bom;
|
|
93
|
+
uint32_t whitespace_columns;
|
|
94
|
+
} DocumentationLine;
|
|
95
|
+
|
|
96
|
+
static bool scan_declaration_doc(TSLexer *lexer, const bool *valid_symbols, DocumentationLine line) {
|
|
97
|
+
if (!valid_symbols[DECLARATION_DOC_OPEN] || valid_symbols[ERROR_SENTINEL]) return false;
|
|
98
|
+
// The adjusted column excludes an initial BOM and includes the three marker characters already read.
|
|
99
|
+
if (!line.starts_line &&
|
|
100
|
+
(!line.may_follow_bom || lexer->get_column(lexer) != line.whitespace_columns + 3)) return false;
|
|
101
|
+
lexer->result_symbol = DECLARATION_DOC_OPEN;
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static bool scan_line_comment(TSLexer *lexer, const bool *valid_symbols, DocumentationLine line) {
|
|
106
|
+
lexer->advance(lexer, false);
|
|
107
|
+
if (lexer->lookahead == '!') return false;
|
|
108
|
+
if (lexer->lookahead == '/') {
|
|
109
|
+
lexer->advance(lexer, false);
|
|
110
|
+
if (lexer->lookahead != '/') return scan_declaration_doc(lexer, valid_symbols, line);
|
|
111
|
+
}
|
|
112
|
+
if (!valid_symbols[COMMENT]) return false;
|
|
113
|
+
while (lexer->lookahead != '\n' && !at_eof(lexer)) lexer->advance(lexer, false);
|
|
114
|
+
lexer->result_symbol = COMMENT;
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static bool scan_slash(TSLexer *lexer, const bool *valid_symbols, DocumentationLine line) {
|
|
119
|
+
if (lexer->lookahead != '/') return false;
|
|
120
|
+
lexer->advance(lexer, false);
|
|
121
|
+
if (lexer->lookahead == '/') return scan_line_comment(lexer, valid_symbols, line);
|
|
122
|
+
if (valid_symbols[ERROR_SENTINEL]) return false;
|
|
123
|
+
if (lexer->lookahead == '=') {
|
|
124
|
+
if (!valid_symbols[DIVISION_ASSIGNMENT]) return false;
|
|
125
|
+
lexer->advance(lexer, false);
|
|
126
|
+
lexer->result_symbol = DIVISION_ASSIGNMENT;
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
if (!valid_symbols[DIVISION]) return false;
|
|
130
|
+
lexer->result_symbol = DIVISION;
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static DocumentationLine skip_whitespace(TSLexer *lexer, bool may_start_documentation) {
|
|
135
|
+
DocumentationLine line = {0};
|
|
136
|
+
if (may_start_documentation) {
|
|
137
|
+
TSLexerPosition position;
|
|
138
|
+
lexer->get_position(lexer, &position);
|
|
139
|
+
line.starts_line = position.column == 0;
|
|
140
|
+
line.may_follow_bom = position.row == 0 && position.bytes <= 3;
|
|
141
|
+
}
|
|
142
|
+
while (is_whitespace(lexer->lookahead)) {
|
|
143
|
+
line.starts_line |= lexer->lookahead == '\n';
|
|
144
|
+
line.whitespace_columns++;
|
|
145
|
+
lexer->advance(lexer, true);
|
|
146
|
+
}
|
|
147
|
+
return line;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
bool tree_sitter_zig_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
|
|
151
|
+
(void)payload;
|
|
152
|
+
if (!valid_symbols[ERROR_SENTINEL] &&
|
|
153
|
+
(valid_symbols[DOC_COMMENT_CONTENT] || valid_symbols[EMPTY_DOC_COMMENT_CONTENT])) {
|
|
154
|
+
return scan_doc_content(lexer, valid_symbols);
|
|
155
|
+
}
|
|
156
|
+
// Literal string contents take priority over comment prefixes.
|
|
157
|
+
if (valid_symbols[STRING_CONTENT_GUARD] && !valid_symbols[ERROR_SENTINEL] &&
|
|
158
|
+
lexer->lookahead != '\n' && lexer->lookahead != '\r') return false;
|
|
159
|
+
DocumentationLine line = skip_whitespace(lexer, valid_symbols[DECLARATION_DOC_OPEN]);
|
|
160
|
+
if (!valid_symbols[ERROR_SENTINEL]) {
|
|
161
|
+
if (lexer->lookahead == ':' && valid_symbols[DECLARATION_NAME_COLON]) {
|
|
162
|
+
return scan_declaration_name_colon(lexer);
|
|
163
|
+
}
|
|
164
|
+
if (lexer->lookahead == '(' && valid_symbols[UNION_BACKING_OPEN]) {
|
|
165
|
+
return scan_union_backing_open(lexer);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return scan_slash(lexer, valid_symbols, line);
|
|
169
|
+
}
|
package/tree-sitter-zig.wasm
CHANGED
|
Binary file
|