@willbooster/tree-sitter-kotlin 5.0.1 → 5.0.3
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 +133 -115
- package/package.json +11 -12
- package/src/node-types.json +14 -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,
|
|
@@ -36,6 +42,12 @@ module.exports = grammar({
|
|
|
36
42
|
[$.user_type],
|
|
37
43
|
[$._simple_user_type, $.primary_expression],
|
|
38
44
|
[$.type, $._receiver_type],
|
|
45
|
+
[$._receiver_type, $._reserved_identifier],
|
|
46
|
+
[$.type, $._reserved_identifier],
|
|
47
|
+
[$.nullable_type, $._reserved_identifier],
|
|
48
|
+
[$.type, $.nullable_type, $._reserved_identifier],
|
|
49
|
+
[$.type, $.nullable_type],
|
|
50
|
+
[$.type, $._receiver_type, $._reserved_identifier],
|
|
39
51
|
|
|
40
52
|
[$.modifiers, $.annotated_lambda],
|
|
41
53
|
[$.modifiers, $.annotated_expression],
|
|
@@ -85,26 +97,26 @@ module.exports = grammar({
|
|
|
85
97
|
[$._receiver_type],
|
|
86
98
|
],
|
|
87
99
|
|
|
88
|
-
extras: ($) => [/\s/, $.line_comment,
|
|
100
|
+
extras: ($) => [/\s/, $.line_comment, sym('block_comment')],
|
|
89
101
|
|
|
90
|
-
externals: (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
102
|
+
externals: () => [
|
|
103
|
+
sym('_destructuring_type_start'),
|
|
104
|
+
sym('_semi'),
|
|
105
|
+
sym('_class_member_semi'),
|
|
94
106
|
// Unlike properties, these declarations can end before another member on the same line.
|
|
95
|
-
|
|
96
|
-
|
|
107
|
+
sym('_same_line_member_end'),
|
|
108
|
+
sym('block_comment'),
|
|
97
109
|
// also lexed by the scanner, since the generated lexer stops at a NUL character
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
sym('line_comment'),
|
|
111
|
+
sym('_not_is'),
|
|
112
|
+
sym('_in'),
|
|
113
|
+
sym('_q_dot'),
|
|
114
|
+
sym('_multiline_string_content'),
|
|
115
|
+
sym('_multi_dollar_string_start'),
|
|
116
|
+
sym('_multi_dollar_multiline_string_start'),
|
|
117
|
+
sym('_multi_dollar_string_content'),
|
|
118
|
+
sym('_multi_dollar_interpolation_start'),
|
|
119
|
+
sym('_multi_dollar_string_end'),
|
|
108
120
|
// used to check if a preceding annoation should not have an automatic _semi inserted
|
|
109
121
|
'constructor',
|
|
110
122
|
'get',
|
|
@@ -114,33 +126,33 @@ module.exports = grammar({
|
|
|
114
126
|
// used to check if a modifier alone on its line belongs to a declaration on the next line
|
|
115
127
|
'val',
|
|
116
128
|
// never scanned: it tells the scanner where a primary constructor may start
|
|
117
|
-
|
|
129
|
+
sym('_primary_constructor_position'),
|
|
118
130
|
// empty: it ends a delegation expression in a class header before `{` (see `explicit_delegation`)
|
|
119
|
-
|
|
131
|
+
sym('_delegation_end'),
|
|
120
132
|
// the `)` that ends a call's arguments (see `value_arguments`)
|
|
121
|
-
|
|
133
|
+
sym('_arguments_end'),
|
|
122
134
|
// empty: they tell the scanner when a statement list or the member list of a class body opens in braces, and when
|
|
123
135
|
// either closes (see `frames` in the scanner)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
136
|
+
sym('_open_statements'),
|
|
137
|
+
sym('_open_members'),
|
|
138
|
+
sym('_close_braces'),
|
|
139
|
+
sym('_top_level_statement_end'),
|
|
128
140
|
// empty: it ends a context list of types among modifiers, except directly in a statement list (see `modifiers`)
|
|
129
|
-
|
|
141
|
+
sym('_context_end'),
|
|
130
142
|
// a hard keyword other than `this` right after the `$` of a string template (see `_template_name`)
|
|
131
|
-
|
|
143
|
+
sym('_keyword_reference'),
|
|
132
144
|
// never scanned: see `_template_name`
|
|
133
|
-
|
|
145
|
+
sym('_keyword_reference_end'),
|
|
134
146
|
'where',
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
147
|
+
sym('_separated_member_start'),
|
|
148
|
+
sym('_unseparated_member_start'),
|
|
149
|
+
sym('_infix_position'),
|
|
150
|
+
sym('_companion_name_position'),
|
|
151
|
+
sym('_try_continuation_position'),
|
|
152
|
+
sym('_infix_get_identifier'),
|
|
141
153
|
],
|
|
142
154
|
|
|
143
|
-
inline: ($) => [$._statements, $._identifier, $._control_structure_body],
|
|
155
|
+
inline: ($) => [$._statements, $._identifier, $._control_structure_body, $._non_function_type],
|
|
144
156
|
|
|
145
157
|
precedences: ($) => [
|
|
146
158
|
[$.block, $.lambda_literal],
|
|
@@ -199,11 +211,17 @@ module.exports = grammar({
|
|
|
199
211
|
repeat($.import),
|
|
200
212
|
// The scanner clears its brace frames after each top-level statement, so that a brace that error recovery
|
|
201
213
|
// consumed affects no later statement.
|
|
202
|
-
repeat(seq($.statement,
|
|
214
|
+
repeat(seq($.statement, sym('_semi'), sym('_top_level_statement_end')))
|
|
203
215
|
),
|
|
204
216
|
|
|
205
217
|
file_annotation: ($) =>
|
|
206
|
-
seq(
|
|
218
|
+
seq(
|
|
219
|
+
'@',
|
|
220
|
+
'file',
|
|
221
|
+
':',
|
|
222
|
+
choice(seq('[', repeat1($._unescaped_annotation), ']'), $._unescaped_annotation),
|
|
223
|
+
sym('_semi')
|
|
224
|
+
),
|
|
207
225
|
|
|
208
226
|
package_header: ($) => seq('package', $.qualified_identifier, optional(';')),
|
|
209
227
|
|
|
@@ -217,11 +235,11 @@ module.exports = grammar({
|
|
|
217
235
|
prec.right(
|
|
218
236
|
seq(
|
|
219
237
|
optional($.modifiers),
|
|
220
|
-
choice('class', seq(optional(seq('fun', optional(
|
|
221
|
-
optional(
|
|
238
|
+
choice('class', seq(optional(seq('fun', optional(sym('_unseparated_member_start')))), 'interface')),
|
|
239
|
+
optional(sym('_unseparated_member_start')),
|
|
222
240
|
field('name', $.identifier),
|
|
223
241
|
optional($.type_parameters),
|
|
224
|
-
optional(seq(optional(
|
|
242
|
+
optional(seq(optional(sym('_primary_constructor_position')), $.primary_constructor)),
|
|
225
243
|
optional(seq(':', $.delegation_specifiers)),
|
|
226
244
|
optional($.type_constraints),
|
|
227
245
|
optional(choice($.class_body, $.enum_class_body))
|
|
@@ -233,7 +251,7 @@ module.exports = grammar({
|
|
|
233
251
|
seq(
|
|
234
252
|
optional($.modifiers),
|
|
235
253
|
'object',
|
|
236
|
-
optional(
|
|
254
|
+
optional(sym('_unseparated_member_start')),
|
|
237
255
|
field('name', $.identifier),
|
|
238
256
|
optional(seq(':', $.delegation_specifiers)),
|
|
239
257
|
optional($.class_body)
|
|
@@ -245,7 +263,7 @@ module.exports = grammar({
|
|
|
245
263
|
seq(
|
|
246
264
|
optional($.modifiers),
|
|
247
265
|
choice('val', 'var'),
|
|
248
|
-
optional(
|
|
266
|
+
optional(sym('_separated_member_start')),
|
|
249
267
|
optional($.type_parameters),
|
|
250
268
|
optional(seq($._receiver_type, optional('.'))),
|
|
251
269
|
choice($.variable_declaration, $.multi_variable_declaration),
|
|
@@ -261,7 +279,7 @@ module.exports = grammar({
|
|
|
261
279
|
seq(
|
|
262
280
|
optional($.modifiers),
|
|
263
281
|
'typealias',
|
|
264
|
-
optional(
|
|
282
|
+
optional(sym('_separated_member_start')),
|
|
265
283
|
field('type', $.identifier),
|
|
266
284
|
optional($.type_parameters),
|
|
267
285
|
'=',
|
|
@@ -274,19 +292,19 @@ module.exports = grammar({
|
|
|
274
292
|
optional($.modifiers),
|
|
275
293
|
'companion',
|
|
276
294
|
'object',
|
|
277
|
-
optional(
|
|
278
|
-
optional(seq(optional(
|
|
295
|
+
optional(sym('_unseparated_member_start')),
|
|
296
|
+
optional(seq(optional(sym('_companion_name_position')), field('name', $.identifier))),
|
|
279
297
|
optional(seq(':', $.delegation_specifiers)),
|
|
280
298
|
optional($.class_body)
|
|
281
299
|
),
|
|
282
300
|
|
|
283
|
-
anonymous_initializer: ($) => seq('init', optional(
|
|
301
|
+
anonymous_initializer: ($) => seq('init', optional(sym('_unseparated_member_start')), $.block),
|
|
284
302
|
|
|
285
303
|
secondary_constructor: ($) =>
|
|
286
304
|
seq(
|
|
287
305
|
optional($.modifiers),
|
|
288
306
|
'constructor',
|
|
289
|
-
optional(
|
|
307
|
+
optional(sym('_unseparated_member_start')),
|
|
290
308
|
$.function_value_parameters,
|
|
291
309
|
optional(seq(':', $.constructor_delegation_call)),
|
|
292
310
|
optional($.block)
|
|
@@ -324,7 +342,7 @@ module.exports = grammar({
|
|
|
324
342
|
seq(
|
|
325
343
|
optional($.modifiers),
|
|
326
344
|
'fun',
|
|
327
|
-
optional(
|
|
345
|
+
optional(sym('_unseparated_member_start')),
|
|
328
346
|
optional($.type_parameters),
|
|
329
347
|
optional(seq($._receiver_type, optional('.'))),
|
|
330
348
|
field('name', $._identifier),
|
|
@@ -359,7 +377,7 @@ module.exports = grammar({
|
|
|
359
377
|
|
|
360
378
|
// As in Kotlin, a `{` after the delegation expression starts the class body, never a trailing lambda, also after the
|
|
361
379
|
// last operand of an operator (`B by a ?: b { … }`): the scanner ends the expression before it.
|
|
362
|
-
explicit_delegation: ($) => seq($.type, 'by', $.expression, optional(
|
|
380
|
+
explicit_delegation: ($) => seq($.type, 'by', $.expression, optional(sym('_delegation_end'))),
|
|
363
381
|
|
|
364
382
|
getter: ($) =>
|
|
365
383
|
prec.right(
|
|
@@ -389,7 +407,7 @@ module.exports = grammar({
|
|
|
389
407
|
|
|
390
408
|
function_body: ($) => choice($.block, seq('=', $.expression)),
|
|
391
409
|
|
|
392
|
-
block: ($) => seq('{',
|
|
410
|
+
block: ($) => seq('{', sym('_open_statements'), optional($._statements), '}', sym('_close_braces')),
|
|
393
411
|
|
|
394
412
|
for_statement: ($) =>
|
|
395
413
|
prec.right(
|
|
@@ -433,10 +451,11 @@ module.exports = grammar({
|
|
|
433
451
|
|
|
434
452
|
_loop_prefix: ($) => prec.dynamic(1, repeat1(choice($.annotation, $.label))),
|
|
435
453
|
|
|
436
|
-
class_body: ($) =>
|
|
454
|
+
class_body: ($) =>
|
|
455
|
+
seq('{', sym('_open_members'), repeat($._class_member_with_separator), '}', sym('_close_braces')),
|
|
437
456
|
|
|
438
457
|
_class_member_with_separator: ($) =>
|
|
439
|
-
seq($.class_member_declaration, optional(
|
|
458
|
+
seq($.class_member_declaration, optional(sym('_same_line_member_end')), sym('_class_member_semi')),
|
|
440
459
|
|
|
441
460
|
class_member_declaration: ($) =>
|
|
442
461
|
choice($.declaration, $.companion_object, $.anonymous_initializer, $.secondary_constructor),
|
|
@@ -446,11 +465,11 @@ module.exports = grammar({
|
|
|
446
465
|
enum_class_body: ($) =>
|
|
447
466
|
seq(
|
|
448
467
|
'{',
|
|
449
|
-
|
|
468
|
+
sym('_open_members'),
|
|
450
469
|
optionalCommaSep1($.enum_entry),
|
|
451
470
|
optional(seq(';', repeat($._class_member_with_separator))),
|
|
452
471
|
'}',
|
|
453
|
-
|
|
472
|
+
sym('_close_braces')
|
|
454
473
|
),
|
|
455
474
|
|
|
456
475
|
// Only annotations can modify an enum entry, and with the full modifier list a `context` after an annotation would
|
|
@@ -467,7 +486,7 @@ module.exports = grammar({
|
|
|
467
486
|
|
|
468
487
|
value_argument: ($) => seq(optional(seq($._identifier, '=')), optional('*'), $.expression),
|
|
469
488
|
|
|
470
|
-
_statements: ($) => seq($.statement, repeat(seq(
|
|
489
|
+
_statements: ($) => seq($.statement, repeat(seq(sym('_semi'), $.statement)), optional(sym('_semi'))),
|
|
471
490
|
|
|
472
491
|
statement: ($) =>
|
|
473
492
|
choice($.declaration, $.assignment, $.for_statement, $.while_statement, $.do_while_statement, $.expression),
|
|
@@ -537,14 +556,16 @@ module.exports = grammar({
|
|
|
537
556
|
|
|
538
557
|
_annotation_arguments: ($) => valueArguments($, alias(token.immediate('('), '(')),
|
|
539
558
|
|
|
540
|
-
type: ($) =>
|
|
541
|
-
|
|
559
|
+
type: ($) => choice($._non_function_type, $.function_type),
|
|
560
|
+
|
|
561
|
+
_non_function_type: ($) =>
|
|
562
|
+
choice($.user_type, $.nullable_type, $.non_nullable_type, $.parenthesized_type, 'dynamic'),
|
|
542
563
|
|
|
543
564
|
user_type: ($) => seq(optional($.type_modifiers), sep1($._simple_user_type, '.')),
|
|
544
565
|
|
|
545
566
|
_simple_user_type: ($) => prec.right(seq($._identifier, optional($.type_arguments))),
|
|
546
567
|
|
|
547
|
-
nullable_type: ($) => seq(optional($.type_modifiers), $.
|
|
568
|
+
nullable_type: ($) => seq(optional($.type_modifiers), $._non_function_type, '?'),
|
|
548
569
|
|
|
549
570
|
non_nullable_type: ($) =>
|
|
550
571
|
prec.right(seq(optional($.type_modifiers), $.type, '&', optional($.type_modifiers), $.type)),
|
|
@@ -580,7 +601,7 @@ module.exports = grammar({
|
|
|
580
601
|
'context',
|
|
581
602
|
'(',
|
|
582
603
|
choice(
|
|
583
|
-
seq(commaSep1($.type), optional(','), ')',
|
|
604
|
+
seq(commaSep1($.type), optional(','), ')', sym('_context_end')),
|
|
584
605
|
seq(
|
|
585
606
|
repeat(seq($.type, ',')),
|
|
586
607
|
seq(optional($.parameter_modifiers), $.parameter),
|
|
@@ -659,6 +680,7 @@ module.exports = grammar({
|
|
|
659
680
|
labeled_expression: ($) => seq($.label, $.expression),
|
|
660
681
|
|
|
661
682
|
binary_expression: ($) => {
|
|
683
|
+
/** @type {[string, number][]} */
|
|
662
684
|
const table = [
|
|
663
685
|
['+', PREC.ADD],
|
|
664
686
|
['-', PREC.ADD],
|
|
@@ -682,12 +704,7 @@ module.exports = grammar({
|
|
|
682
704
|
...table.map(([operator, precedence]) => {
|
|
683
705
|
return prec.left(
|
|
684
706
|
precedence,
|
|
685
|
-
seq(
|
|
686
|
-
field('left', $.expression),
|
|
687
|
-
// @ts-ignore
|
|
688
|
-
field('operator', operator),
|
|
689
|
-
field('right', $.expression)
|
|
690
|
-
)
|
|
707
|
+
seq(field('left', $.expression), field('operator', operator), field('right', $.expression))
|
|
691
708
|
);
|
|
692
709
|
})
|
|
693
710
|
);
|
|
@@ -699,7 +716,7 @@ module.exports = grammar({
|
|
|
699
716
|
is_expression: ($) =>
|
|
700
717
|
prec.left(
|
|
701
718
|
PREC.IN,
|
|
702
|
-
seq(field('left', $.expression), choice('is', alias(
|
|
719
|
+
seq(field('left', $.expression), choice('is', alias(sym('_not_is'), '!is')), field('right', $.type))
|
|
703
720
|
),
|
|
704
721
|
|
|
705
722
|
as_expression: ($) =>
|
|
@@ -714,8 +731,8 @@ module.exports = grammar({
|
|
|
714
731
|
PREC.INFIX,
|
|
715
732
|
seq(
|
|
716
733
|
$.expression,
|
|
717
|
-
optional(
|
|
718
|
-
choice($.identifier, alias(
|
|
734
|
+
optional(sym('_infix_position')),
|
|
735
|
+
choice($.identifier, alias(sym('_infix_get_identifier'), $.identifier)),
|
|
719
736
|
$.expression
|
|
720
737
|
)
|
|
721
738
|
),
|
|
@@ -737,11 +754,11 @@ module.exports = grammar({
|
|
|
737
754
|
lambda_literal: ($) =>
|
|
738
755
|
seq(
|
|
739
756
|
'{',
|
|
740
|
-
|
|
757
|
+
sym('_open_statements'),
|
|
741
758
|
optional(seq(optional($.lambda_parameters), '->')),
|
|
742
|
-
optionalSep1($.statement,
|
|
759
|
+
optionalSep1($.statement, sym('_semi')),
|
|
743
760
|
'}',
|
|
744
|
-
|
|
761
|
+
sym('_close_braces')
|
|
745
762
|
),
|
|
746
763
|
|
|
747
764
|
lambda_parameters: ($) => seq(commaSep1($._lambda_parameter), optional(',')),
|
|
@@ -750,7 +767,10 @@ module.exports = grammar({
|
|
|
750
767
|
choice($.variable_declaration, alias($._destructuring_lambda_parameter, $.multi_variable_declaration)),
|
|
751
768
|
|
|
752
769
|
_destructuring_lambda_parameter: ($) =>
|
|
753
|
-
seq(
|
|
770
|
+
seq(
|
|
771
|
+
$._multi_variable_declaration,
|
|
772
|
+
optional(seq(alias(sym('_destructuring_type_start'), ':'), field('type', $.type)))
|
|
773
|
+
),
|
|
754
774
|
|
|
755
775
|
anonymous_function: ($) =>
|
|
756
776
|
prec.right(
|
|
@@ -809,7 +829,15 @@ module.exports = grammar({
|
|
|
809
829
|
collection_literal: ($) => seq('[', optionalCommaSep1($.expression), ']'),
|
|
810
830
|
|
|
811
831
|
when_expression: ($) =>
|
|
812
|
-
seq(
|
|
832
|
+
seq(
|
|
833
|
+
'when',
|
|
834
|
+
optional($.when_subject),
|
|
835
|
+
'{',
|
|
836
|
+
sym('_open_statements'),
|
|
837
|
+
repeat($.when_entry),
|
|
838
|
+
'}',
|
|
839
|
+
sym('_close_braces')
|
|
840
|
+
),
|
|
813
841
|
|
|
814
842
|
when_subject: ($) =>
|
|
815
843
|
seq('(', optional(seq(repeat($.annotation), 'val', $.variable_declaration, '=')), $.expression, ')'),
|
|
@@ -820,21 +848,21 @@ module.exports = grammar({
|
|
|
820
848
|
optional(seq('if', field('guard', $.expression))),
|
|
821
849
|
'->',
|
|
822
850
|
field('body', choice($.block, $.statement)),
|
|
823
|
-
optional(
|
|
851
|
+
optional(sym('_semi'))
|
|
824
852
|
),
|
|
825
853
|
|
|
826
854
|
_when_condition: ($) => choice($.expression, $.range_test, $.type_test),
|
|
827
855
|
|
|
828
|
-
range_test: ($) => seq(choice(alias(
|
|
856
|
+
range_test: ($) => seq(choice(alias(sym('_in'), 'in'), '!in'), $.expression),
|
|
829
857
|
|
|
830
|
-
type_test: ($) => seq(choice('is', alias(
|
|
858
|
+
type_test: ($) => seq(choice('is', alias(sym('_not_is'), '!is')), $.type),
|
|
831
859
|
|
|
832
860
|
try_expression: ($) =>
|
|
833
861
|
seq(
|
|
834
862
|
'try',
|
|
835
863
|
$.block,
|
|
836
864
|
choice(
|
|
837
|
-
seq(repeat1(seq($.catch_block, optional(
|
|
865
|
+
seq(repeat1(seq($.catch_block, optional(sym('_try_continuation_position')))), optional($.finally_block)),
|
|
838
866
|
$.finally_block
|
|
839
867
|
)
|
|
840
868
|
),
|
|
@@ -842,7 +870,7 @@ module.exports = grammar({
|
|
|
842
870
|
catch_block: ($) => seq('catch', '(', repeat($.annotation), $.identifier, ':', $.type, optional(','), ')', $.block),
|
|
843
871
|
|
|
844
872
|
finally_block: ($) =>
|
|
845
|
-
choice(prec(1, seq(
|
|
873
|
+
choice(prec(1, seq(sym('_try_continuation_position'), 'finally', $.block)), seq('finally', $.block)),
|
|
846
874
|
|
|
847
875
|
return_expression: ($) =>
|
|
848
876
|
prec.right(seq(choice('return', seq('return@', field('label', $.identifier))), optional($.expression))),
|
|
@@ -859,7 +887,7 @@ module.exports = grammar({
|
|
|
859
887
|
prec(
|
|
860
888
|
PREC.CALL,
|
|
861
889
|
choice(
|
|
862
|
-
seq($.expression, choice('.', alias(
|
|
890
|
+
seq($.expression, choice('.', alias(sym('_q_dot'), '?.')), $.identifier),
|
|
863
891
|
seq($.expression, '::', choice($.identifier, 'class'))
|
|
864
892
|
)
|
|
865
893
|
),
|
|
@@ -874,7 +902,7 @@ module.exports = grammar({
|
|
|
874
902
|
choice(
|
|
875
903
|
alias(
|
|
876
904
|
choice(token.immediate(prec(2, seq('\\', /[^bnrt'"\\$]/))), token.immediate(prec(1, /[^"\\$]+/)), '$'),
|
|
877
|
-
|
|
905
|
+
sym('string_content')
|
|
878
906
|
),
|
|
879
907
|
$.escape_sequence,
|
|
880
908
|
$.interpolation
|
|
@@ -883,30 +911,34 @@ module.exports = grammar({
|
|
|
883
911
|
'"'
|
|
884
912
|
),
|
|
885
913
|
seq(
|
|
886
|
-
|
|
914
|
+
sym('_multi_dollar_string_start'),
|
|
887
915
|
repeat(
|
|
888
916
|
choice(
|
|
889
|
-
alias(
|
|
917
|
+
alias(sym('_multi_dollar_string_content'), sym('string_content')),
|
|
890
918
|
$.escape_sequence,
|
|
891
919
|
alias($._multi_dollar_interpolation, $.interpolation)
|
|
892
920
|
)
|
|
893
921
|
),
|
|
894
|
-
|
|
922
|
+
sym('_multi_dollar_string_end')
|
|
895
923
|
)
|
|
896
924
|
),
|
|
897
925
|
|
|
898
926
|
multiline_string_literal: ($) =>
|
|
899
927
|
choice(
|
|
900
|
-
seq('"""', repeat(choice(alias($._multiline_string_content, $.string_content), $.interpolation)), '"""'),
|
|
901
928
|
seq(
|
|
902
|
-
|
|
929
|
+
'"""',
|
|
930
|
+
repeat(choice(alias(sym('_multiline_string_content'), sym('string_content')), $.interpolation)),
|
|
931
|
+
'"""'
|
|
932
|
+
),
|
|
933
|
+
seq(
|
|
934
|
+
sym('_multi_dollar_multiline_string_start'),
|
|
903
935
|
repeat(
|
|
904
936
|
choice(
|
|
905
|
-
alias(
|
|
937
|
+
alias(sym('_multi_dollar_string_content'), sym('string_content')),
|
|
906
938
|
alias($._multi_dollar_interpolation, $.interpolation)
|
|
907
939
|
)
|
|
908
940
|
),
|
|
909
|
-
|
|
941
|
+
sym('_multi_dollar_string_end')
|
|
910
942
|
)
|
|
911
943
|
),
|
|
912
944
|
|
|
@@ -922,13 +954,19 @@ module.exports = grammar({
|
|
|
922
954
|
// As in Kotlin, another hard keyword after `$` is an error: the scanner lexes it, and the grammar then expects
|
|
923
955
|
// `_keyword_reference_end`, which is never scanned. The first alias keeps a name required in `interpolation`; the
|
|
924
956
|
// second makes the end visible when error recovery inserts it as missing, which a hidden token would not be.
|
|
925
|
-
seq(
|
|
957
|
+
seq(
|
|
958
|
+
alias(sym('_keyword_reference'), $.identifier),
|
|
959
|
+
alias(sym('_keyword_reference_end'), 'keyword_reference_end')
|
|
960
|
+
)
|
|
926
961
|
),
|
|
927
962
|
|
|
928
963
|
// In a string prefixed with n dollars (Kotlin 2.1), exactly n dollars start an interpolation; the scanner
|
|
929
964
|
// returns them as one token only where they do.
|
|
930
965
|
_multi_dollar_interpolation: ($) =>
|
|
931
|
-
seq(
|
|
966
|
+
seq(
|
|
967
|
+
sym('_multi_dollar_interpolation_start'),
|
|
968
|
+
choice($._template_name, seq(token.immediate('{'), $.expression, '}'))
|
|
969
|
+
),
|
|
932
970
|
|
|
933
971
|
character_literal: ($) => seq("'", choice(token.immediate(prec(1, /[^'\\\r\n]/)), $.escape_sequence), "'"),
|
|
934
972
|
|
|
@@ -973,7 +1011,7 @@ module.exports = grammar({
|
|
|
973
1011
|
|
|
974
1012
|
label: () => token(/[a-zA-Z_][a-zA-Z_0-9]*@/),
|
|
975
1013
|
|
|
976
|
-
_identifier: ($) => choice($.identifier, $._reserved_identifier, alias(
|
|
1014
|
+
_identifier: ($) => choice($.identifier, $._reserved_identifier, alias(sym('_infix_get_identifier'), $.identifier)),
|
|
977
1015
|
|
|
978
1016
|
identifier: () => token(choice(/[\p{L}_][\p{L}_\p{Nd}]*/u, /`[^\r\n`]+`/)),
|
|
979
1017
|
|
|
@@ -986,6 +1024,7 @@ module.exports = grammar({
|
|
|
986
1024
|
'const',
|
|
987
1025
|
'constructor',
|
|
988
1026
|
'data',
|
|
1027
|
+
'dynamic',
|
|
989
1028
|
'enum',
|
|
990
1029
|
'expect',
|
|
991
1030
|
'external',
|
|
@@ -1019,50 +1058,30 @@ module.exports = grammar({
|
|
|
1019
1058
|
});
|
|
1020
1059
|
|
|
1021
1060
|
/**
|
|
1022
|
-
* Creates a rule to match one or more of the rules separated by `separator`
|
|
1023
|
-
*
|
|
1024
1061
|
* @param {RuleOrLiteral} rule
|
|
1025
|
-
*
|
|
1026
1062
|
* @param {RuleOrLiteral} separator
|
|
1027
|
-
*
|
|
1028
|
-
* @returns {SeqRule}
|
|
1029
1063
|
*/
|
|
1030
1064
|
function sep1(rule, separator) {
|
|
1031
1065
|
return seq(rule, repeat(seq(separator, rule)));
|
|
1032
1066
|
}
|
|
1033
1067
|
|
|
1034
1068
|
/**
|
|
1035
|
-
* Creates a rule to optionally match one or more of the rules separated by `separator`
|
|
1036
|
-
* and optionally ending with `separator`
|
|
1037
|
-
*
|
|
1038
1069
|
* @param {RuleOrLiteral} rule
|
|
1039
|
-
*
|
|
1040
1070
|
* @param {RuleOrLiteral} separator
|
|
1041
|
-
*
|
|
1042
|
-
* @returns {ChoiceRule}
|
|
1043
1071
|
*/
|
|
1044
1072
|
function optionalSep1(rule, separator) {
|
|
1045
1073
|
return optional(seq(rule, repeat(seq(separator, rule)), optional(separator)));
|
|
1046
1074
|
}
|
|
1047
1075
|
|
|
1048
1076
|
/**
|
|
1049
|
-
*
|
|
1050
|
-
*
|
|
1051
|
-
* @param {Rule} rule
|
|
1052
|
-
*
|
|
1053
|
-
* @returns {SeqRule}
|
|
1077
|
+
* @param {RuleOrLiteral} rule
|
|
1054
1078
|
*/
|
|
1055
1079
|
function commaSep1(rule) {
|
|
1056
1080
|
return seq(rule, repeat(seq(',', rule)));
|
|
1057
1081
|
}
|
|
1058
1082
|
|
|
1059
1083
|
/**
|
|
1060
|
-
*
|
|
1061
|
-
* and optionally ending with a comma
|
|
1062
|
-
*
|
|
1063
|
-
* @param {Rule} rule
|
|
1064
|
-
*
|
|
1065
|
-
* @returns {ChoiceRule}
|
|
1084
|
+
* @param {RuleOrLiteral} rule
|
|
1066
1085
|
*/
|
|
1067
1086
|
function optionalCommaSep1(rule) {
|
|
1068
1087
|
return optional(seq(rule, repeat(seq(',', rule)), optional(',')));
|
|
@@ -1073,11 +1092,10 @@ function optionalCommaSep1(rule) {
|
|
|
1073
1092
|
* its arguments, which the lookahead of the scanned `)` reaches, so an edit there makes incremental parsing reparse the
|
|
1074
1093
|
* call instead of reusing a call without the lambda.
|
|
1075
1094
|
*
|
|
1076
|
-
* @param {GrammarSymbols
|
|
1095
|
+
* @param {GrammarSymbols} $
|
|
1077
1096
|
* @param {RuleOrLiteral} open
|
|
1078
1097
|
*
|
|
1079
|
-
* @returns {SeqRule}
|
|
1080
1098
|
*/
|
|
1081
1099
|
function valueArguments($, open) {
|
|
1082
|
-
return seq(open, optionalCommaSep1($.value_argument), alias(
|
|
1100
|
+
return seq(open, optionalCommaSep1($.value_argument), alias(sym('_arguments_end'), ')'));
|
|
1083
1101
|
}
|
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.3",
|
|
4
4
|
"description": "Kotlin grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -45,21 +45,20 @@
|
|
|
45
45
|
"@vitest/browser-playwright": "5.0.3",
|
|
46
46
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
47
47
|
"@willbooster/oxlint-config": "1.4.8",
|
|
48
|
-
"@willbooster/wb": "22.
|
|
49
|
-
"@willbooster/web-tree-sitter": "2.0.
|
|
50
|
-
"conventional-changelog-conventionalcommits": "10.4.
|
|
51
|
-
"lefthook": "2.1
|
|
52
|
-
"oxfmt": "0.
|
|
53
|
-
"oxlint": "1.
|
|
54
|
-
"oxlint-tsgolint": "7.0.
|
|
55
|
-
"playwright": "1.
|
|
48
|
+
"@willbooster/wb": "22.26.1",
|
|
49
|
+
"@willbooster/web-tree-sitter": "2.0.24",
|
|
50
|
+
"conventional-changelog-conventionalcommits": "10.4.1",
|
|
51
|
+
"lefthook": "2.2.1",
|
|
52
|
+
"oxfmt": "0.72.0",
|
|
53
|
+
"oxlint": "1.87.0",
|
|
54
|
+
"oxlint-tsgolint": "7.0.2004",
|
|
55
|
+
"playwright": "1.64.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
|
-
"vite": "8.3.
|
|
59
|
+
"vite": "8.3.4",
|
|
61
60
|
"vitest": "5.0.3",
|
|
62
|
-
"wrangler": "4.
|
|
61
|
+
"wrangler": "4.149.0"
|
|
63
62
|
},
|
|
64
63
|
"peerDependencies": {
|
|
65
64
|
"@willbooster/web-tree-sitter": "^2.0.0"
|
package/src/node-types.json
CHANGED
|
@@ -1753,15 +1753,27 @@
|
|
|
1753
1753
|
"fields": {},
|
|
1754
1754
|
"children": {
|
|
1755
1755
|
"multiple": true,
|
|
1756
|
-
"required":
|
|
1756
|
+
"required": false,
|
|
1757
1757
|
"types": [
|
|
1758
1758
|
{
|
|
1759
|
-
"type": "
|
|
1759
|
+
"type": "non_nullable_type",
|
|
1760
|
+
"named": true
|
|
1761
|
+
},
|
|
1762
|
+
{
|
|
1763
|
+
"type": "nullable_type",
|
|
1764
|
+
"named": true
|
|
1765
|
+
},
|
|
1766
|
+
{
|
|
1767
|
+
"type": "parenthesized_type",
|
|
1760
1768
|
"named": true
|
|
1761
1769
|
},
|
|
1762
1770
|
{
|
|
1763
1771
|
"type": "type_modifiers",
|
|
1764
1772
|
"named": true
|
|
1773
|
+
},
|
|
1774
|
+
{
|
|
1775
|
+
"type": "user_type",
|
|
1776
|
+
"named": true
|
|
1765
1777
|
}
|
|
1766
1778
|
]
|
|
1767
1779
|
}
|
package/tree-sitter-kotlin.wasm
CHANGED
|
Binary file
|