@willbooster/tree-sitter-kotlin 5.0.1 → 5.0.2
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 +120 -111
- package/package.json +1 -2
- package/tree-sitter-kotlin.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
/// <reference types="tree-sitter-cli/dsl" />
|
|
2
1
|
// @ts-check
|
|
3
2
|
|
|
3
|
+
// The CLI injects the DSL before loading this CommonJS grammar.
|
|
4
|
+
const { grammar, alias, choice, field, optional, prec, repeat, repeat1, seq, sym, token } =
|
|
5
|
+
/** @type {typeof globalThis & import('@willbooster/web-tree-sitter/dsl').DSL} */ (globalThis);
|
|
6
|
+
|
|
7
|
+
/** @typedef {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} RuleOrLiteral */
|
|
8
|
+
/** @typedef {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'value_argument'>} GrammarSymbols */
|
|
9
|
+
|
|
4
10
|
const PREC = {
|
|
5
11
|
SPREAD: 1,
|
|
6
12
|
LOGICAL_OR: 2,
|
|
@@ -85,26 +91,26 @@ module.exports = grammar({
|
|
|
85
91
|
[$._receiver_type],
|
|
86
92
|
],
|
|
87
93
|
|
|
88
|
-
extras: ($) => [/\s/, $.line_comment,
|
|
94
|
+
extras: ($) => [/\s/, $.line_comment, sym('block_comment')],
|
|
89
95
|
|
|
90
|
-
externals: (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
externals: () => [
|
|
97
|
+
sym('_destructuring_type_start'),
|
|
98
|
+
sym('_semi'),
|
|
99
|
+
sym('_class_member_semi'),
|
|
94
100
|
// Unlike properties, these declarations can end before another member on the same line.
|
|
95
|
-
|
|
96
|
-
|
|
101
|
+
sym('_same_line_member_end'),
|
|
102
|
+
sym('block_comment'),
|
|
97
103
|
// also lexed by the scanner, since the generated lexer stops at a NUL character
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
sym('line_comment'),
|
|
105
|
+
sym('_not_is'),
|
|
106
|
+
sym('_in'),
|
|
107
|
+
sym('_q_dot'),
|
|
108
|
+
sym('_multiline_string_content'),
|
|
109
|
+
sym('_multi_dollar_string_start'),
|
|
110
|
+
sym('_multi_dollar_multiline_string_start'),
|
|
111
|
+
sym('_multi_dollar_string_content'),
|
|
112
|
+
sym('_multi_dollar_interpolation_start'),
|
|
113
|
+
sym('_multi_dollar_string_end'),
|
|
108
114
|
// used to check if a preceding annoation should not have an automatic _semi inserted
|
|
109
115
|
'constructor',
|
|
110
116
|
'get',
|
|
@@ -114,30 +120,30 @@ module.exports = grammar({
|
|
|
114
120
|
// used to check if a modifier alone on its line belongs to a declaration on the next line
|
|
115
121
|
'val',
|
|
116
122
|
// never scanned: it tells the scanner where a primary constructor may start
|
|
117
|
-
|
|
123
|
+
sym('_primary_constructor_position'),
|
|
118
124
|
// empty: it ends a delegation expression in a class header before `{` (see `explicit_delegation`)
|
|
119
|
-
|
|
125
|
+
sym('_delegation_end'),
|
|
120
126
|
// the `)` that ends a call's arguments (see `value_arguments`)
|
|
121
|
-
|
|
127
|
+
sym('_arguments_end'),
|
|
122
128
|
// empty: they tell the scanner when a statement list or the member list of a class body opens in braces, and when
|
|
123
129
|
// either closes (see `frames` in the scanner)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
130
|
+
sym('_open_statements'),
|
|
131
|
+
sym('_open_members'),
|
|
132
|
+
sym('_close_braces'),
|
|
133
|
+
sym('_top_level_statement_end'),
|
|
128
134
|
// empty: it ends a context list of types among modifiers, except directly in a statement list (see `modifiers`)
|
|
129
|
-
|
|
135
|
+
sym('_context_end'),
|
|
130
136
|
// a hard keyword other than `this` right after the `$` of a string template (see `_template_name`)
|
|
131
|
-
|
|
137
|
+
sym('_keyword_reference'),
|
|
132
138
|
// never scanned: see `_template_name`
|
|
133
|
-
|
|
139
|
+
sym('_keyword_reference_end'),
|
|
134
140
|
'where',
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
+
sym('_separated_member_start'),
|
|
142
|
+
sym('_unseparated_member_start'),
|
|
143
|
+
sym('_infix_position'),
|
|
144
|
+
sym('_companion_name_position'),
|
|
145
|
+
sym('_try_continuation_position'),
|
|
146
|
+
sym('_infix_get_identifier'),
|
|
141
147
|
],
|
|
142
148
|
|
|
143
149
|
inline: ($) => [$._statements, $._identifier, $._control_structure_body],
|
|
@@ -199,11 +205,17 @@ module.exports = grammar({
|
|
|
199
205
|
repeat($.import),
|
|
200
206
|
// The scanner clears its brace frames after each top-level statement, so that a brace that error recovery
|
|
201
207
|
// consumed affects no later statement.
|
|
202
|
-
repeat(seq($.statement,
|
|
208
|
+
repeat(seq($.statement, sym('_semi'), sym('_top_level_statement_end')))
|
|
203
209
|
),
|
|
204
210
|
|
|
205
211
|
file_annotation: ($) =>
|
|
206
|
-
seq(
|
|
212
|
+
seq(
|
|
213
|
+
'@',
|
|
214
|
+
'file',
|
|
215
|
+
':',
|
|
216
|
+
choice(seq('[', repeat1($._unescaped_annotation), ']'), $._unescaped_annotation),
|
|
217
|
+
sym('_semi')
|
|
218
|
+
),
|
|
207
219
|
|
|
208
220
|
package_header: ($) => seq('package', $.qualified_identifier, optional(';')),
|
|
209
221
|
|
|
@@ -217,11 +229,11 @@ module.exports = grammar({
|
|
|
217
229
|
prec.right(
|
|
218
230
|
seq(
|
|
219
231
|
optional($.modifiers),
|
|
220
|
-
choice('class', seq(optional(seq('fun', optional(
|
|
221
|
-
optional(
|
|
232
|
+
choice('class', seq(optional(seq('fun', optional(sym('_unseparated_member_start')))), 'interface')),
|
|
233
|
+
optional(sym('_unseparated_member_start')),
|
|
222
234
|
field('name', $.identifier),
|
|
223
235
|
optional($.type_parameters),
|
|
224
|
-
optional(seq(optional(
|
|
236
|
+
optional(seq(optional(sym('_primary_constructor_position')), $.primary_constructor)),
|
|
225
237
|
optional(seq(':', $.delegation_specifiers)),
|
|
226
238
|
optional($.type_constraints),
|
|
227
239
|
optional(choice($.class_body, $.enum_class_body))
|
|
@@ -233,7 +245,7 @@ module.exports = grammar({
|
|
|
233
245
|
seq(
|
|
234
246
|
optional($.modifiers),
|
|
235
247
|
'object',
|
|
236
|
-
optional(
|
|
248
|
+
optional(sym('_unseparated_member_start')),
|
|
237
249
|
field('name', $.identifier),
|
|
238
250
|
optional(seq(':', $.delegation_specifiers)),
|
|
239
251
|
optional($.class_body)
|
|
@@ -245,7 +257,7 @@ module.exports = grammar({
|
|
|
245
257
|
seq(
|
|
246
258
|
optional($.modifiers),
|
|
247
259
|
choice('val', 'var'),
|
|
248
|
-
optional(
|
|
260
|
+
optional(sym('_separated_member_start')),
|
|
249
261
|
optional($.type_parameters),
|
|
250
262
|
optional(seq($._receiver_type, optional('.'))),
|
|
251
263
|
choice($.variable_declaration, $.multi_variable_declaration),
|
|
@@ -261,7 +273,7 @@ module.exports = grammar({
|
|
|
261
273
|
seq(
|
|
262
274
|
optional($.modifiers),
|
|
263
275
|
'typealias',
|
|
264
|
-
optional(
|
|
276
|
+
optional(sym('_separated_member_start')),
|
|
265
277
|
field('type', $.identifier),
|
|
266
278
|
optional($.type_parameters),
|
|
267
279
|
'=',
|
|
@@ -274,19 +286,19 @@ module.exports = grammar({
|
|
|
274
286
|
optional($.modifiers),
|
|
275
287
|
'companion',
|
|
276
288
|
'object',
|
|
277
|
-
optional(
|
|
278
|
-
optional(seq(optional(
|
|
289
|
+
optional(sym('_unseparated_member_start')),
|
|
290
|
+
optional(seq(optional(sym('_companion_name_position')), field('name', $.identifier))),
|
|
279
291
|
optional(seq(':', $.delegation_specifiers)),
|
|
280
292
|
optional($.class_body)
|
|
281
293
|
),
|
|
282
294
|
|
|
283
|
-
anonymous_initializer: ($) => seq('init', optional(
|
|
295
|
+
anonymous_initializer: ($) => seq('init', optional(sym('_unseparated_member_start')), $.block),
|
|
284
296
|
|
|
285
297
|
secondary_constructor: ($) =>
|
|
286
298
|
seq(
|
|
287
299
|
optional($.modifiers),
|
|
288
300
|
'constructor',
|
|
289
|
-
optional(
|
|
301
|
+
optional(sym('_unseparated_member_start')),
|
|
290
302
|
$.function_value_parameters,
|
|
291
303
|
optional(seq(':', $.constructor_delegation_call)),
|
|
292
304
|
optional($.block)
|
|
@@ -324,7 +336,7 @@ module.exports = grammar({
|
|
|
324
336
|
seq(
|
|
325
337
|
optional($.modifiers),
|
|
326
338
|
'fun',
|
|
327
|
-
optional(
|
|
339
|
+
optional(sym('_unseparated_member_start')),
|
|
328
340
|
optional($.type_parameters),
|
|
329
341
|
optional(seq($._receiver_type, optional('.'))),
|
|
330
342
|
field('name', $._identifier),
|
|
@@ -359,7 +371,7 @@ module.exports = grammar({
|
|
|
359
371
|
|
|
360
372
|
// As in Kotlin, a `{` after the delegation expression starts the class body, never a trailing lambda, also after the
|
|
361
373
|
// last operand of an operator (`B by a ?: b { … }`): the scanner ends the expression before it.
|
|
362
|
-
explicit_delegation: ($) => seq($.type, 'by', $.expression, optional(
|
|
374
|
+
explicit_delegation: ($) => seq($.type, 'by', $.expression, optional(sym('_delegation_end'))),
|
|
363
375
|
|
|
364
376
|
getter: ($) =>
|
|
365
377
|
prec.right(
|
|
@@ -389,7 +401,7 @@ module.exports = grammar({
|
|
|
389
401
|
|
|
390
402
|
function_body: ($) => choice($.block, seq('=', $.expression)),
|
|
391
403
|
|
|
392
|
-
block: ($) => seq('{',
|
|
404
|
+
block: ($) => seq('{', sym('_open_statements'), optional($._statements), '}', sym('_close_braces')),
|
|
393
405
|
|
|
394
406
|
for_statement: ($) =>
|
|
395
407
|
prec.right(
|
|
@@ -433,10 +445,11 @@ module.exports = grammar({
|
|
|
433
445
|
|
|
434
446
|
_loop_prefix: ($) => prec.dynamic(1, repeat1(choice($.annotation, $.label))),
|
|
435
447
|
|
|
436
|
-
class_body: ($) =>
|
|
448
|
+
class_body: ($) =>
|
|
449
|
+
seq('{', sym('_open_members'), repeat($._class_member_with_separator), '}', sym('_close_braces')),
|
|
437
450
|
|
|
438
451
|
_class_member_with_separator: ($) =>
|
|
439
|
-
seq($.class_member_declaration, optional(
|
|
452
|
+
seq($.class_member_declaration, optional(sym('_same_line_member_end')), sym('_class_member_semi')),
|
|
440
453
|
|
|
441
454
|
class_member_declaration: ($) =>
|
|
442
455
|
choice($.declaration, $.companion_object, $.anonymous_initializer, $.secondary_constructor),
|
|
@@ -446,11 +459,11 @@ module.exports = grammar({
|
|
|
446
459
|
enum_class_body: ($) =>
|
|
447
460
|
seq(
|
|
448
461
|
'{',
|
|
449
|
-
|
|
462
|
+
sym('_open_members'),
|
|
450
463
|
optionalCommaSep1($.enum_entry),
|
|
451
464
|
optional(seq(';', repeat($._class_member_with_separator))),
|
|
452
465
|
'}',
|
|
453
|
-
|
|
466
|
+
sym('_close_braces')
|
|
454
467
|
),
|
|
455
468
|
|
|
456
469
|
// Only annotations can modify an enum entry, and with the full modifier list a `context` after an annotation would
|
|
@@ -467,7 +480,7 @@ module.exports = grammar({
|
|
|
467
480
|
|
|
468
481
|
value_argument: ($) => seq(optional(seq($._identifier, '=')), optional('*'), $.expression),
|
|
469
482
|
|
|
470
|
-
_statements: ($) => seq($.statement, repeat(seq(
|
|
483
|
+
_statements: ($) => seq($.statement, repeat(seq(sym('_semi'), $.statement)), optional(sym('_semi'))),
|
|
471
484
|
|
|
472
485
|
statement: ($) =>
|
|
473
486
|
choice($.declaration, $.assignment, $.for_statement, $.while_statement, $.do_while_statement, $.expression),
|
|
@@ -580,7 +593,7 @@ module.exports = grammar({
|
|
|
580
593
|
'context',
|
|
581
594
|
'(',
|
|
582
595
|
choice(
|
|
583
|
-
seq(commaSep1($.type), optional(','), ')',
|
|
596
|
+
seq(commaSep1($.type), optional(','), ')', sym('_context_end')),
|
|
584
597
|
seq(
|
|
585
598
|
repeat(seq($.type, ',')),
|
|
586
599
|
seq(optional($.parameter_modifiers), $.parameter),
|
|
@@ -659,6 +672,7 @@ module.exports = grammar({
|
|
|
659
672
|
labeled_expression: ($) => seq($.label, $.expression),
|
|
660
673
|
|
|
661
674
|
binary_expression: ($) => {
|
|
675
|
+
/** @type {[string, number][]} */
|
|
662
676
|
const table = [
|
|
663
677
|
['+', PREC.ADD],
|
|
664
678
|
['-', PREC.ADD],
|
|
@@ -682,12 +696,7 @@ module.exports = grammar({
|
|
|
682
696
|
...table.map(([operator, precedence]) => {
|
|
683
697
|
return prec.left(
|
|
684
698
|
precedence,
|
|
685
|
-
seq(
|
|
686
|
-
field('left', $.expression),
|
|
687
|
-
// @ts-ignore
|
|
688
|
-
field('operator', operator),
|
|
689
|
-
field('right', $.expression)
|
|
690
|
-
)
|
|
699
|
+
seq(field('left', $.expression), field('operator', operator), field('right', $.expression))
|
|
691
700
|
);
|
|
692
701
|
})
|
|
693
702
|
);
|
|
@@ -699,7 +708,7 @@ module.exports = grammar({
|
|
|
699
708
|
is_expression: ($) =>
|
|
700
709
|
prec.left(
|
|
701
710
|
PREC.IN,
|
|
702
|
-
seq(field('left', $.expression), choice('is', alias(
|
|
711
|
+
seq(field('left', $.expression), choice('is', alias(sym('_not_is'), '!is')), field('right', $.type))
|
|
703
712
|
),
|
|
704
713
|
|
|
705
714
|
as_expression: ($) =>
|
|
@@ -714,8 +723,8 @@ module.exports = grammar({
|
|
|
714
723
|
PREC.INFIX,
|
|
715
724
|
seq(
|
|
716
725
|
$.expression,
|
|
717
|
-
optional(
|
|
718
|
-
choice($.identifier, alias(
|
|
726
|
+
optional(sym('_infix_position')),
|
|
727
|
+
choice($.identifier, alias(sym('_infix_get_identifier'), $.identifier)),
|
|
719
728
|
$.expression
|
|
720
729
|
)
|
|
721
730
|
),
|
|
@@ -737,11 +746,11 @@ module.exports = grammar({
|
|
|
737
746
|
lambda_literal: ($) =>
|
|
738
747
|
seq(
|
|
739
748
|
'{',
|
|
740
|
-
|
|
749
|
+
sym('_open_statements'),
|
|
741
750
|
optional(seq(optional($.lambda_parameters), '->')),
|
|
742
|
-
optionalSep1($.statement,
|
|
751
|
+
optionalSep1($.statement, sym('_semi')),
|
|
743
752
|
'}',
|
|
744
|
-
|
|
753
|
+
sym('_close_braces')
|
|
745
754
|
),
|
|
746
755
|
|
|
747
756
|
lambda_parameters: ($) => seq(commaSep1($._lambda_parameter), optional(',')),
|
|
@@ -750,7 +759,10 @@ module.exports = grammar({
|
|
|
750
759
|
choice($.variable_declaration, alias($._destructuring_lambda_parameter, $.multi_variable_declaration)),
|
|
751
760
|
|
|
752
761
|
_destructuring_lambda_parameter: ($) =>
|
|
753
|
-
seq(
|
|
762
|
+
seq(
|
|
763
|
+
$._multi_variable_declaration,
|
|
764
|
+
optional(seq(alias(sym('_destructuring_type_start'), ':'), field('type', $.type)))
|
|
765
|
+
),
|
|
754
766
|
|
|
755
767
|
anonymous_function: ($) =>
|
|
756
768
|
prec.right(
|
|
@@ -809,7 +821,15 @@ module.exports = grammar({
|
|
|
809
821
|
collection_literal: ($) => seq('[', optionalCommaSep1($.expression), ']'),
|
|
810
822
|
|
|
811
823
|
when_expression: ($) =>
|
|
812
|
-
seq(
|
|
824
|
+
seq(
|
|
825
|
+
'when',
|
|
826
|
+
optional($.when_subject),
|
|
827
|
+
'{',
|
|
828
|
+
sym('_open_statements'),
|
|
829
|
+
repeat($.when_entry),
|
|
830
|
+
'}',
|
|
831
|
+
sym('_close_braces')
|
|
832
|
+
),
|
|
813
833
|
|
|
814
834
|
when_subject: ($) =>
|
|
815
835
|
seq('(', optional(seq(repeat($.annotation), 'val', $.variable_declaration, '=')), $.expression, ')'),
|
|
@@ -820,21 +840,21 @@ module.exports = grammar({
|
|
|
820
840
|
optional(seq('if', field('guard', $.expression))),
|
|
821
841
|
'->',
|
|
822
842
|
field('body', choice($.block, $.statement)),
|
|
823
|
-
optional(
|
|
843
|
+
optional(sym('_semi'))
|
|
824
844
|
),
|
|
825
845
|
|
|
826
846
|
_when_condition: ($) => choice($.expression, $.range_test, $.type_test),
|
|
827
847
|
|
|
828
|
-
range_test: ($) => seq(choice(alias(
|
|
848
|
+
range_test: ($) => seq(choice(alias(sym('_in'), 'in'), '!in'), $.expression),
|
|
829
849
|
|
|
830
|
-
type_test: ($) => seq(choice('is', alias(
|
|
850
|
+
type_test: ($) => seq(choice('is', alias(sym('_not_is'), '!is')), $.type),
|
|
831
851
|
|
|
832
852
|
try_expression: ($) =>
|
|
833
853
|
seq(
|
|
834
854
|
'try',
|
|
835
855
|
$.block,
|
|
836
856
|
choice(
|
|
837
|
-
seq(repeat1(seq($.catch_block, optional(
|
|
857
|
+
seq(repeat1(seq($.catch_block, optional(sym('_try_continuation_position')))), optional($.finally_block)),
|
|
838
858
|
$.finally_block
|
|
839
859
|
)
|
|
840
860
|
),
|
|
@@ -842,7 +862,7 @@ module.exports = grammar({
|
|
|
842
862
|
catch_block: ($) => seq('catch', '(', repeat($.annotation), $.identifier, ':', $.type, optional(','), ')', $.block),
|
|
843
863
|
|
|
844
864
|
finally_block: ($) =>
|
|
845
|
-
choice(prec(1, seq(
|
|
865
|
+
choice(prec(1, seq(sym('_try_continuation_position'), 'finally', $.block)), seq('finally', $.block)),
|
|
846
866
|
|
|
847
867
|
return_expression: ($) =>
|
|
848
868
|
prec.right(seq(choice('return', seq('return@', field('label', $.identifier))), optional($.expression))),
|
|
@@ -859,7 +879,7 @@ module.exports = grammar({
|
|
|
859
879
|
prec(
|
|
860
880
|
PREC.CALL,
|
|
861
881
|
choice(
|
|
862
|
-
seq($.expression, choice('.', alias(
|
|
882
|
+
seq($.expression, choice('.', alias(sym('_q_dot'), '?.')), $.identifier),
|
|
863
883
|
seq($.expression, '::', choice($.identifier, 'class'))
|
|
864
884
|
)
|
|
865
885
|
),
|
|
@@ -874,7 +894,7 @@ module.exports = grammar({
|
|
|
874
894
|
choice(
|
|
875
895
|
alias(
|
|
876
896
|
choice(token.immediate(prec(2, seq('\\', /[^bnrt'"\\$]/))), token.immediate(prec(1, /[^"\\$]+/)), '$'),
|
|
877
|
-
|
|
897
|
+
sym('string_content')
|
|
878
898
|
),
|
|
879
899
|
$.escape_sequence,
|
|
880
900
|
$.interpolation
|
|
@@ -883,30 +903,34 @@ module.exports = grammar({
|
|
|
883
903
|
'"'
|
|
884
904
|
),
|
|
885
905
|
seq(
|
|
886
|
-
|
|
906
|
+
sym('_multi_dollar_string_start'),
|
|
887
907
|
repeat(
|
|
888
908
|
choice(
|
|
889
|
-
alias(
|
|
909
|
+
alias(sym('_multi_dollar_string_content'), sym('string_content')),
|
|
890
910
|
$.escape_sequence,
|
|
891
911
|
alias($._multi_dollar_interpolation, $.interpolation)
|
|
892
912
|
)
|
|
893
913
|
),
|
|
894
|
-
|
|
914
|
+
sym('_multi_dollar_string_end')
|
|
895
915
|
)
|
|
896
916
|
),
|
|
897
917
|
|
|
898
918
|
multiline_string_literal: ($) =>
|
|
899
919
|
choice(
|
|
900
|
-
seq('"""', repeat(choice(alias($._multiline_string_content, $.string_content), $.interpolation)), '"""'),
|
|
901
920
|
seq(
|
|
902
|
-
|
|
921
|
+
'"""',
|
|
922
|
+
repeat(choice(alias(sym('_multiline_string_content'), sym('string_content')), $.interpolation)),
|
|
923
|
+
'"""'
|
|
924
|
+
),
|
|
925
|
+
seq(
|
|
926
|
+
sym('_multi_dollar_multiline_string_start'),
|
|
903
927
|
repeat(
|
|
904
928
|
choice(
|
|
905
|
-
alias(
|
|
929
|
+
alias(sym('_multi_dollar_string_content'), sym('string_content')),
|
|
906
930
|
alias($._multi_dollar_interpolation, $.interpolation)
|
|
907
931
|
)
|
|
908
932
|
),
|
|
909
|
-
|
|
933
|
+
sym('_multi_dollar_string_end')
|
|
910
934
|
)
|
|
911
935
|
),
|
|
912
936
|
|
|
@@ -922,13 +946,19 @@ module.exports = grammar({
|
|
|
922
946
|
// As in Kotlin, another hard keyword after `$` is an error: the scanner lexes it, and the grammar then expects
|
|
923
947
|
// `_keyword_reference_end`, which is never scanned. The first alias keeps a name required in `interpolation`; the
|
|
924
948
|
// second makes the end visible when error recovery inserts it as missing, which a hidden token would not be.
|
|
925
|
-
seq(
|
|
949
|
+
seq(
|
|
950
|
+
alias(sym('_keyword_reference'), $.identifier),
|
|
951
|
+
alias(sym('_keyword_reference_end'), 'keyword_reference_end')
|
|
952
|
+
)
|
|
926
953
|
),
|
|
927
954
|
|
|
928
955
|
// In a string prefixed with n dollars (Kotlin 2.1), exactly n dollars start an interpolation; the scanner
|
|
929
956
|
// returns them as one token only where they do.
|
|
930
957
|
_multi_dollar_interpolation: ($) =>
|
|
931
|
-
seq(
|
|
958
|
+
seq(
|
|
959
|
+
sym('_multi_dollar_interpolation_start'),
|
|
960
|
+
choice($._template_name, seq(token.immediate('{'), $.expression, '}'))
|
|
961
|
+
),
|
|
932
962
|
|
|
933
963
|
character_literal: ($) => seq("'", choice(token.immediate(prec(1, /[^'\\\r\n]/)), $.escape_sequence), "'"),
|
|
934
964
|
|
|
@@ -973,7 +1003,7 @@ module.exports = grammar({
|
|
|
973
1003
|
|
|
974
1004
|
label: () => token(/[a-zA-Z_][a-zA-Z_0-9]*@/),
|
|
975
1005
|
|
|
976
|
-
_identifier: ($) => choice($.identifier, $._reserved_identifier, alias(
|
|
1006
|
+
_identifier: ($) => choice($.identifier, $._reserved_identifier, alias(sym('_infix_get_identifier'), $.identifier)),
|
|
977
1007
|
|
|
978
1008
|
identifier: () => token(choice(/[\p{L}_][\p{L}_\p{Nd}]*/u, /`[^\r\n`]+`/)),
|
|
979
1009
|
|
|
@@ -1019,50 +1049,30 @@ module.exports = grammar({
|
|
|
1019
1049
|
});
|
|
1020
1050
|
|
|
1021
1051
|
/**
|
|
1022
|
-
* Creates a rule to match one or more of the rules separated by `separator`
|
|
1023
|
-
*
|
|
1024
1052
|
* @param {RuleOrLiteral} rule
|
|
1025
|
-
*
|
|
1026
1053
|
* @param {RuleOrLiteral} separator
|
|
1027
|
-
*
|
|
1028
|
-
* @returns {SeqRule}
|
|
1029
1054
|
*/
|
|
1030
1055
|
function sep1(rule, separator) {
|
|
1031
1056
|
return seq(rule, repeat(seq(separator, rule)));
|
|
1032
1057
|
}
|
|
1033
1058
|
|
|
1034
1059
|
/**
|
|
1035
|
-
* Creates a rule to optionally match one or more of the rules separated by `separator`
|
|
1036
|
-
* and optionally ending with `separator`
|
|
1037
|
-
*
|
|
1038
1060
|
* @param {RuleOrLiteral} rule
|
|
1039
|
-
*
|
|
1040
1061
|
* @param {RuleOrLiteral} separator
|
|
1041
|
-
*
|
|
1042
|
-
* @returns {ChoiceRule}
|
|
1043
1062
|
*/
|
|
1044
1063
|
function optionalSep1(rule, separator) {
|
|
1045
1064
|
return optional(seq(rule, repeat(seq(separator, rule)), optional(separator)));
|
|
1046
1065
|
}
|
|
1047
1066
|
|
|
1048
1067
|
/**
|
|
1049
|
-
*
|
|
1050
|
-
*
|
|
1051
|
-
* @param {Rule} rule
|
|
1052
|
-
*
|
|
1053
|
-
* @returns {SeqRule}
|
|
1068
|
+
* @param {RuleOrLiteral} rule
|
|
1054
1069
|
*/
|
|
1055
1070
|
function commaSep1(rule) {
|
|
1056
1071
|
return seq(rule, repeat(seq(',', rule)));
|
|
1057
1072
|
}
|
|
1058
1073
|
|
|
1059
1074
|
/**
|
|
1060
|
-
*
|
|
1061
|
-
* and optionally ending with a comma
|
|
1062
|
-
*
|
|
1063
|
-
* @param {Rule} rule
|
|
1064
|
-
*
|
|
1065
|
-
* @returns {ChoiceRule}
|
|
1075
|
+
* @param {RuleOrLiteral} rule
|
|
1066
1076
|
*/
|
|
1067
1077
|
function optionalCommaSep1(rule) {
|
|
1068
1078
|
return optional(seq(rule, repeat(seq(',', rule)), optional(',')));
|
|
@@ -1073,11 +1083,10 @@ function optionalCommaSep1(rule) {
|
|
|
1073
1083
|
* its arguments, which the lookahead of the scanned `)` reaches, so an edit there makes incremental parsing reparse the
|
|
1074
1084
|
* call instead of reusing a call without the lambda.
|
|
1075
1085
|
*
|
|
1076
|
-
* @param {GrammarSymbols
|
|
1086
|
+
* @param {GrammarSymbols} $
|
|
1077
1087
|
* @param {RuleOrLiteral} open
|
|
1078
1088
|
*
|
|
1079
|
-
* @returns {SeqRule}
|
|
1080
1089
|
*/
|
|
1081
1090
|
function valueArguments($, open) {
|
|
1082
|
-
return seq(open, optionalCommaSep1($.value_argument), alias(
|
|
1091
|
+
return seq(open, optionalCommaSep1($.value_argument), alias(sym('_arguments_end'), ')'));
|
|
1083
1092
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-kotlin",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "Kotlin grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -55,7 +55,6 @@
|
|
|
55
55
|
"playwright": "1.63.0",
|
|
56
56
|
"semantic-release": "25.0.9",
|
|
57
57
|
"sort-package-json": "4.0.0",
|
|
58
|
-
"tree-sitter-cli": "0.27.0",
|
|
59
58
|
"typescript": "7.0.2",
|
|
60
59
|
"vite": "8.3.2",
|
|
61
60
|
"vitest": "5.0.3",
|
package/tree-sitter-kotlin.wasm
CHANGED
|
Binary file
|