@willbooster/tree-sitter-kotlin 1.0.0 → 1.2.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
@@ -18,10 +18,11 @@ const PREC = {
18
18
  UNARY: 14,
19
19
  };
20
20
 
21
+ // oxlint-disable-next-line unicorn/prefer-module -- This package is CommonJS, so tree-sitter loads grammar.js as CommonJS.
21
22
  module.exports = grammar({
22
23
  name: 'kotlin',
23
24
 
24
- conflicts: $ => [
25
+ conflicts: ($) => [
25
26
  [$.class_body, $.enum_class_body],
26
27
 
27
28
  [$.binary_expression, $.call_expression],
@@ -65,13 +66,9 @@ module.exports = grammar({
65
66
  [$._receiver_type],
66
67
  ],
67
68
 
68
- extras: $ => [
69
- /\s/,
70
- $.line_comment,
71
- $.block_comment,
72
- ],
69
+ extras: ($) => [/\s/, $.line_comment, $.block_comment],
73
70
 
74
- externals: $ => [
71
+ externals: ($) => [
75
72
  $._semi,
76
73
  $._class_member_semi,
77
74
  $.block_comment,
@@ -87,18 +84,15 @@ module.exports = grammar({
87
84
  '$',
88
85
  ],
89
86
 
90
- inline: $ => [
91
- $._statements,
92
- $._identifier,
93
- ],
87
+ inline: ($) => [$._statements, $._identifier],
94
88
 
95
- precedences: $ => [
89
+ precedences: ($) => [
96
90
  [$.block, $.lambda_literal],
97
91
  [$.function_type, $.nullable_type],
98
92
  [$.function_type, $.non_nullable_type],
99
93
  ],
100
94
 
101
- supertypes: $ => [
95
+ supertypes: ($) => [
102
96
  $.class_member_declaration,
103
97
  $.declaration,
104
98
  $.expression,
@@ -107,574 +101,392 @@ module.exports = grammar({
107
101
  $.statement,
108
102
  ],
109
103
 
110
- word: $ => $.identifier,
104
+ word: ($) => $.identifier,
111
105
 
112
106
  rules: {
113
- source_file: $ => seq(
114
- optional($.shebang),
115
- repeat($.file_annotation),
116
- optional($.package_header),
117
- repeat($.import),
118
- repeat(seq($.statement, $._semi)),
119
- ),
120
-
121
- file_annotation: $ => seq(
122
- '@',
123
- 'file',
124
- ':',
125
- choice(
126
- seq('[', repeat1($._unescaped_annotation), ']'),
127
- $._unescaped_annotation,
107
+ source_file: ($) =>
108
+ seq(
109
+ optional($.shebang),
110
+ repeat($.file_annotation),
111
+ optional($.package_header),
112
+ repeat($.import),
113
+ repeat(seq($.statement, $._semi))
114
+ ),
115
+
116
+ file_annotation: ($) =>
117
+ seq('@', 'file', ':', choice(seq('[', repeat1($._unescaped_annotation), ']'), $._unescaped_annotation), $._semi),
118
+
119
+ package_header: ($) => seq('package', $.qualified_identifier, optional(';')),
120
+
121
+ import: ($) =>
122
+ seq('import', $.qualified_identifier, optional(choice(seq('.', '*'), seq('as', $.identifier))), optional(';')),
123
+
124
+ declaration: ($) =>
125
+ choice($.class_declaration, $.object_declaration, $.function_declaration, $.property_declaration, $.type_alias),
126
+
127
+ class_declaration: ($) =>
128
+ prec.right(
129
+ seq(
130
+ optional($.modifiers),
131
+ choice('class', seq(optional('fun'), 'interface')),
132
+ field('name', $.identifier),
133
+ optional($.type_parameters),
134
+ optional($.primary_constructor),
135
+ optional(seq(':', $.delegation_specifiers)),
136
+ optional($.type_constraints),
137
+ optional(choice($.class_body, $.enum_class_body))
138
+ )
128
139
  ),
129
- $._semi,
130
-
131
- ),
132
-
133
- package_header: $ => seq(
134
- 'package',
135
- $.qualified_identifier,
136
- optional(';'),
137
- ),
138
-
139
- import: $ => seq(
140
- 'import',
141
- $.qualified_identifier,
142
- optional(choice(
143
- seq('.', '*'),
144
- seq('as', $.identifier),
145
- )),
146
- optional(';'),
147
- ),
148
-
149
- declaration: $ => choice(
150
- $.class_declaration,
151
- $.object_declaration,
152
- $.function_declaration,
153
- $.property_declaration,
154
- $.type_alias,
155
- ),
156
-
157
- class_declaration: $ => prec.right(seq(
158
- optional($.modifiers),
159
- choice('class', seq(optional('fun'), 'interface')),
160
- field('name', $.identifier),
161
- optional($.type_parameters),
162
- optional($.primary_constructor),
163
- optional(seq(':', $.delegation_specifiers)),
164
- optional($.type_constraints),
165
- optional(choice($.class_body, $.enum_class_body)),
166
- )),
167
-
168
- object_declaration: $ => prec.right(seq(
169
- optional($.modifiers),
170
- 'object',
171
- field('name', $.identifier),
172
- optional(seq(':', $.delegation_specifiers)),
173
- optional($.class_body),
174
- )),
175
-
176
- property_declaration: $ => prec.right(seq(
177
- optional($.modifiers),
178
- choice('val', 'var'),
179
- optional($.type_parameters),
180
- optional(seq($._receiver_type, optional('.'))),
181
- choice($.variable_declaration, $.multi_variable_declaration),
182
- optional($.type_constraints),
183
- optional(choice(
184
- seq('=', $.expression),
185
- $.property_delegate,
186
- )),
187
- optional(';'),
188
- optional(choice(
189
- seq($.getter, optional($.setter)),
190
- seq($.setter, optional($.getter)),
191
- )),
192
- )),
193
-
194
- type_alias: $ => prec.right(seq(
195
- optional($.modifiers),
196
- 'typealias',
197
- field('type', $.identifier),
198
- optional($.type_parameters),
199
- '=',
200
- $.type,
201
- )),
202
-
203
- companion_object: $ => seq(
204
- optional($.modifiers),
205
- 'companion',
206
- 'object',
207
- optional(field('name', $.identifier)),
208
- optional(seq(':', $.delegation_specifiers)),
209
- optional($.class_body),
210
- ),
211
-
212
- anonymous_initializer: $ => seq('init', $.block),
213
-
214
- secondary_constructor: $ => seq(
215
- optional($.modifiers),
216
- 'constructor',
217
- $.function_value_parameters,
218
- optional(seq(':', $.constructor_delegation_call)),
219
- optional($.block),
220
- ),
221
-
222
- constructor_delegation_call: $ => seq(choice('this', 'super'), $.value_arguments),
223
-
224
- type_parameters: $ => seq('<', commaSep1($.type_parameter), '>'),
225
-
226
- type_parameter: $ => seq(
227
- optional($.type_parameter_modifiers),
228
- $.identifier,
229
- optional(seq(':', $.type)),
230
- ),
231
-
232
- primary_constructor: $ => seq(
233
- optional(seq(
140
+
141
+ object_declaration: ($) =>
142
+ prec.right(
143
+ seq(
144
+ optional($.modifiers),
145
+ 'object',
146
+ field('name', $.identifier),
147
+ optional(seq(':', $.delegation_specifiers)),
148
+ optional($.class_body)
149
+ )
150
+ ),
151
+
152
+ property_declaration: ($) =>
153
+ prec.right(
154
+ seq(
155
+ optional($.modifiers),
156
+ choice('val', 'var'),
157
+ optional($.type_parameters),
158
+ optional(seq($._receiver_type, optional('.'))),
159
+ choice($.variable_declaration, $.multi_variable_declaration),
160
+ optional($.type_constraints),
161
+ optional(choice(seq('=', $.expression), $.property_delegate)),
162
+ optional(';'),
163
+ optional(choice(seq($.getter, optional($.setter)), seq($.setter, optional($.getter))))
164
+ )
165
+ ),
166
+
167
+ type_alias: ($) =>
168
+ prec.right(
169
+ seq(optional($.modifiers), 'typealias', field('type', $.identifier), optional($.type_parameters), '=', $.type)
170
+ ),
171
+
172
+ companion_object: ($) =>
173
+ seq(
174
+ optional($.modifiers),
175
+ 'companion',
176
+ 'object',
177
+ optional(field('name', $.identifier)),
178
+ optional(seq(':', $.delegation_specifiers)),
179
+ optional($.class_body)
180
+ ),
181
+
182
+ anonymous_initializer: ($) => seq('init', $.block),
183
+
184
+ secondary_constructor: ($) =>
185
+ seq(
234
186
  optional($.modifiers),
235
187
  'constructor',
236
- )),
237
- $.class_parameters,
238
- ),
239
-
240
- class_parameters: $ => seq(
241
- '(',
242
- optionalCommaSep1($.class_parameter),
243
- ')',
244
- ),
245
-
246
- class_parameter: $ => seq(
247
- optional($.modifiers),
248
- optional(choice('val', 'var')),
249
- $._identifier,
250
- ':', $.type,
251
- optional(seq('=', $.expression)),
252
- ),
253
-
254
- type_constraints: $ => prec.right(seq(
255
- 'where',
256
- commaSep1($.type_constraint),
257
- )),
258
-
259
- type_constraint: $ => prec.right(seq(
260
- $.identifier,
261
- ':',
262
- $.type,
263
- )),
264
-
265
- constructor_invocation: $ => seq($.type, $.value_arguments),
266
-
267
- function_declaration: $ => prec.right(1, seq(
268
- optional($.modifiers),
269
- 'fun',
270
- optional($.type_parameters),
271
- optional(seq($._receiver_type, optional('.'))),
272
- field('name', $._identifier),
273
- $.function_value_parameters,
274
- optional(seq(':', $.type)),
275
- optional($.type_constraints),
276
- optional($.function_body),
277
- )),
278
-
279
- function_value_parameters: $ => seq(
280
- '(',
281
- optionalCommaSep1(seq(
282
- optional($.parameter_modifiers),
283
- $.parameter,
284
- optional(seq('=', $.expression)),
285
- )),
286
- ')',
287
- ),
288
-
289
- parameter: $ => seq($._identifier, ':', $.type),
290
-
291
- delegation_specifiers: $ => commaSep1($.delegation_specifier),
292
-
293
- delegation_specifier: $ => prec.right(seq(
294
- repeat($.annotation),
295
- choice(
296
- $.constructor_invocation,
297
- $.explicit_delegation,
188
+ $.function_value_parameters,
189
+ optional(seq(':', $.constructor_delegation_call)),
190
+ optional($.block)
191
+ ),
192
+
193
+ constructor_delegation_call: ($) => seq(choice('this', 'super'), $.value_arguments),
194
+
195
+ type_parameters: ($) => seq('<', commaSep1($.type_parameter), '>'),
196
+
197
+ type_parameter: ($) => seq(optional($.type_parameter_modifiers), $.identifier, optional(seq(':', $.type))),
198
+
199
+ primary_constructor: ($) => seq(optional(seq(optional($.modifiers), 'constructor')), $.class_parameters),
200
+
201
+ class_parameters: ($) => seq('(', optionalCommaSep1($.class_parameter), ')'),
202
+
203
+ class_parameter: ($) =>
204
+ seq(
205
+ optional($.modifiers),
206
+ optional(choice('val', 'var')),
207
+ $._identifier,
208
+ ':',
298
209
  $.type,
210
+ optional(seq('=', $.expression))
299
211
  ),
300
- )),
301
-
302
- variable_declaration: $ => prec(1, seq(
303
- repeat($.annotation),
304
- $._identifier,
305
- optional(seq(':', $.type)),
306
- )),
307
-
308
- multi_variable_declaration: $ => seq(
309
- '(',
310
- optionalCommaSep1($.variable_declaration),
311
- ')',
312
- ),
313
-
314
- property_delegate: $ => seq(
315
- 'by',
316
- $.expression,
317
- ),
318
-
319
- explicit_delegation: $ => seq(
320
- $.type,
321
- 'by',
322
- $.primary_expression,
323
- ),
324
-
325
- getter: $ => prec.right(seq(
326
- optional($.modifiers),
327
- 'get',
328
- optional(seq(
329
- '(',
330
- ')',
331
- optional(seq(':', $.type)),
332
- $.function_body,
333
- )),
334
- )),
335
-
336
- setter: $ => prec.right(seq(
337
- optional($.modifiers),
338
- 'set',
339
- optional(seq(
340
- '(',
341
- optional($.parameter_modifiers),
342
- $.identifier,
343
- optional(seq(':', $.type)),
344
- optional(seq('=', $.expression)),
345
- ')',
346
- optional(seq(':', $.type)),
347
- $.function_body,
348
- )),
349
- )),
350
-
351
- function_body: $ => choice(
352
- $.block,
353
- seq('=', $.expression),
354
- ),
355
-
356
- block: $ => seq(
357
- '{',
358
- optional($._statements),
359
- '}',
360
- ),
361
-
362
- for_statement: $ => prec.right(seq(
363
- optional($.label),
364
- 'for',
365
- '(',
366
- repeat($.annotation),
367
- choice($.variable_declaration, $.multi_variable_declaration),
368
- 'in',
369
- $.expression,
370
- ')',
371
- optional(choice($.block, $.statement)),
372
- )),
373
-
374
- while_statement: $ => prec.right(seq(
375
- optional($.label),
376
- 'while',
377
- '(',
378
- field('condition', $.expression),
379
- ')',
380
- optional(choice($.block, $.statement, ';')),
381
- )),
382
-
383
- do_while_statement: $ => prec.right(seq(
384
- optional($.label),
385
- 'do',
386
- optional(choice($.block, $.statement, ';')),
387
- 'while',
388
- '(',
389
- field('condition', $.expression),
390
- ')',
391
- )),
392
-
393
- class_body: $ => seq(
394
- '{',
395
- repeat(seq($.class_member_declaration, $._class_member_semi)),
396
- '}',
397
- ),
398
-
399
- class_member_declaration: $ => choice(
400
- $.declaration,
401
- $.companion_object,
402
- $.anonymous_initializer,
403
- $.secondary_constructor,
404
- ),
405
-
406
- enum_class_body: $ => seq(
407
- '{',
408
- optionalCommaSep1($.enum_entry),
409
- optional(seq(
410
- ';',
411
- repeat(seq($.class_member_declaration, $._class_member_semi)),
412
- )),
413
- '}',
414
- ),
415
-
416
- enum_entry: $ => seq(
417
- optional($.modifiers),
418
- $.identifier,
419
- optional($.value_arguments),
420
- optional($.class_body),
421
- ),
422
-
423
- value_arguments: $ => seq(
424
- '(',
425
- optionalCommaSep1($.value_argument),
426
- ')',
427
- ),
428
-
429
- value_argument: $ => seq(
430
- optional(seq($._identifier, '=')),
431
- optional('*'),
432
- $.expression,
433
- ),
434
-
435
- _statements: $ => seq(
436
- $.statement,
437
- repeat(seq($._semi, $.statement)),
438
- optional($._semi),
439
- ),
440
-
441
- statement: $ => choice(
442
- $.declaration,
443
- $.assignment,
444
- $.for_statement,
445
- $.while_statement,
446
- $.do_while_statement,
447
- $.expression,
448
- ),
449
-
450
- modifiers: $ => prec.right(repeat1(choice(
451
- $.annotation,
452
- $.class_modifier,
453
- $.member_modifier,
454
- $.function_modifier,
455
- $.property_modifier,
456
- $.visibility_modifier,
457
- $.inheritance_modifier,
458
- $.parameter_modifier,
459
- $.platform_modifier,
460
- ))),
461
-
462
- class_modifier: _ => choice(
463
- 'enum',
464
- 'sealed',
465
- 'annotation',
466
- 'data',
467
- 'inner',
468
- 'value',
469
- ),
470
-
471
- function_modifier: _ => prec.right(choice(
472
- 'tailrec',
473
- 'operator',
474
- 'infix',
475
- 'inline',
476
- 'external',
477
- 'suspend',
478
- )),
479
-
480
- property_modifier: _ => 'const',
481
-
482
- visibility_modifier: _ => choice(
483
- 'public',
484
- 'private',
485
- 'protected',
486
- 'internal',
487
- ),
488
-
489
- inheritance_modifier: _ => choice(
490
- 'abstract',
491
- 'final',
492
- 'open',
493
- ),
494
-
495
- member_modifier: _ => choice(
496
- 'override',
497
- 'lateinit',
498
- ),
499
-
500
- parameter_modifiers: $ => repeat1(choice($.annotation, $.parameter_modifier)),
501
-
502
- parameter_modifier: _ => choice(
503
- 'vararg',
504
- 'noinline',
505
- 'crossinline',
506
- ),
507
-
508
- reification_modifier: _ => 'reified',
509
-
510
- platform_modifier: _ => choice(
511
- 'expect',
512
- 'actual',
513
- ),
514
-
515
- type_modifiers: $ => prec.right(
516
- repeat1(choice($.annotation, 'suspend')),
517
- ),
518
-
519
- annotation: $ => choice(
212
+
213
+ type_constraints: ($) => prec.right(seq('where', commaSep1($.type_constraint))),
214
+
215
+ type_constraint: ($) => prec.right(seq($.identifier, ':', $.type)),
216
+
217
+ constructor_invocation: ($) => seq($.type, $.value_arguments),
218
+
219
+ function_declaration: ($) =>
220
+ prec.right(
221
+ 1,
222
+ seq(
223
+ optional($.modifiers),
224
+ 'fun',
225
+ optional($.type_parameters),
226
+ optional(seq($._receiver_type, optional('.'))),
227
+ field('name', $._identifier),
228
+ $.function_value_parameters,
229
+ optional(seq(':', $.type)),
230
+ optional($.type_constraints),
231
+ optional($.function_body)
232
+ )
233
+ ),
234
+
235
+ function_value_parameters: ($) =>
520
236
  seq(
521
- '@',
522
- optional($.use_site_target),
523
- $._unescaped_annotation,
237
+ '(',
238
+ optionalCommaSep1(seq(optional($.parameter_modifiers), $.parameter, optional(seq('=', $.expression)))),
239
+ ')'
240
+ ),
241
+
242
+ parameter: ($) => seq($._identifier, ':', $.type),
243
+
244
+ delegation_specifiers: ($) => commaSep1($.delegation_specifier),
245
+
246
+ delegation_specifier: ($) =>
247
+ prec.right(seq(repeat($.annotation), choice($.constructor_invocation, $.explicit_delegation, $.type))),
248
+
249
+ variable_declaration: ($) => prec(1, seq(repeat($.annotation), $._identifier, optional(seq(':', $.type)))),
250
+
251
+ multi_variable_declaration: ($) => seq('(', optionalCommaSep1($.variable_declaration), ')'),
252
+
253
+ property_delegate: ($) => seq('by', $.expression),
254
+
255
+ explicit_delegation: ($) => seq($.type, 'by', $.primary_expression),
256
+
257
+ getter: ($) =>
258
+ prec.right(
259
+ seq(optional($.modifiers), 'get', optional(seq('(', ')', optional(seq(':', $.type)), $.function_body)))
260
+ ),
261
+
262
+ setter: ($) =>
263
+ prec.right(
264
+ seq(
265
+ optional($.modifiers),
266
+ 'set',
267
+ optional(
268
+ seq(
269
+ '(',
270
+ optional($.parameter_modifiers),
271
+ $.identifier,
272
+ optional(seq(':', $.type)),
273
+ optional(seq('=', $.expression)),
274
+ ')',
275
+ optional(seq(':', $.type)),
276
+ $.function_body
277
+ )
278
+ )
279
+ )
280
+ ),
281
+
282
+ function_body: ($) => choice($.block, seq('=', $.expression)),
283
+
284
+ block: ($) => seq('{', optional($._statements), '}'),
285
+
286
+ for_statement: ($) =>
287
+ prec.right(
288
+ seq(
289
+ optional($.label),
290
+ 'for',
291
+ '(',
292
+ repeat($.annotation),
293
+ choice($.variable_declaration, $.multi_variable_declaration),
294
+ 'in',
295
+ $.expression,
296
+ ')',
297
+ optional(field('body', choice($.block, $.statement)))
298
+ )
299
+ ),
300
+
301
+ while_statement: ($) =>
302
+ prec.right(
303
+ seq(
304
+ optional($.label),
305
+ 'while',
306
+ '(',
307
+ field('condition', $.expression),
308
+ ')',
309
+ optional(choice(field('body', choice($.block, $.statement)), ';'))
310
+ )
311
+ ),
312
+
313
+ do_while_statement: ($) =>
314
+ prec.right(
315
+ seq(
316
+ optional($.label),
317
+ 'do',
318
+ optional(choice(field('body', choice($.block, $.statement)), ';')),
319
+ 'while',
320
+ '(',
321
+ field('condition', $.expression),
322
+ ')'
323
+ )
524
324
  ),
325
+
326
+ class_body: ($) => seq('{', repeat(seq($.class_member_declaration, $._class_member_semi)), '}'),
327
+
328
+ class_member_declaration: ($) =>
329
+ choice($.declaration, $.companion_object, $.anonymous_initializer, $.secondary_constructor),
330
+
331
+ enum_class_body: ($) =>
525
332
  seq(
526
- '@',
527
- optional($.use_site_target),
528
- '[',
529
- repeat1($._unescaped_annotation),
530
- ']',
333
+ '{',
334
+ optionalCommaSep1($.enum_entry),
335
+ optional(seq(';', repeat(seq($.class_member_declaration, $._class_member_semi)))),
336
+ '}'
531
337
  ),
532
- ),
533
-
534
- use_site_target: _ => seq(
535
- choice('field', 'property', 'get', 'set', 'receiver', 'param', 'setparam', 'delegate'),
536
- ':',
537
- ),
538
-
539
- _unescaped_annotation: $ => choice(
540
- $.constructor_invocation,
541
- $.type,
542
- ),
543
-
544
- type: $ => choice(
545
- $.user_type,
546
- $.nullable_type,
547
- $.function_type,
548
- $.non_nullable_type,
549
- $.parenthesized_type,
550
- 'dynamic',
551
- ),
552
-
553
- user_type: $ => seq(
554
- optional($.type_modifiers),
555
- sep1(
556
- $._simple_user_type,
557
- '.',
338
+
339
+ enum_entry: ($) => seq(optional($.modifiers), $.identifier, optional($.value_arguments), optional($.class_body)),
340
+
341
+ value_arguments: ($) => seq('(', optionalCommaSep1($.value_argument), ')'),
342
+
343
+ value_argument: ($) => seq(optional(seq($._identifier, '=')), optional('*'), $.expression),
344
+
345
+ _statements: ($) => seq($.statement, repeat(seq($._semi, $.statement)), optional($._semi)),
346
+
347
+ statement: ($) =>
348
+ choice($.declaration, $.assignment, $.for_statement, $.while_statement, $.do_while_statement, $.expression),
349
+
350
+ modifiers: ($) =>
351
+ prec.right(
352
+ repeat1(
353
+ choice(
354
+ $.annotation,
355
+ $.class_modifier,
356
+ $.member_modifier,
357
+ $.function_modifier,
358
+ $.property_modifier,
359
+ $.visibility_modifier,
360
+ $.inheritance_modifier,
361
+ $.parameter_modifier,
362
+ $.platform_modifier
363
+ )
364
+ )
558
365
  ),
559
- ),
560
-
561
- _simple_user_type: $ => prec.right(seq($._identifier, optional($.type_arguments))),
562
-
563
- nullable_type: $ => seq(
564
- optional($.type_modifiers),
565
- $.type,
566
- '?',
567
- ),
568
-
569
- non_nullable_type: $ => prec.right(seq(
570
- optional($.type_modifiers),
571
- $.type,
572
- '&',
573
- optional($.type_modifiers),
574
- $.type,
575
- )),
576
-
577
- _receiver_type: $ => seq(
578
- optional($.type_modifiers),
366
+
367
+ class_modifier: () => choice('enum', 'sealed', 'annotation', 'data', 'inner', 'value'),
368
+
369
+ function_modifier: () => prec.right(choice('tailrec', 'operator', 'infix', 'inline', 'external', 'suspend')),
370
+
371
+ property_modifier: () => 'const',
372
+
373
+ visibility_modifier: () => choice('public', 'private', 'protected', 'internal'),
374
+
375
+ inheritance_modifier: () => choice('abstract', 'final', 'open'),
376
+
377
+ member_modifier: () => choice('override', 'lateinit'),
378
+
379
+ parameter_modifiers: ($) => repeat1(choice($.annotation, $.parameter_modifier)),
380
+
381
+ parameter_modifier: () => choice('vararg', 'noinline', 'crossinline'),
382
+
383
+ reification_modifier: () => 'reified',
384
+
385
+ platform_modifier: () => choice('expect', 'actual'),
386
+
387
+ type_modifiers: ($) => prec.right(repeat1(choice($.annotation, 'suspend'))),
388
+
389
+ annotation: ($) =>
579
390
  choice(
580
- $.user_type,
581
- 'dynamic',
582
- $.parenthesized_type,
583
- $.nullable_type,
391
+ seq('@', optional($.use_site_target), $._unescaped_annotation),
392
+ seq('@', optional($.use_site_target), '[', repeat1($._unescaped_annotation), ']')
584
393
  ),
585
- ),
586
-
587
- type_arguments: $ => seq('<', commaSep1($.type_projection), '>'),
588
-
589
- type_projection: $ => choice(
590
- seq(repeat($.variance_modifier), $.type),
591
- '*',
592
- ),
593
-
594
- function_type: $ => seq(
595
- optional($.type_modifiers),
596
- optional(seq($._receiver_type, '.')),
597
- $.function_type_parameters,
598
- '->',
599
- $.type,
600
- ),
601
-
602
- function_type_parameters: $ => seq(
603
- '(',
604
- optionalCommaSep1(choice($.parameter, $.type)),
605
- ')',
606
- ),
607
-
608
- parenthesized_type: $ => seq('(', $.type, ')'),
609
-
610
- assignment: $ => seq(
611
- field('left', $.expression),
612
- field('operator', choice(
613
- '=',
614
- '+=',
615
- '-=',
616
- '*=',
617
- '/=',
618
- '%=',
619
- )),
620
- field('right', $.expression),
621
- ),
622
-
623
- expression: $ => choice(
624
- $.primary_expression,
625
- $.index_expression,
626
- $.return_expression,
627
- $.throw_expression,
628
- ),
629
-
630
- primary_expression: $ => choice(
631
- $._identifier,
632
- $.string_literal,
633
- $.multiline_string_literal,
634
- $.character_literal,
635
- $.number_literal,
636
- $.float_literal,
637
- $.object_literal,
638
- $.collection_literal,
639
- $.navigation_expression,
640
- $.binary_expression,
641
- $.unary_expression,
642
- $.annotated_expression,
643
- $.labeled_expression,
644
- $.call_expression,
645
- $.in_expression,
646
- $.is_expression,
647
- $.as_expression,
648
- $.spread_expression,
649
- $.infix_expression,
650
- $.range_expression,
651
- $.if_expression,
652
- $.parenthesized_expression,
653
- $.this_expression,
654
- $.super_expression,
655
- $.when_expression,
656
- $.try_expression,
657
- $.callable_reference,
658
- $.lambda_literal,
659
- $.anonymous_function,
660
- ),
661
-
662
- unary_expression: $ => prec.left(PREC.UNARY, choice(
394
+
395
+ use_site_target: () =>
396
+ seq(choice('field', 'property', 'get', 'set', 'receiver', 'param', 'setparam', 'delegate'), ':'),
397
+
398
+ _unescaped_annotation: ($) => choice($.constructor_invocation, $.type),
399
+
400
+ type: ($) =>
401
+ choice($.user_type, $.nullable_type, $.function_type, $.non_nullable_type, $.parenthesized_type, 'dynamic'),
402
+
403
+ user_type: ($) => seq(optional($.type_modifiers), sep1($._simple_user_type, '.')),
404
+
405
+ _simple_user_type: ($) => prec.right(seq($._identifier, optional($.type_arguments))),
406
+
407
+ nullable_type: ($) => seq(optional($.type_modifiers), $.type, '?'),
408
+
409
+ non_nullable_type: ($) =>
410
+ prec.right(seq(optional($.type_modifiers), $.type, '&', optional($.type_modifiers), $.type)),
411
+
412
+ _receiver_type: ($) =>
413
+ seq(optional($.type_modifiers), choice($.user_type, 'dynamic', $.parenthesized_type, $.nullable_type)),
414
+
415
+ type_arguments: ($) => seq('<', commaSep1($.type_projection), '>'),
416
+
417
+ type_projection: ($) => choice(seq(repeat($.variance_modifier), $.type), '*'),
418
+
419
+ function_type: ($) =>
420
+ seq(optional($.type_modifiers), optional(seq($._receiver_type, '.')), $.function_type_parameters, '->', $.type),
421
+
422
+ function_type_parameters: ($) => seq('(', optionalCommaSep1(choice($.parameter, $.type)), ')'),
423
+
424
+ parenthesized_type: ($) => seq('(', $.type, ')'),
425
+
426
+ assignment: ($) =>
663
427
  seq(
664
- field('operator', choice('++', '--', '+', '-', '!')),
665
- field('argument', $.expression),
428
+ field('left', $.expression),
429
+ field('operator', choice('=', '+=', '-=', '*=', '/=', '%=')),
430
+ field('right', $.expression)
666
431
  ),
667
- seq(
668
- field('argument', $.expression),
669
- field('operator', choice('++', '--', '!!')),
432
+
433
+ expression: ($) =>
434
+ choice(
435
+ $.primary_expression,
436
+ $.index_expression,
437
+ $.return_expression,
438
+ $.throw_expression,
439
+ $.continue_expression,
440
+ $.break_expression
441
+ ),
442
+
443
+ primary_expression: ($) =>
444
+ choice(
445
+ $._identifier,
446
+ $.string_literal,
447
+ $.multiline_string_literal,
448
+ $.character_literal,
449
+ $.number_literal,
450
+ $.float_literal,
451
+ $.object_literal,
452
+ $.collection_literal,
453
+ $.navigation_expression,
454
+ $.binary_expression,
455
+ $.unary_expression,
456
+ $.annotated_expression,
457
+ $.labeled_expression,
458
+ $.call_expression,
459
+ $.in_expression,
460
+ $.is_expression,
461
+ $.as_expression,
462
+ $.spread_expression,
463
+ $.infix_expression,
464
+ $.range_expression,
465
+ $.if_expression,
466
+ $.parenthesized_expression,
467
+ $.this_expression,
468
+ $.super_expression,
469
+ $.when_expression,
470
+ $.try_expression,
471
+ $.callable_reference,
472
+ $.lambda_literal,
473
+ $.anonymous_function
474
+ ),
475
+
476
+ unary_expression: ($) =>
477
+ prec.left(
478
+ PREC.UNARY,
479
+ choice(
480
+ seq(field('operator', choice('++', '--', '+', '-', '!')), field('argument', $.expression)),
481
+ seq(field('argument', $.expression), field('operator', choice('++', '--', '!!')))
482
+ )
670
483
  ),
671
- )),
672
484
 
673
- annotated_expression: $ => seq($.annotation, $.expression),
485
+ annotated_expression: ($) => seq($.annotation, $.expression),
674
486
 
675
- labeled_expression: $ => seq($.label, $.expression),
487
+ labeled_expression: ($) => seq($.label, $.expression),
676
488
 
677
- binary_expression: $ => {
489
+ binary_expression: ($) => {
678
490
  const table = [
679
491
  ['+', PREC.ADD],
680
492
  ['-', PREC.ADD],
@@ -694,299 +506,191 @@ module.exports = grammar({
694
506
  ['?:', PREC.ELVIS],
695
507
  ];
696
508
 
697
- return choice(...table.map(([operator, precedence]) => {
698
- return prec.left(precedence, seq(
699
- field('left', $.expression),
700
- // @ts-ignore
701
- field('operator', operator),
702
- field('right', $.expression),
703
- ));
704
- }));
509
+ return choice(
510
+ ...table.map(([operator, precedence]) => {
511
+ return prec.left(
512
+ precedence,
513
+ seq(
514
+ field('left', $.expression),
515
+ // @ts-ignore
516
+ field('operator', operator),
517
+ field('right', $.expression)
518
+ )
519
+ );
520
+ })
521
+ );
705
522
  },
706
523
 
707
- in_expression: $ => prec.left(PREC.IN, seq(
708
- field('left', $.expression),
709
- choice('in', '!in'),
710
- field('right', $.expression),
711
- )),
712
-
713
- is_expression: $ => prec.left(PREC.IN, seq(
714
- field('left', $.expression),
715
- choice('is', alias($._not_is, '!is')),
716
- field('right', $.type),
717
- )),
718
-
719
- as_expression: $ => prec.left(PREC.AS, seq(
720
- field('left', $.expression),
721
- choice('as', 'as?'),
722
- field('right', $.type),
723
- )),
724
-
725
- spread_expression: $ => prec(PREC.SPREAD, seq('*', $.expression)),
726
-
727
- range_expression: $ => prec.left(PREC.RANGE, seq(
728
- $.expression,
729
- choice('..', '..<'),
730
- $.expression,
731
- )),
732
-
733
- infix_expression: $ => prec.left(PREC.INFIX, seq(
734
- $.expression,
735
- $.identifier,
736
- $.expression,
737
- )),
738
-
739
- call_expression: $ => prec.left(PREC.CALL, seq(
740
- $.expression,
741
- optional($.type_arguments),
742
- choice(
743
- $.value_arguments,
744
- seq(optional($.value_arguments), $.annotated_lambda),
524
+ in_expression: ($) =>
525
+ prec.left(PREC.IN, seq(field('left', $.expression), choice('in', '!in'), field('right', $.expression))),
526
+
527
+ is_expression: ($) =>
528
+ prec.left(
529
+ PREC.IN,
530
+ seq(field('left', $.expression), choice('is', alias($._not_is, '!is')), field('right', $.type))
745
531
  ),
746
- )),
747
-
748
- annotated_lambda: $ => seq(
749
- repeat($.annotation),
750
- optional($.label),
751
- $.lambda_literal,
752
- ),
753
-
754
- lambda_literal: $ => seq(
755
- '{',
756
- optional(seq(optional($.lambda_parameters), '->')),
757
- optionalSep1($.statement, $._semi),
758
- '}',
759
- ),
760
-
761
- lambda_parameters: $ => seq(commaSep1($._lambda_parameter), optional(',')),
762
-
763
- _lambda_parameter: $ => choice(
764
- $.variable_declaration,
765
- $.multi_variable_declaration,
766
- ),
767
-
768
- anonymous_function: $ => prec.right(seq(
769
- 'fun',
770
- optional(seq($.type, '.')),
771
- $.function_value_parameters,
772
- optional(seq(':', $.type)),
773
- optional($.type_constraints),
774
- optional($.function_body),
775
- )),
776
-
777
- index_expression: $ => prec(PREC.CALL, seq(
778
- $.expression,
779
- '[',
780
- commaSep($.expression),
781
- ']',
782
- )),
783
-
784
- this_expression: $ => seq(
785
- choice(
786
- 'this',
787
- seq('this@', $.identifier),
532
+
533
+ as_expression: ($) =>
534
+ prec.left(PREC.AS, seq(field('left', $.expression), choice('as', 'as?'), field('right', $.type))),
535
+
536
+ spread_expression: ($) => prec(PREC.SPREAD, seq('*', $.expression)),
537
+
538
+ range_expression: ($) => prec.left(PREC.RANGE, seq($.expression, choice('..', '..<'), $.expression)),
539
+
540
+ infix_expression: ($) => prec.left(PREC.INFIX, seq($.expression, $.identifier, $.expression)),
541
+
542
+ call_expression: ($) =>
543
+ prec.left(
544
+ PREC.CALL,
545
+ seq(
546
+ $.expression,
547
+ optional($.type_arguments),
548
+ choice($.value_arguments, seq(optional($.value_arguments), $.annotated_lambda))
549
+ )
788
550
  ),
789
- ),
790
-
791
- super_expression: $ => prec.right(choice(
792
- 'super',
793
- seq('super', '<', $.type, '>'),
794
- seq('super@', $.identifier),
795
- seq('super', '<', $.type, '>', token.immediate('@'), $.identifier),
796
- )),
797
-
798
- if_expression: $ => prec.right(seq(
799
- 'if',
800
- '(',
801
- field('condition', $.expression),
802
- ')',
803
- choice(
804
- $.block,
805
- $.expression,
806
- $.assignment,
807
- ';',
551
+
552
+ annotated_lambda: ($) => seq(repeat($.annotation), optional($.label), $.lambda_literal),
553
+
554
+ lambda_literal: ($) =>
555
+ seq('{', optional(seq(optional($.lambda_parameters), '->')), optionalSep1($.statement, $._semi), '}'),
556
+
557
+ lambda_parameters: ($) => seq(commaSep1($._lambda_parameter), optional(',')),
558
+
559
+ _lambda_parameter: ($) => choice($.variable_declaration, $.multi_variable_declaration),
560
+
561
+ anonymous_function: ($) =>
562
+ prec.right(
808
563
  seq(
809
- optional(choice(
810
- $.block,
811
- $.expression,
812
- $.assignment,
813
- )),
814
- optional(';'),
815
- 'else',
816
- choice(
817
- $.block,
818
- $.expression,
819
- $.assignment,
820
- ';',
821
- ),
822
- ),
564
+ 'fun',
565
+ optional(seq($.type, '.')),
566
+ $.function_value_parameters,
567
+ optional(seq(':', $.type)),
568
+ optional($.type_constraints),
569
+ optional($.function_body)
570
+ )
823
571
  ),
824
- )),
825
-
826
- parenthesized_expression: $ => seq('(', $.expression, ')'),
827
-
828
- collection_literal: $ => seq('[', commaSep1($.expression), optional(','), ']'),
829
-
830
- when_expression: $ => seq(
831
- 'when',
832
- optional($.when_subject),
833
- '{',
834
- repeat($.when_entry),
835
- '}',
836
- ),
837
-
838
- when_subject: $ => seq(
839
- '(',
840
- optional(seq(
841
- repeat($.annotation),
842
- 'val',
843
- $.variable_declaration,
844
- '=',
845
- )),
846
- $.expression,
847
- ')',
848
- ),
849
-
850
- when_entry: $ => seq(
851
- choice(
572
+
573
+ index_expression: ($) => prec(PREC.CALL, seq($.expression, '[', commaSep($.expression), ']')),
574
+
575
+ this_expression: ($) => seq(choice('this', seq('this@', $.identifier))),
576
+
577
+ super_expression: ($) =>
578
+ prec.right(
579
+ choice(
580
+ 'super',
581
+ seq('super', '<', $.type, '>'),
582
+ seq('super@', $.identifier),
583
+ seq('super', '<', $.type, '>', token.immediate('@'), $.identifier)
584
+ )
585
+ ),
586
+
587
+ if_expression: ($) =>
588
+ prec.right(
852
589
  seq(
853
- commaSep1(field('condition', $._when_condition)),
854
- optional(','),
855
- ),
856
- 'else',
590
+ 'if',
591
+ '(',
592
+ field('condition', $.expression),
593
+ ')',
594
+ choice(
595
+ field('consequence', choice($.block, $.expression, $.assignment)),
596
+ ';',
597
+ seq(
598
+ optional(field('consequence', choice($.block, $.expression, $.assignment))),
599
+ optional(';'),
600
+ 'else',
601
+ choice(field('alternative', choice($.block, $.expression, $.assignment)), ';')
602
+ )
603
+ )
604
+ )
857
605
  ),
858
- '->',
859
- choice($.block, $.statement),
860
- optional($._semi),
861
- ),
862
-
863
- _when_condition: $ => choice(
864
- $.expression,
865
- $.range_test,
866
- $.type_test,
867
- ),
868
-
869
- range_test: $ => seq(
870
- choice(alias($._in, 'in'), '!in'),
871
- $.expression,
872
- ),
873
-
874
- type_test: $ => seq(
875
- choice('is', alias($._not_is, '!is')),
876
- $.type,
877
- ),
878
-
879
- try_expression: $ => seq(
880
- 'try',
881
- $.block,
882
- choice(
883
- seq(repeat1($.catch_block), optional($.finally_block)),
884
- $.finally_block,
606
+
607
+ parenthesized_expression: ($) => seq('(', $.expression, ')'),
608
+
609
+ collection_literal: ($) => seq('[', commaSep1($.expression), optional(','), ']'),
610
+
611
+ when_expression: ($) => seq('when', optional($.when_subject), '{', repeat($.when_entry), '}'),
612
+
613
+ when_subject: ($) =>
614
+ seq('(', optional(seq(repeat($.annotation), 'val', $.variable_declaration, '=')), $.expression, ')'),
615
+
616
+ when_entry: ($) =>
617
+ seq(
618
+ choice(seq(commaSep1(field('condition', $._when_condition)), optional(',')), 'else'),
619
+ '->',
620
+ field('body', choice($.block, $.statement)),
621
+ optional($._semi)
885
622
  ),
886
- ),
887
-
888
- catch_block: $ => seq(
889
- 'catch',
890
- '(',
891
- repeat($.annotation),
892
- $.identifier,
893
- ':',
894
- $.type,
895
- ')',
896
- $.block,
897
- ),
898
-
899
- finally_block: $ => seq('finally', $.block),
900
-
901
- return_expression: $ => prec.right(seq(
902
- choice(
903
- 'return',
904
- seq('return@', field('label', $.identifier)),
623
+
624
+ _when_condition: ($) => choice($.expression, $.range_test, $.type_test),
625
+
626
+ range_test: ($) => seq(choice(alias($._in, 'in'), '!in'), $.expression),
627
+
628
+ type_test: ($) => seq(choice('is', alias($._not_is, '!is')), $.type),
629
+
630
+ try_expression: ($) =>
631
+ seq('try', $.block, choice(seq(repeat1($.catch_block), optional($.finally_block)), $.finally_block)),
632
+
633
+ catch_block: ($) => seq('catch', '(', repeat($.annotation), $.identifier, ':', $.type, ')', $.block),
634
+
635
+ finally_block: ($) => seq('finally', $.block),
636
+
637
+ return_expression: ($) =>
638
+ prec.right(seq(choice('return', seq('return@', field('label', $.identifier))), optional($.expression))),
639
+
640
+ throw_expression: ($) => seq('throw', $.expression),
641
+
642
+ continue_expression: ($) => choice('continue', seq('continue@', field('label', $.identifier))),
643
+
644
+ break_expression: ($) => choice('break', seq('break@', field('label', $.identifier))),
645
+
646
+ callable_reference: ($) => seq(optional($._receiver_type), '::', choice($.identifier, 'class')),
647
+
648
+ navigation_expression: ($) =>
649
+ prec(
650
+ PREC.CALL,
651
+ choice(
652
+ seq($.expression, choice('.', alias($._q_dot, '?.')), $.identifier),
653
+ seq($.expression, '::', choice($.identifier, 'class'))
654
+ )
905
655
  ),
906
- optional($.expression),
907
- )),
908
-
909
- throw_expression: $ => seq(
910
- 'throw',
911
- $.expression,
912
- ),
913
-
914
- continue_expression: $ => choice(
915
- 'continue',
916
- seq('continue@', field('label', $.identifier)),
917
- ),
918
-
919
- break_expression: $ => choice(
920
- 'break',
921
- seq('break@', field('label', $.identifier)),
922
- ),
923
-
924
- callable_reference: $ => seq(
925
- optional($._receiver_type),
926
- '::',
927
- choice($.identifier, 'class'),
928
- ),
929
-
930
- navigation_expression: $ => prec(PREC.CALL, seq(
931
- $.expression,
932
- choice('.', alias($._q_dot, '?.'), '::'),
933
- $.identifier,
934
- )),
935
-
936
- object_literal: $ => seq(
937
- 'object',
938
- optional(seq(':', $.delegation_specifiers)),
939
- $.class_body,
940
- ),
941
-
942
- string_literal: $ => seq(
943
- '"',
944
- repeat(choice(
945
- alias(choice(
946
- token.immediate(prec(2, seq('\\', /[^bnrt'\"\\\$]/))),
947
- token.immediate(prec(1, /[^"\\\$]+/)),
948
- '$',
949
- ),
950
- $.string_content,
656
+
657
+ object_literal: ($) => seq('object', optional(seq(':', $.delegation_specifiers)), $.class_body),
658
+
659
+ string_literal: ($) =>
660
+ seq(
661
+ '"',
662
+ repeat(
663
+ choice(
664
+ alias(
665
+ choice(token.immediate(prec(2, seq('\\', /[^bnrt'"\\$]/))), token.immediate(prec(1, /[^"\\$]+/)), '$'),
666
+ $.string_content
667
+ ),
668
+ $.escape_sequence,
669
+ $.interpolation
670
+ )
951
671
  ),
952
- $.escape_sequence,
953
- $.interpolation,
954
- )),
955
- '"',
956
- ),
957
-
958
- multiline_string_literal: $ => seq(
959
- '"""',
960
- repeat(choice(
961
- alias($._multiline_string_content, $.string_content),
962
- $.interpolation,
963
- )),
964
- choice('"""', '""""'),
965
- ),
966
-
967
- interpolation: $ => choice(
968
- seq('$', $._identifier),
969
- seq('${', $.expression, '}'),
970
- ),
971
-
972
- character_literal: $ => seq(
973
- '\'',
974
- choice(
975
- token.immediate(prec(1, /[^'\\\r\n]/)),
976
- $.escape_sequence,
672
+ '"'
673
+ ),
674
+
675
+ multiline_string_literal: ($) =>
676
+ seq(
677
+ '"""',
678
+ repeat(choice(alias($._multiline_string_content, $.string_content), $.interpolation)),
679
+ choice('"""', '""""')
977
680
  ),
978
- '\'',
979
- ),
980
681
 
981
- escape_sequence: _ => token.immediate(prec(1, seq(
982
- '\\',
682
+ interpolation: ($) =>
983
683
  choice(
984
- /[^xu0-7]/,
985
- /u[0-9a-fA-F]{4}/,
684
+ // Immediate so that it outranks the string content that would otherwise absorb the name.
685
+ seq('$', alias(token.immediate(prec(2, /[\p{L}_][\p{L}_\p{Nd}]*/u)), $.identifier)),
686
+ seq('${', $.expression, '}')
986
687
  ),
987
- ))),
988
688
 
989
- number_literal: _ => {
689
+ character_literal: ($) => seq("'", choice(token.immediate(prec(1, /[^'\\\r\n]/)), $.escape_sequence), "'"),
690
+
691
+ escape_sequence: () => token.immediate(prec(1, seq('\\', choice(/[^xu0-7]/, /u[0-9a-fA-F]{4}/)))),
692
+
693
+ number_literal: () => {
990
694
  const separator = '_';
991
695
  const decimal = /[0-9]+/;
992
696
  const hex = /[0-9a-fA-F]/;
@@ -995,77 +699,65 @@ module.exports = grammar({
995
699
  const hexDigits = seq(repeat1(hex), repeat(seq(separator, repeat1(hex))));
996
700
  const binDigits = seq(repeat1(bin), repeat(seq(separator, repeat1(bin))));
997
701
 
998
- return token(seq(
999
- choice(
1000
- decimalDigits,
1001
- seq(/0[xX]/, hexDigits),
1002
- seq(/0[bB]/, binDigits),
1003
- ),
1004
- optional(/([lL]|[uU][lL]?)/),
1005
- ));
702
+ return token(
703
+ seq(choice(decimalDigits, seq(/0[xX]/, hexDigits), seq(/0[bB]/, binDigits)), optional(/([lL]|[uU][lL]?)/))
704
+ );
1006
705
  },
1007
706
 
1008
- float_literal: _ => {
707
+ float_literal: () => {
1009
708
  const separator = '_';
1010
709
  const decimal = /[0-9]+/;
1011
710
  const exponent = /[eE][+-]?[0-9]+/;
1012
711
  const decimalDigits = seq(repeat1(decimal), repeat(seq(separator, repeat1(decimal))));
1013
712
 
1014
- return token(seq(
1015
- choice(
1016
- seq(decimalDigits, exponent, optional(/[fF]/)),
1017
- seq(optional(decimalDigits), '.', repeat1(decimalDigits), optional(exponent), optional(/[fF]/)),
1018
- seq(decimalDigits, /[fF]/),
1019
- ),
1020
- ));
713
+ return token(
714
+ seq(
715
+ choice(
716
+ seq(decimalDigits, exponent, optional(/[fF]/)),
717
+ seq(optional(decimalDigits), '.', repeat1(decimalDigits), optional(exponent), optional(/[fF]/)),
718
+ seq(decimalDigits, /[fF]/)
719
+ )
720
+ )
721
+ );
1021
722
  },
1022
723
 
1023
- variance_modifier: _ => choice(
1024
- 'in',
1025
- 'out',
1026
- ),
724
+ variance_modifier: () => choice('in', 'out'),
1027
725
 
1028
- type_parameter_modifiers: $ => repeat1(choice(
1029
- $.reification_modifier,
1030
- $.variance_modifier,
1031
- $.annotation,
1032
- )),
726
+ type_parameter_modifiers: ($) => repeat1(choice($.reification_modifier, $.variance_modifier, $.annotation)),
1033
727
 
1034
- qualified_identifier: $ => seq(
1035
- $.identifier,
1036
- repeat(seq('.', $.identifier)),
1037
- ),
728
+ qualified_identifier: ($) => seq($.identifier, repeat(seq('.', $.identifier))),
1038
729
 
1039
- label: _ => token(/[a-zA-Z_][a-zA-Z_0-9]*@/),
730
+ label: () => token(/[a-zA-Z_][a-zA-Z_0-9]*@/),
1040
731
 
1041
- _identifier: $ => choice($.identifier, $._reserved_identifier),
732
+ _identifier: ($) => choice($.identifier, $._reserved_identifier),
1042
733
 
1043
- identifier: _ => token(choice(
1044
- /[\p{L}_][\p{L}_\p{Nd}]*/u,
1045
- /`[^\r\n`]+`/,
1046
- )),
734
+ identifier: () => token(choice(/[\p{L}_][\p{L}_\p{Nd}]*/u, /`[^\r\n`]+`/)),
1047
735
 
1048
- _reserved_identifier: $ => prec.dynamic(1, alias(
1049
- choice(
1050
- 'actual',
1051
- 'annotation',
1052
- 'constructor',
1053
- 'const',
1054
- 'data',
1055
- 'enum',
1056
- 'expect',
1057
- 'inner',
1058
- 'get',
1059
- 'set',
1060
- 'operator',
1061
- 'value',
736
+ _reserved_identifier: ($) =>
737
+ prec.dynamic(
738
+ 1,
739
+ alias(
740
+ choice(
741
+ 'actual',
742
+ 'annotation',
743
+ 'constructor',
744
+ 'const',
745
+ 'data',
746
+ 'enum',
747
+ 'expect',
748
+ 'inner',
749
+ 'get',
750
+ 'set',
751
+ 'operator',
752
+ 'value'
753
+ ),
754
+ $.identifier
755
+ )
1062
756
  ),
1063
- $.identifier,
1064
- )),
1065
757
 
1066
- shebang: _ => /#!.*/,
758
+ shebang: () => /#!.*/,
1067
759
 
1068
- line_comment: _ => token(seq('//', /.*/)),
760
+ line_comment: () => token(seq('//', /.*/)),
1069
761
  },
1070
762
  });
1071
763