-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
-
228
-
229
-
230
-
231
-
232
-
233
-
234
-
235
-
236
-
237
-
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
-
261
-
262
-
263
-
264
-
265
-
266
-
267
-
268
-
269
-
270
-
271
-
272
-
273
-
274
-
275
-
276
-
277
-
278
-
279
-
280
-
281
-
282
-
283
-
284
-
285
-
286
-
287
-
288
-
289
-
290
-
291
-
292
-
293
-
294
-
295
-
296
-
297
-
298
-
299
-
300
-
301
-
302
-
303
-
304
-
305
-
306
-
307
-
308
-
309
-
310
-
311
-
312
-
313
-
314
-
315
-
316
-
317
-
318
-
319
-
320
-
321
-
322
-
323
-
324
-
325
-
326
-
327
-
328
-
329
-
330
-
331
-
332
-
333
-
334
-
335
-
336
-
337
-
338
-
339
-
340
-
341
-
342
-
343
-
344
-
345
-
346
-
347
-
348
-
349
-
350
-
351
-
352
-
353
-
354
-
355
-
356
-
357
-
358
-
359
-
360
-
361
-
362
-
363
-
364
-
365
-
366
-
367
-
368
-
369
-
370
-
371
-
372
-
373
-
374
-
375
-
376
-
377
-
378
-
379
-
380
-
381
-
382
-
383
-
384
-
385
-
386
-
387
-
388
-
389
-
390
-
391
-
392
-
393
-
394
-
395
-
396
-
397
-
398
-
399
-
400
-
401
-
402
-
403
-
404
-
405
-
406
-
407
-
408
-
409
-
410
-
411
-
412
-
413
-
414
-
415
-
416
-
417
-
418
-
419
-
420
-
421
-
422
-
423
-
424
-
425
-
426
-
427
-
428
-
429
-
430
-
431
-
432
-
433
-
434
-
435
-
436
-
437
-
438
-
439
-
440
-
441
-
442
-
443
-
444
-
445
-
446
-
447
-
448
-
449
-
450
-
451
-
452
-
453
-
454
-
455
-
456
-
457
-
458
-
459
-
460
-
461
-
462
-
463
-
464
-
465
-
466
-
467
-
468
-
469
-
470
-
471
-
472
-
473
-
474
-
475
-
476
-
477
-
478
-
479
-
480
-
481
-
482
-
483
-
484
-
485
-
486
-
487
-
488
-
489
-
490
-
491
-
492
-
493
-
494
-
495
-
496
-
497
-
498
-
499
-
500
-
501
-
502
-
503
-
504
-
505
-
506
-
507
-
508
-
509
-
510
-
511
-
512
-
513
-
514
-
515
-
516
-
517
-
518
-
519
-
520
-
521
-
522
-
523
-
524
-
525
-
526
-
527
-
528
-
529
-
530
-
531
-
532
-
533
-
534
-
535
-
536
-
537
-
538
-
539
-
540
-
541
-
542
-
543
-
544
-
545
-
546
-
547
-
548
-
549
-
550
-
551
-
552
-
553
-
554
-
555
-
556
-
557
-
558
-
559
-
560
-
561
-
562
-
563
-
564
-
565
-
566
-
567
-
568
-
569
-
570
-
571
-
572
-
573
-
574
-
575
-
576
-
577
-
578
-
579
-
580
-
581
-
582
-
583
-
584
-
585
-
586
-
587
-
588
-
589
-
590
-
591
-
592
-
593
-
594
-
595
-
596
-
597
-
598
-
599
-
600
-
601
-
602
-
603
-
604
-
605
-
606
-
607
-
608
-
609
-
610
-
611
-
612
-
613
-
614
-
615
-
616
-
617
-
618
-
619
-
620
-
621
-
622
-
623
-
624
-
625
-
626
-
627
-
628
-
629
-
630
-
631
-
632
-
633
-
634
-
635
-
636
-
637
-
638
-
639
-
640
-
641
-
642
-
643
-
644
-
645
-
646
-
647
-
648
-
649
-
650
-
651
-
652
-
653
-
654
-
655
-
656
-
657
-
658
-
659
-
660
-
661
-
662
-
663
-
664
-
665
-
666
-
667
-
668
-
669
-
670
-
671
-
672
-
673
-
674
-
675
-
676
-
677
-
678
-
679
-
680
-
681
-
682
-
683
-
684
-
685
-
686
-
687
-
688
-
689
-
690
-
691
-
692
-
693
-
694
-
695
-
696
-
697
-
698
-
699
-
700
-
701
-
702
-
703
-
704
-
705
-
706
-
707
-
708
-
709
-
710
-
711
-
712
-
713
-
714
-
715
-
716
-
717
-
718
-
719
-
720
-
721
-
722
-
723
-
724
-
725
-
726
-
727
-
728
-
729
-
730
-
731
-
732
-
733
-
734
-
735
-
736
-
737
-
738
-
739
-
740
-
741
-
742
-
743
-
744
-
745
-
746
-
747
-
748
-
749
-
750
-
751
-
752
-
753
-
754
-
755
-
756
-
757
-
758
-
759
-
760
-
761
-
762
-
763
-
764
-
765
-
766
-
767
-
768
-
769
-
770
-
771
-
772
-
773
-
774
-
775
-
776
-
777
-
778
-
779
-
780
-
781
-
782
-
783
-
784
-
785
-
786
-
787
-
788
-
789
-
790
-
791
-
792
-
793
-
794
-
795
-
796
-
797
-
798
-
799
-
800
-
801
-
802
-
803
-
804
-
805
-
806
-
807
-
808
-
809
-
810
-
811
-
812
-
813
-
814
-
815
-
816
-
817
-
818
-
819
-
820
-
821
-
822
-
823
-
824
-
825
-
826
-
827
-
828
-
829
-
830
-
831
-
832
-
833
-
834
-
835
-
836
-
837
-
838
-
839
-
840
-
841
-
842
-
843
-
844
-
845
-
846
-
847
-
848
-
849
-
850
-
851
-
852
-
853
-
854
-
855
-
856
-
857
-
858
-
859
-
860
-
861
-
862
-
863
-
864
-
865
-
866
-
867
-
868
-
869
-
870
-
871
-
872
-
873
-
874
-
875
-
876
-
877
-
878
-
879
-
880
-
881
-
882
-
883
-
884
-
885
-
886
-
887
-
888
-
889
-
890
-
891
-
892
-
893
-
894
-
895
-
896
-
897
-
898
-
899
-
900
-
901
-
902
-
903
-
904
-
905
-
906
-
907
-
908
-
909
-
910
-
911
-
912
-
913
-
914
-
915
-
916
-
917
-
918
-
919
-
920
-
921
-
922
-
923
-
924
-
925
module.exports = grammar({
name: 'vala',
word: $ => $.identifier,
rules: {
source_file: $ => seq(repeat($.using_directive), repeat(choice($.namespace_member, $._statement))),
// taken from tree-sitter-c
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
comment: $ => token(prec(1, choice(
seq('//', /(\\(.|\r?\n)|[^\\\n])*/),
seq(
'/*',
/[^*]*\*+([^/*][^*]*\*+)*/,
'/'
)
))),
using_directive: $ => seq(
'using',
$.symbol,
repeat(seq(',', $.symbol)),
';'
),
symbol: $ => choice(
seq($.symbol, '.', $.identifier),
seq(optional('global::'), $.identifier)
),
identifier: $ => /[@A-Za-z_]\w*/,
namespace_member: $ => seq(
repeat($._attribute_list),
choice(
$.namespace_declaration,
$.class_declaration,
$.interface_declaration,
$.struct_declaration,
$.enum_declaration,
$.errordomain_declaration,
$.delegate_declaration,
$.method_declaration,
$.signal_declaration,
$.field_declaration,
$.constant_declaration
)
),
_attribute_list: $ => seq(
'[',
$.attribute,
repeat(seq(',', $.attribute)),
']'
),
attribute: $ => seq(
$.identifier,
optional(seq('(', $.attribute_argument, repeat(seq(',', $.attribute_argument)), ')'))
),
attribute_argument: $ => seq(
$.identifier,
'=',
$._expression
),
_expression: $ => choice(
$._contained_expression,
$.initializer,
$.yield_expression,
$.lambda_expression,
$.static_cast_expression,
$._unary_expression,
$.multiplicative_expression,
$.arithmetic_expression,
$.in_expression,
$.bitshift_expression,
$.dynamic_cast_expression,
$.type_relational_expression,
$.relational_expression,
$.equality_expression,
$.bitwise_and_expression,
$.bitwise_xor_expression,
$.bitwise_or_expression,
$.logical_and_expression,
$.logical_or_expression,
$.null_coalescing_expression,
$.ternary_expression,
$.assignment_expression
),
// expressions that never need to be wrapped in parentheses
_contained_expression: $ => choice(
seq('(', $._expression, ')'),
$.literal,
$.array_creation_expression,
$.object_creation_expression,
$.this_access,
$.base_access,
$.value_access,
$.member_access_expression,
$.element_access_expression,
$.struct_initializer,
$.method_call_expression,
$.sizeof_expression,
$.typeof_expression,
$.postfix_expression,
),
// expressions that are contained by an operator to the left
// for example:
// if (!yield x())
// ^^^^^^^^^ -- we don't need parens here because of the '!' operator
_left_contained_expression: $ => choice(
$._contained_expression,
$.yield_expression,
$.static_cast_expression,
$._unary_expression
),
member_access_expression: $ => seq(
optional(seq(
$._contained_expression,
choice('.', '?.', '->'),
)),
$.identifier
),
element_access_expression: $ => seq(
$._contained_expression,
repeat1($.element_access)
),
element_access: $ => seq(
'[',
choice($._expression, $.slice_expression),
repeat(seq(',', choice($._expression, $.slice_expression))),
']'
),
slice_expression: $ => choice(
seq($._expression, ':', optional($._expression)),
seq(':', $._expression)
),
argument: $ => choice(
seq('ref', $._expression),
seq('out', $._expression),
$._expression,
seq($.identifier, ':', $._expression)
),
method_call_expression: $ => seq(
choice(
seq('(', $._expression, ')'),
seq($.member_access_expression, optional($.type_arguments)),
$._contained_expression
),
'(',
optional(seq($.argument, repeat(seq(',', $.argument)))),
')'
),
struct_initializer: $ => seq(
$.method_call_expression,
$.object_initializers,
),
yield_expression: $ => seq('yield', $._expression),
lambda_expression: $ => seq(
choice(
$.identifier,
seq('(', optional(seq($.identifier, repeat(seq(',', $.identifier)))), ')')
),
'=>',
choice($._expression, $.block)
),
postfix_expression: $ => prec.left(15, seq($._expression, choice('++', '--'))),
static_cast_expression: $ => prec.right(14, seq('(', choice($.type, '!', 'owned'), ')', $._expression)),
typeof_expression: $ => prec.right(14, seq('typeof', '(', $.type, ')')),
sizeof_expression: $ => prec.right(14, seq('sizeof', '(', $.type, ')')),
dereferencing_expression: $ => prec.right(14, seq('*', $._left_contained_expression)),
addressof_expression: $ => prec.right(14, seq('&', $._left_contained_expression)),
arithmetic_negation_expression: $ => prec.right(14, seq('-', $._left_contained_expression)),
prefix_expression: $ => prec.right(14, seq(choice('++', '--'), $._left_contained_expression)),
bitwise_negation_expression: $ => prec.right(14, seq('~', $._left_contained_expression)),
logical_negation_expression: $ => prec.right(14, seq(choice('!', 'not'), $._left_contained_expression)),
_unary_expression: $ => prec.right(14, choice(
$.dereferencing_expression,
$.addressof_expression,
$.arithmetic_negation_expression,
$.prefix_expression,
$.bitwise_negation_expression,
$.logical_negation_expression
)),
multiplicative_expression: $ => prec.left(13, seq($._expression, choice('*', '/', '%'), $._expression)),
arithmetic_expression: $ => prec.left(12, seq($._expression, choice('+', '-'), $._expression)),
bitshift_expression: $ => prec.left(11, seq($._expression, choice('<<', '>>'), $._expression)),
in_expression: $ => prec.left(10, seq($._expression, optional('not'), 'in', $._expression)),
dynamic_cast_expression: $ => prec.left(10, seq($._expression, 'as', $.type)),
type_relational_expression: $ => prec.left(10, seq($._expression, 'is', optional('not'), $.type)),
relational_expression: $ => prec.left(10, seq($._expression, choice('<', '<=', '>=', '>'), $._expression)),
equality_expression: $ => prec.left(9, seq($._expression, choice('==', '!='), $._expression)),
bitwise_and_expression: $ => prec.left(8, seq($._expression, '&', $._expression)),
bitwise_xor_expression: $ => prec.left(7, seq($._expression, '^', $._expression)),
bitwise_or_expression: $ => prec.left(6, seq($._expression, '|', $._expression)),
logical_and_expression: $ => prec.left(5, seq($._expression, choice('&&', 'and'), $._expression)),
logical_or_expression: $ => prec.left(4, seq($._expression, choice('||', 'or'), $._expression)),
null_coalescing_expression: $ => prec.left(3, seq($._expression, '??', $._expression)),
ternary_expression: $ => prec.right(2, seq($._expression, '?', $._expression, ':', $._expression)),
_assignment_operator: $ => choice('=', '+=', '-=', '|=', '&=', '^=', '/=', '*=', '%=', '<<=', '>>='),
assignment_expression: $ => prec.right(1, seq($._expression, $._assignment_operator, $._expression)),
this_access: $ => 'this',
base_access: $ => 'base',
value_access: $ => 'value',
array_creation_expression: $ => seq(
'new',
$.type,
$.inline_array_type,
optional($.initializer)
),
object_creation_expression: $ => seq(
'new',
$.type,
optional(seq('.', $.identifier)),
'(',
optional(seq($.argument, repeat(seq(',', $.argument)))),
')',
optional($.object_initializers)
),
object_initializers: $ => seq(
'{',
optional(seq($.member_initializer, repeat(seq(',', $.member_initializer)), optional(',') /* support trailing comma */)),
'}'
),
member_initializer: $ => seq(
$.identifier,
'=',
$._expression
),
initializer: $ => seq(
'{',
optional(seq($.argument, repeat(seq(',', $.argument)), optional(',') /* support trailing comma */)),
'}'
),
boolean: $ => choice('true', 'false'),
character: $ => /'(\S+|\s)'/,
integer: $ => choice(/([1-9]\d*|0[0-7]*)[UuLl]?/, /0[xX][A-Fa-f0-9]+/),
null: $ => 'null',
real: $ => /\d+(\.\d+)?([eE][+-]?\d+)?[Ff]?/,
regex: $ => /\/([^\\\/\n]|\\[\\\/A-z0|\[\]^$?.(){}+\-*])+\/[gmxsu]*/,
string: $ => seq(
'"',
repeat(choice(
token(prec(2, /[^"%\\]+/)),
$.escape_sequence,
/\\[^abefnrtv\\'"? xXuU]/,
$.string_formatter,
/%[^$#0\- +'I\d\\.hlqLjzZtdiouxXeEfFgGaAcsCSpnm%"]/
)),
token(prec(2, '"'))
),
escape_sequence: $ => /\\([abefnrtv\\'"? ]|[0-7]{3}|[xX][A-Fa-f0-9]{2}|[uU][A-Fa-f0-9]{4,8})/,
string_formatter: $ => /%\$?[#0\- +'I]?\d*(\.\d+)?(hh?|ll?|q|L|j|z|Z|t)?[diouxXeEfFgGaAcsCSpnm%]?/,
template_string: $ => seq(
'@"',
repeat(choice(token(prec(2, /([^$"]+|\\")+/)), $.template_string_expression, '$$')),
token(prec(2, '"'))
),
template_string_expression: $ => choice(
seq('$(', $._expression, ')'),
seq('$', $.identifier)
),
verbatim_string: $=> /"""(.|\n)*"""/,
literal: $ => choice(
$.boolean,
$.null,
$.character,
$.integer,
$.real,
$.regex,
$.string,
$.template_string,
$.verbatim_string
),
type: $ => choice(
'var',
seq('void', repeat('*')),
seq(
optional('dynamic'),
optional(choice('unowned', 'owned', 'weak')),
'(',
$.type,
')',
repeat1($.array_type)
),
seq(
optional('dynamic'),
optional(choice('unowned', 'owned', 'weak')),
$.symbol,
optional($.type_arguments),
repeat('*'),
optional('?'),
repeat($.array_type)
)
),
unqualified_type: $ => seq(
$.symbol,
optional($.type_arguments)
),
type_arguments: $ => seq(
'<',
$.type,
repeat(seq(',', $.type)),
'>'
),
array_type: $ => seq(
'[',
optional($.array_size),
']',
optional('?')
),
array_size: $ => seq(
$._expression,
repeat(seq(',', $._expression))
),
member_declaration_modifier: $ => choice(
'async',
'class',
'extern',
'inline',
'static',
'abstract',
'virtual',
'override',
'new'
),
access_modifier: $ => choice(
'private',
'protected',
'internal',
'public'
),
namespace_declaration: $ => seq(
'namespace',
$.symbol,
'{',
repeat($.using_directive),
repeat($.namespace_member),
'}'
),
type_declaration_modifier: $ => choice(
'partial',
'abstract',
'extern',
'static',
'sealed'
),
class_declaration: $ => seq(
optional($.access_modifier),
repeat($.type_declaration_modifier),
'class',
$.unqualified_type,
optional(seq(':', $.type, repeat(seq(',', $.type)))),
'{',
repeat($.class_member),
'}'
),
class_member: $ => seq(
repeat($._attribute_list),
choice(
$.class_declaration,
$.interface_declaration,
$.struct_declaration,
$.enum_declaration,
$.delegate_declaration,
$.method_declaration,
$.creation_method_declaration,
$.signal_declaration,
$.field_declaration,
$.constant_declaration,
$.property_declaration,
$.constructor_declaration,
$.destructor_declaration
),
),
interface_declaration: $ => seq(
optional($.access_modifier),
repeat($.type_declaration_modifier),
'interface',
$.unqualified_type,
optional(seq(':', $.type, repeat(seq(',', $.type)))),
'{',
repeat($.interface_member),
'}'
),
interface_member: $ => seq(
repeat($._attribute_list),
choice(
$.class_declaration,
$.interface_declaration,
$.struct_declaration,
$.enum_declaration,
$.delegate_declaration,
$.method_declaration,
$.signal_declaration,
$.field_declaration,
$.constant_declaration,
$.property_declaration
)
),
struct_declaration: $ => seq(
optional($.access_modifier),
repeat($.type_declaration_modifier),
'struct',
$.unqualified_type,
optional(seq(':', $.type, repeat(seq(',', $.type)))),
'{',
repeat($.struct_member),
'}'
),
struct_member: $ => seq(
repeat($._attribute_list),
choice(
$.method_declaration,
$.creation_method_declaration,
$.field_declaration,
$.constant_declaration,
$.property_declaration
)
),
enum_declaration: $ => seq(
optional($.access_modifier),
repeat($.type_declaration_modifier),
'enum',
$.symbol,
'{',
$.enum_value,
repeat(seq(',', $.enum_value)),
optional(choice(
',', // support trailing ','
seq(';', repeat(seq(
repeat($._attribute_list),
choice($.method_declaration, $.constant_declaration)
)))
)),
'}'
),
enum_value: $ => seq(
repeat($._attribute_list),
$.identifier,
optional(seq('=', $._expression))
),
errordomain_declaration: $ => seq(
optional($.access_modifier),
repeat($.type_declaration_modifier),
'errordomain',
$.symbol,
'{',
$.errorcode,
repeat(seq(',', $.errorcode)),
optional(choice(
',', // support trailing ','
seq(';', repeat(seq(repeat($._attribute_list), $.method_declaration)))
)),
'}'
),
errorcode: $ => seq(
repeat($._attribute_list),
$.identifier,
optional(seq('=', $._expression))
),
parameter: $ => seq(
repeat($._attribute_list),
choice(
seq(
optional('params'),
optional(choice('out', 'ref')),
$.type,
$.identifier,
optional($.inline_array_type),
optional(seq('=', $._expression))
),
'...'
)
),
creation_method_declaration: $ => seq(
optional($.access_modifier),
repeat($.member_declaration_modifier),
$.symbol,
'(',
optional(seq($.parameter, repeat(seq(',', $.parameter)))),
')',
optional(seq('throws', $.type)),
optional(seq(choice('requires', 'ensures'), '(', $._expression, ')')),
choice($.block, ';')
),
delegate_declaration_modifier: $ => seq(
'async',
'class',
'extern',
'inline',
'abstract',
'virtual',
'override'
),
delegate_declaration: $ => seq(
optional($.access_modifier),
repeat($.delegate_declaration_modifier),
'delegate',
$.type,
$.symbol,
optional($.type_arguments),
'(',
optional(seq($.parameter, repeat(seq(',', $.parameter)))),
')',
optional(seq('throws', $.type)),
';'
),
method_declaration: $ => seq(
optional($.access_modifier),
repeat($.member_declaration_modifier),
$.type,
$.symbol,
optional($.type_arguments),
'(',
optional(seq($.parameter, repeat(seq(',', $.parameter)))),
')',
optional(seq('throws', $.type)),
optional(seq(choice('requires', 'ensures'), '(', $._expression, ')')),
choice($.block, ';')
),
signal_declaration_modifier: $ => choice(
'async',
'extern',
'inline',
'abstract',
'virtual',
'override',
'new'
),
signal_declaration: $ => seq(
optional($.access_modifier),
repeat($.signal_declaration_modifier),
'signal',
$.type,
$.symbol,
'(',
optional(seq($.parameter, repeat(seq(',', $.parameter)))),
')',
choice($.block, ';')
),
field_declaration: $ => seq(
optional($.access_modifier),
repeat($.member_declaration_modifier),
$.type,
$.identifier,
optional($.inline_array_type),
optional(seq('=', $._expression)),
';'
),
constant_declaration: $ => seq(
optional($.access_modifier),
repeat($.member_declaration_modifier),
'const',
$.type,
$.identifier,
optional($.inline_array_type),
optional(seq('=', $._expression)),
';'
),
inline_array_type: $ => seq('[', optional($._expression), ']'),
property_declaration: $ => seq(
optional($.access_modifier),
repeat($.member_declaration_modifier),
$.type,
$.symbol,
'{',
choice($.property_default, $.property_accessor),
repeat(choice($.property_default, $.property_accessor)),
'}'
),
property_default: $ => seq('default', '=', $._expression, ';'),
property_accessor: $ => seq(
repeat($._attribute_list),
optional($.access_modifier),
choice(
seq(optional('owned'), 'get'),
seq(optional('owned'), 'set', optional('construct')),
seq('construct', optional('set'))
),
choice(';', $.block)
),
constructor_declaration_modifier: $ => choice(
'async',
'class',
'extern',
'inline',
'static',
'abstract',
'virtual',
'override'
),
constructor_declaration: $ => seq(
repeat($.constructor_declaration_modifier),
'construct',
$.block
),
destructor_declaration: $ => seq(
repeat($.constructor_declaration_modifier),
'~',
$.identifier,
'(', ')',
$.block
),
local_declaration: $ => seq(
$.type,
$.assignment,
repeat(seq(',', $.assignment)),
';'
),
local_function_declaration: $ => seq(
$.type,
$.identifier,
'(',
optional(seq($.parameter, repeat(seq(',', $.parameter)))),
')',
$.block
),
assignment: $ => prec.dynamic(20, seq(
$.identifier,
optional($.inline_array_type),
optional(seq('=', $._expression))
)),
block: $ => seq('{', repeat(choice($._statement, $.local_declaration, $.local_function_declaration)), '}'),
_statement: $ => choice(
$.if_statement,
$._statement_without_if
),
// resolves ambiguities with 'else if'
_statement_without_if: $ => choice(
$.block,
$.empty_statement,
$.expression_statement,
$.return_statement,
$.try_statement,
$.while_statement,
$.do_statement,
$.for_statement,
$.foreach_statement,
$.break_statement,
$.continue_statement,
$.lock_statement,
$.delete_statement,
$.throw_statement,
$.yield_statement,
$.switch_statement,
$.with_statement
),
empty_statement: $ => ';',
expression_statement: $ => seq($._expression, ';'),
return_statement: $ => seq('return', optional($._expression), ';'),
if_statement: $ => seq(
'if', '(', $._expression, ')',
$._statement,
repeat($.elseif_statement),
optional($.else_statement)
),
elseif_statement: $ => seq(
'else', 'if', '(', $._expression, ')',
$._statement
),
else_statement: $ => seq(
'else',
$._statement_without_if
),
try_statement: $ => seq(
'try',
$.block,
repeat($.catch_clause),
optional($.finally_clause)
),
catch_clause: $ => seq(
'catch',
optional(seq('(', $.type, $.identifier, ')')),
$.block
),
finally_clause: $ => seq(
'finally', $.block
),
while_statement: $ => seq(
'while',
'(',
$._expression,
')',
$._statement
),
do_statement: $ => seq(
'do',
$._statement,
'while',
'(', $._expression, ')',
';'
),
for_statement: $ => seq(
'for',
'(',
optional(choice($.local_declaration, seq($._expression, ';'), ';')),
optional($._expression),
';',
optional(seq($._expression, repeat(seq(',', $._expression)))),
')',
$._statement
),
foreach_statement: $ => seq(
'foreach',
'(',
$.type,
$.identifier,
'in',
$._expression,
')',
$._statement
),
break_statement: $ => seq('break', ';'),
continue_statement: $ => seq('continue', ';'),
lock_statement: $ => seq(
'lock', '(', $._expression, ')',
$._statement
),
delete_statement: $ => seq(
'delete', $._expression, ';'
),
throw_statement: $ => seq(
'throw', $._expression, ';'
),
yield_statement: $ => seq(
'yield',
optional(seq('return', $._expression)),
';'
),
switch_statement: $ => seq(
'switch', '(', $._expression, ')',
'{',
repeat($.switch_section),
'}'
),
switch_section: $ => seq(
choice(
seq('case', $._expression),
'default'
),
':',
repeat(choice($._statement, $.local_declaration))
),
with_statement: $ => seq(
'with', '(', $._expression, ')',
$._statement
),
// --- preprocessor
_preprocessor_directive_start: $ => /#[\t ]*/,
_preprocessor_statement: $ => seq(
$._preprocessor_directive_start,
choice(
$.if_directive,
$.elif_directive,
$.else_directive,
$.endif_directive
)
),
if_directive: $ => seq('if', field('expression', $._preprocessor_expression)),
elif_directive: $ => seq('elif', field('expression', $._preprocessor_expression)),
else_directive: $ => 'else',
endif_directive: $ => 'endif',
_preprocessor_expression: $ => choice(
seq('(', $._preprocessor_contained_expression, ')'),
$.identifier,
$.literal
),
_preprocessor_contained_expression: $ => choice(
seq('(', $._preprocessor_contained_expression, ')'),
$.identifier,
$.literal,
prec.right(4, seq('!', $._preprocessor_expression)),
prec.left(3, seq($._preprocessor_expression, choice('==', '!='), $._preprocessor_expression)),
prec.left(2, seq($._preprocessor_expression, '&&', $._preprocessor_expression)),
prec.left(1, seq($._preprocessor_expression, '||', $._preprocessor_expression)),
)
},
conflicts: $ => [
[$.member_declaration_modifier, $.class_declaration], // because both can start with 'class'
[$.member_declaration_modifier, $.type_declaration_modifier], // because both share 'extern'
[$.member_declaration_modifier, $.object_creation_expression], // because OCEs can appear in the main block
[$.member_declaration_modifier, $.signal_declaration_modifier], // both can start with 'new'
[$.member_declaration_modifier,
$.type_declaration_modifier,
$.signal_declaration_modifier], // ambiguity between all three
[$.member_declaration_modifier, $.delegate_declaration_modifier], // both can start with 'new'
[$.array_creation_expression, $.member_declaration_modifier], // because both can start with 'new ('
[$.array_creation_expression,
$.object_creation_expression,
$.member_declaration_modifier], // because these all start with 'new'
[$.member_declaration_modifier,
$.delegate_declaration_modifier,
$.constructor_declaration_modifier], // these all start with 'class'
[$.member_declaration_modifier,
$.signal_declaration_modifier,
$.constructor_declaration_modifier], // these all start with 'class'
[$.member_declaration_modifier,
$.constructor_declaration_modifier], // these start with 'class'
[$.member_declaration_modifier,
$.type_declaration_modifier,
$.constructor_declaration_modifier], // these start with 'class'
[$.member_declaration_modifier,
$.type_declaration_modifier,
$.signal_declaration_modifier,
$.constructor_declaration_modifier], // these start with 'class'
[$.symbol, $.member_access_expression], // disambiguate member access and static cast expressions
[$.symbol, $.member_access_expression, $.lambda_expression], // head of lambda expression may be head of symbol or MA
[$.type], // disambiguate between 'X as <type *> ...' and '(X as <type>)* ...'
[$.array_type], // when 'X[]? ...' could also be '(X[]) ? ...'
[$.symbol, $.type], // for object creation expression
[$._expression, $.method_call_expression], // 'X <' may be start of comparison or method call
[$._contained_expression, $.method_call_expression], // for ambiguity because of contained expressions
[$._expression, $.element_access_expression], // because EAEs have a prefix that is a member access
[$.element_access_expression], // for ambiguity because of contained expressions
[$.initializer, $.block], // because {} is ambiguous in statement-expression contexts
[$.if_statement], // because of ambiguity with nested if statements
[$._expression, $._left_contained_expression]
],
extras: $ => [
/\s|\\\r?\n/,
$.comment,
$._preprocessor_statement
],
});