@willbooster/tree-sitter-zig 18.0.0 → 20.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/grammar.js CHANGED
@@ -33,6 +33,7 @@ const builtinTypes = [
33
33
  'type',
34
34
  'anyerror',
35
35
  'anyopaque',
36
+ 'anytype',
36
37
  'noreturn',
37
38
  'isize',
38
39
  'usize',
@@ -53,40 +54,29 @@ const builtinTypes = [
53
54
  module.exports = grammar({
54
55
  name: 'zig',
55
56
 
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
- ],
57
+ externals: $ => [$.doc_comment_content, $._empty_doc_comment_content, $._error_sentinel, $._declaration_name_colon],
68
58
 
69
59
  conflicts: $ => [
70
- [$.block_label, $.primary_type_expression],
60
+ [$.block_label, $._type_expression],
71
61
  [$.block_label, $.boolean],
72
62
  [$.for_expression],
73
63
  [$.while_expression],
74
-
75
- [$.comptime_type_expression, $.parameter],
76
64
  ],
77
65
 
78
66
  extras: $ => [
79
67
  $.comment,
68
+ $.doc_comment,
69
+ $.container_doc_comment,
80
70
  /\s/,
81
71
  ],
82
72
 
83
73
  inline: $ => [
84
74
  $._reserved_identifier,
75
+ $._type_or_conditional,
85
76
  ],
86
77
 
87
78
  precedences: $ => [
88
- [$.container_field, $.type_expression],
89
- [$.container_field, $.comptime_type_expression],
79
+ [$.container_field, $._type_expression],
90
80
  [$._variable_declaration_expression_statement, $.assignment_expression],
91
81
  [$._variable_declaration_expression_statement, $._single_assignment_expression],
92
82
  ],
@@ -94,33 +84,26 @@ module.exports = grammar({
94
84
  supertypes: $ => [
95
85
  $.statement,
96
86
  $.expression,
97
- $.type_expression,
98
- $.primary_type_expression,
99
87
  ],
100
88
 
101
- word: $ => $._identifier,
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
- },
89
+ word: $ => $.identifier,
115
90
 
116
91
  rules: {
117
- source_file: $ => seq(repeat($.container_doc_comment), optional(choice($._container_members, repeat1($.doc_comment)))),
118
-
119
- _container_members: $ => containerMembers($, $.container_field),
120
-
121
- _packed_struct_members: $ => packedContainerMembers($, alias($._packed_struct_field, $.container_field)),
92
+ source_file: $ => optional($._container_members),
122
93
 
123
- _packed_union_members: $ => packedContainerMembers($, alias($._packed_union_field, $.container_field)),
94
+ _container_members: $ => choice(
95
+ seq(
96
+ repeat1(choice(
97
+ $.test_declaration,
98
+ $.comptime_declaration,
99
+ $.variable_declaration,
100
+ $.function_declaration,
101
+ seq($.container_field, ','),
102
+ )),
103
+ optional($.container_field),
104
+ ),
105
+ $.container_field,
106
+ ),
124
107
 
125
108
  test_declaration: $ => seq(
126
109
  optional('pub'),
@@ -137,27 +120,27 @@ module.exports = grammar({
137
120
 
138
121
  container_field: $ => prec.right(prec.dynamic(1, seq(
139
122
  optional('comptime'),
140
- choice(namedContainerField($), field('name', typeExpression($))),
123
+ choice(
124
+ seq(
125
+ field('name', choice($.identifier, alias(choice($.builtin_type, $._reserved_identifier), $.identifier))),
126
+ alias($._declaration_name_colon, ':'),
127
+ field('type', $._type_or_conditional),
128
+ ),
129
+ field('name', $._type_or_conditional),
130
+ ),
141
131
  optional($.byte_alignment),
142
132
  optional(seq('=', $.expression)),
143
133
  ))),
144
134
 
145
- _packed_struct_field: $ => packedField($, optional(seq('=', $.expression))),
146
-
147
- _packed_union_field: $ => packedField($),
148
-
149
135
  variable_declaration: $ => seq(
150
- optional('pub'),
151
- optional(choice(
152
- 'export',
153
- seq('extern', optional($.string)),
154
- )),
155
- optional('threadlocal'),
136
+ optional($._declaration_modifiers),
156
137
  $._variable_declaration_header,
157
138
  optional(seq('=', $.expression)),
158
139
  ';',
159
140
  ),
160
141
 
142
+ _declaration_modifiers: $ => repeat1(choice('pub', 'export', seq('extern', optional($.string)), 'threadlocal', 'inline', 'noinline')),
143
+
161
144
  _variable_declaration_expression_statement: $ => choice(
162
145
  seq(
163
146
  $._variable_declaration_header,
@@ -188,21 +171,15 @@ module.exports = grammar({
188
171
  $.identifier,
189
172
  optional(seq(
190
173
  ':',
191
- field('type', typeExpression($)),
174
+ field('type', $._type),
192
175
  )),
193
- optional($.byte_alignment),
194
- optional($.address_space),
195
- optional($.link_section),
176
+ optional($._declaration_attributes),
196
177
  )),
197
178
 
179
+ _declaration_attributes: $ => repeat1(choice($.byte_alignment, $.address_space, $.link_section, $.calling_convention)),
180
+
198
181
  function_declaration: $ => seq(
199
- optional('pub'),
200
- optional(choice(
201
- 'export',
202
- seq('extern', optional($.string)),
203
- 'inline',
204
- 'noinline',
205
- )),
182
+ optional($._declaration_modifiers),
206
183
  $._function_prototype,
207
184
  choice(
208
185
  ';',
@@ -214,29 +191,22 @@ module.exports = grammar({
214
191
  'fn',
215
192
  optional(field('name', $.identifier)),
216
193
  field('parameters', $.parameters),
217
- optional($.byte_alignment),
218
- optional($.address_space),
219
- optional($.link_section),
220
- optional($.calling_convention),
221
- field('type', choice(
222
- typeExpression($),
223
- alias($._inferred_error_union_type, $.error_union_type),
224
- )),
194
+ optional($._declaration_attributes),
195
+ field('type', choice($._type_or_conditional, alias($._inferred_error_union_type, $.error_union_type))),
225
196
  ),
226
197
 
227
- _inferred_error_union_type: $ => prec.right(-1, seq('!', field('ok', typeExpression($)))),
198
+ _inferred_error_union_type: $ => prec.left(-1, seq('!', field('ok', $._type_or_conditional))),
228
199
 
229
200
  parameters: $ => seq('(', optionalCommaSep($.parameter), ')'),
230
201
 
231
202
  parameter: $ => choice(
232
203
  seq(
233
- repeat($.doc_comment),
234
204
  optional(choice('noalias', 'comptime')),
235
205
  optional(seq(
236
206
  field('name', choice($.identifier, alias(choice($.builtin_type, $._reserved_identifier), $.identifier))),
237
207
  alias($._declaration_name_colon, ':'),
238
208
  )),
239
- field('type', choice(alias('anytype', $.builtin_type), typeExpression($))),
209
+ field('type', $._type),
240
210
  ),
241
211
  '...',
242
212
  ),
@@ -247,46 +217,42 @@ module.exports = grammar({
247
217
  '}',
248
218
  ),
249
219
 
250
- _packed_layout: _ => choice('packed', 'bitpack'),
251
-
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
- ),
220
+ struct_declaration: $ => seq(
221
+ optional($._container_layout),
222
+ 'struct',
223
+ optional($._parenthesized),
224
+ $._container_body,
259
225
  ),
260
226
 
261
- opaque_declaration: $ => containerBody($, 'opaque', $._container_members),
227
+ opaque_declaration: $ => seq(optional($._container_layout), 'opaque', $._container_body),
262
228
 
263
- enum_declaration: $ => containerBody(
264
- $,
265
- seq('enum', optional(seq('(', $.expression, ')'))),
266
- $._container_members,
229
+ enum_declaration: $ => seq(
230
+ optional($._container_layout),
231
+ 'enum',
232
+ optional($._parenthesized),
233
+ $._container_body,
267
234
  ),
268
235
 
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
- choice(
276
- seq('extern', 'union'),
277
- seq('union', optional(choice(
278
- $._union_backing,
279
- seq('(', 'enum', optional(seq('(', $.expression, ')')), ')'),
280
- ))),
281
- ),
282
- $._container_members,
283
- ),
236
+ union_declaration: $ => seq(
237
+ optional($._container_layout),
238
+ 'union',
239
+ optional(choice(
240
+ $._parenthesized,
241
+ seq('(', 'enum', optional($._parenthesized), ')'),
242
+ )),
243
+ $._container_body,
284
244
  ),
285
245
 
246
+ _container_layout: _ => choice('extern', 'packed', 'bitpack'),
247
+
248
+ _container_body: $ => seq('{', optional($._container_members), '}'),
249
+
250
+ _parenthesized: $ => seq('(', $.expression, ')'),
251
+
286
252
  error_set_declaration: $ => seq(
287
253
  'error',
288
254
  '{',
289
- optionalCommaSep(seq(repeat($.doc_comment), $.identifier)),
255
+ optionalCommaSep($.identifier),
290
256
  '}',
291
257
  ),
292
258
 
@@ -396,13 +362,13 @@ module.exports = grammar({
396
362
 
397
363
  payload: $ => seq('|', optionalCommaSep1(seq(optional('*'), $.identifier)), '|'),
398
364
 
399
- byte_alignment: $ => seq('align', '(', $.expression, ')'),
365
+ byte_alignment: $ => seq('align', '(', $.expression, optional(seq(':', $.expression, ':', $.expression)), ')'),
400
366
 
401
- address_space: $ => seq('addrspace', '(', $.expression, ')'),
367
+ address_space: $ => seq('addrspace', $._parenthesized),
402
368
 
403
- link_section: $ => seq('linksection', '(', $.expression, ')'),
369
+ link_section: $ => seq('linksection', $._parenthesized),
404
370
 
405
- calling_convention: $ => seq('callconv', '(', $.expression, ')'),
371
+ calling_convention: $ => seq('callconv', $._parenthesized),
406
372
 
407
373
  expression: $ => prec.right(choice(
408
374
  $.asm_expression,
@@ -419,8 +385,8 @@ module.exports = grammar({
419
385
  $.break_expression,
420
386
  $.try_expression,
421
387
  $.catch_expression,
388
+ $._type_expression,
422
389
  $.struct_initializer,
423
- $.type_expression,
424
390
  $.block,
425
391
  )),
426
392
 
@@ -439,7 +405,7 @@ module.exports = grammar({
439
405
  ']',
440
406
  choice($.string, $.multiline_string),
441
407
  '(',
442
- choice(seq('->', typeExpression($)), $.identifier),
408
+ choice(seq('->', $._type_or_conditional), $.identifier),
443
409
  ')',
444
410
  ),
445
411
  asm_input: $ => seq(':', optionalCommaSep($.asm_input_item), optional($.asm_clobbers)),
@@ -457,19 +423,26 @@ module.exports = grammar({
457
423
  if_expression: $ => prec.right(seq(
458
424
  $._if_prefix,
459
425
  $.expression,
460
- optional(seq('else', optional($.payload), $.expression)),
426
+ optional($._else_expression),
461
427
  )),
462
428
 
463
- for_expression: $ => loopExpression($, $._for_prefix, $.expression),
464
-
465
- while_expression: $ => loopExpression($, $._while_prefix, $.expression, seq(optional($.payload), $.expression)),
429
+ for_expression: $ => prec.right(seq(
430
+ optional($.block_label),
431
+ optional('inline'),
432
+ $._for_prefix,
433
+ $.expression,
434
+ optional($._else_expression),
435
+ )),
466
436
 
467
- _for_type_expression: $ => loopExpression($, $._for_prefix, typeExpression($)),
437
+ while_expression: $ => prec.right(seq(
438
+ optional($.block_label),
439
+ optional('inline'),
440
+ $._while_prefix,
441
+ $.expression,
442
+ optional($._else_expression),
443
+ )),
468
444
 
469
- _while_type_expression: $ => {
470
- const type = typeExpression($);
471
- return loopExpression($, $._while_prefix, type, seq(optional($.payload), type));
472
- },
445
+ _else_expression: $ => prec.right(seq('else', optional($.payload), $.expression)),
473
446
 
474
447
  assignment_expression: $ => choice(
475
448
  $._single_assignment_expression,
@@ -487,8 +460,8 @@ module.exports = grammar({
487
460
  field('right', $.expression),
488
461
  ),
489
462
 
490
- _assignment_operator: $ => choice(
491
- '=', '*=', '*%=', '*|=', alias($._division_assignment, '/='), '%=',
463
+ _assignment_operator: _ => choice(
464
+ '=', '*=', '*%=', '*|=', '/=', '%=',
492
465
  '+=', '+%=', '+|=', '-=', '-%=', '-|=',
493
466
  '<<=', '<<|=', '>>=', '&=', '^=', '|=',
494
467
  ),
@@ -523,7 +496,7 @@ module.exports = grammar({
523
496
  ['+|', PREC.ADD],
524
497
  ['-|', PREC.ADD],
525
498
  ['*', PREC.MULTIPLY],
526
- [alias($._division, '/'), PREC.MULTIPLY],
499
+ ['/', PREC.MULTIPLY],
527
500
  ['%', PREC.MULTIPLY],
528
501
  ['**', PREC.MULTIPLY],
529
502
  ['*%', PREC.MULTIPLY],
@@ -563,7 +536,7 @@ module.exports = grammar({
563
536
 
564
537
  try_expression: $ => prec.left(PREC.UNARY, seq('try', $.expression)),
565
538
 
566
- catch_expression: $ => prec.right(PREC.BITWISE, seq(
539
+ catch_expression: $ => prec.left(PREC.BITWISE, seq(
567
540
  $.expression,
568
541
  'catch',
569
542
  optional($.payload),
@@ -573,7 +546,7 @@ module.exports = grammar({
573
546
  switch_expression: $ => seq(
574
547
  optional($.block_label),
575
548
  'switch',
576
- '(', $.expression, ')',
549
+ $._parenthesized,
577
550
  '{',
578
551
  optionalCommaSep($.switch_case),
579
552
  '}',
@@ -592,15 +565,15 @@ module.exports = grammar({
592
565
  ),
593
566
  ),
594
567
 
595
- type_expression: $ => prec.right(choice(
568
+ _type: $ => prec(1, $._type_or_conditional),
569
+
570
+ _type_or_conditional: $ => choice($._type_expression, $.if_type_expression),
571
+
572
+ _type_expression: $ => choice(
596
573
  $.anonymous_struct_initializer,
597
574
  $.labeled_type_expression,
598
575
  $.error_set_declaration,
599
576
  $.parenthesized_expression,
600
- $.primary_type_expression,
601
- )),
602
-
603
- primary_type_expression: $ => choice(
604
577
  $.nullable_type,
605
578
  $.anyframe_type,
606
579
  $.slice_type,
@@ -636,13 +609,13 @@ module.exports = grammar({
636
609
 
637
610
  nullable_type: $ => prec(1, seq(
638
611
  '?',
639
- typeExpression($),
612
+ $._type,
640
613
  )),
641
614
 
642
615
  anyframe_type: $ => prec(1, seq(
643
616
  'anyframe',
644
617
  '->',
645
- typeExpression($),
618
+ $._type_or_conditional,
646
619
  )),
647
620
 
648
621
  slice_type: $ => prec.right(1, seq(
@@ -652,14 +625,8 @@ module.exports = grammar({
652
625
  field('sentinel', $.expression),
653
626
  )),
654
627
  ']',
655
- repeat(choice(
656
- $.byte_alignment,
657
- $.address_space,
658
- 'const',
659
- 'volatile',
660
- 'allowzero',
661
- )),
662
- typeExpression($),
628
+ optional($._pointer_modifiers),
629
+ $._type,
663
630
  )),
664
631
 
665
632
  pointer_type: $ => prec.right(1, seq(
@@ -672,20 +639,16 @@ module.exports = grammar({
672
639
  ']',
673
640
  ),
674
641
  ),
675
- repeat(choice(
676
- $.address_space,
677
- seq(
678
- 'align',
679
- '(',
680
- $.expression,
681
- optional(seq(':', $.expression, ':', $.expression)),
682
- ')',
683
- ),
684
- 'const',
685
- 'volatile',
686
- 'allowzero',
687
- )),
688
- typeExpression($),
642
+ optional($._pointer_modifiers),
643
+ $._type,
644
+ )),
645
+
646
+ _pointer_modifiers: $ => repeat1(choice(
647
+ $.byte_alignment,
648
+ $.address_space,
649
+ 'const',
650
+ 'volatile',
651
+ 'allowzero',
689
652
  )),
690
653
 
691
654
  array_type: $ => prec(1, seq(
@@ -693,23 +656,23 @@ module.exports = grammar({
693
656
  $.expression,
694
657
  optional(seq(':', $.expression)),
695
658
  ']',
696
- typeExpression($),
659
+ $._type,
697
660
  )),
698
661
 
699
662
  error_union_type: $ => prec.right(2, seq(
700
- field('error', $.type_expression),
663
+ field('error', $._type_expression),
701
664
  '!',
702
- field('ok', typeExpression($)),
665
+ field('ok', $._type_or_conditional),
703
666
  )),
704
667
 
705
668
  field_expression: $ => prec(PREC.MEMBER, seq(
706
- optional(field('object', $.type_expression)),
669
+ optional(field('object', $._type_expression)),
707
670
  '.',
708
671
  field('member', $.identifier),
709
672
  )),
710
673
 
711
674
  index_expression: $ => prec(PREC.MEMBER, seq(
712
- field('object', $.type_expression),
675
+ field('object', $._type_expression),
713
676
  '[',
714
677
  choice(
715
678
  field('index', $.expression),
@@ -721,9 +684,9 @@ module.exports = grammar({
721
684
  ']',
722
685
  )),
723
686
 
724
- dereference_expression: $ => prec(PREC.MEMBER, seq($.type_expression, '.*')),
687
+ dereference_expression: $ => prec(PREC.MEMBER, seq($._type_expression, '.*')),
725
688
 
726
- null_coercion_expression: $ => prec(PREC.MEMBER, seq($.type_expression, '.?')),
689
+ null_coercion_expression: $ => prec(PREC.MEMBER, seq($._type_expression, '.?')),
727
690
 
728
691
  range_expression: $ => prec.right(PREC.MEMBER, seq(
729
692
  field('left', $.expression),
@@ -732,7 +695,7 @@ module.exports = grammar({
732
695
  )),
733
696
 
734
697
  call_expression: $ => prec(PREC.MEMBER, seq(
735
- field('function', $.type_expression),
698
+ field('function', $._type_expression),
736
699
  '(',
737
700
  optionalCommaSep($.expression),
738
701
  ')',
@@ -740,7 +703,7 @@ module.exports = grammar({
740
703
 
741
704
  anonymous_struct_initializer: $ => seq('.', $.initializer_list),
742
705
 
743
- struct_initializer: $ => prec(-1, seq($.type_expression, $.initializer_list)),
706
+ struct_initializer: $ => prec(-1, seq($._type_expression, $.initializer_list)),
744
707
 
745
708
  initializer_list: $ => seq(
746
709
  '{',
@@ -760,12 +723,10 @@ module.exports = grammar({
760
723
 
761
724
  labeled_type_expression: $ => seq($.block_label, $.block),
762
725
 
763
- comptime_type_expression: $ => seq('comptime', typeExpression($)),
764
-
765
726
  if_type_expression: $ => prec.right(seq(
766
727
  $._if_prefix,
767
- typeExpression($),
768
- optional(seq('else', optional($.payload), typeExpression($))),
728
+ $._type_or_conditional,
729
+ optional(seq('else', optional($.payload), $._type_or_conditional)),
769
730
  )),
770
731
 
771
732
  parenthesized_expression: $ => seq('(', $.expression, ')'),
@@ -783,12 +744,10 @@ module.exports = grammar({
783
744
  $.arguments,
784
745
  ),
785
746
 
786
- string: $ => $._string,
787
-
788
- _string: $ => seq(
747
+ string: $ => seq(
789
748
  '"',
790
749
  repeat(choice(
791
- stringContent($, /[^\\"\n]+/),
750
+ alias(token.immediate(prec(1, /[^\\"\n]+/)), $.string_content),
792
751
  $.escape_sequence,
793
752
  )),
794
753
  '"',
@@ -796,7 +755,7 @@ module.exports = grammar({
796
755
 
797
756
  multiline_string: $ => prec.right(repeat1(seq(
798
757
  '\\\\',
799
- optional(stringContent($, /[^\r\n]+/)),
758
+ optional(alias(token.immediate(prec(1, /[^\r\n]+/)), $.string_content)),
800
759
  ))),
801
760
 
802
761
  escape_sequence: _ => token(prec(1, seq(
@@ -860,8 +819,7 @@ module.exports = grammar({
860
819
 
861
820
  builtin_identifier: _ => /@[A-Za-z_][A-Za-z0-9_]*/,
862
821
 
863
- identifier: $ => choice($._identifier, seq('@', $._string)),
864
- _identifier: _ => /[A-Za-z_][A-Za-z0-9_]*/,
822
+ identifier: _ => token(choice(/[A-Za-z_][A-Za-z0-9_]*/, /@"([^"\\\n]|\\.)*"/)),
865
823
  _reserved_identifier: _ => choice(
866
824
  'undefined',
867
825
  'null',
@@ -869,10 +827,14 @@ module.exports = grammar({
869
827
  'false',
870
828
  ),
871
829
 
872
- doc_comment: $ => seq(alias($._declaration_doc_open, '///'), choice($.doc_comment_content, $._empty_doc_comment_content)),
830
+ doc_comment: $ => seq('///', choice($.doc_comment_content, $._empty_doc_comment_content)),
873
831
 
874
832
  container_doc_comment: $ => seq('//!', choice($.doc_comment_content, $._empty_doc_comment_content)),
875
833
 
834
+ comment: _ => token(seq('//', optional(choice(
835
+ seq(/[^!/\n]/, /.*/),
836
+ seq('//', /.*/),
837
+ )))),
876
838
  },
877
839
  });
878
840
 
@@ -887,72 +849,3 @@ function optionalCommaSep1(rule) {
887
849
  function commaSep1(rule) {
888
850
  return seq(rule, repeat(seq(',', rule)));
889
851
  }
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-zig",
3
- "version": "18.0.0",
3
+ "version": "20.0.0",
4
4
  "description": "Zig grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "parsing",