@willbooster/tree-sitter-kotlin 1.5.4 → 1.5.6
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 +43 -15
- package/package.json +1 -1
- package/tree-sitter-kotlin.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -122,6 +122,37 @@ module.exports = grammar({
|
|
|
122
122
|
|
|
123
123
|
word: ($) => $.identifier,
|
|
124
124
|
|
|
125
|
+
// Kotlin's hard keywords are never names. `true`, `false`, `null`, and `typeof` are hard keywords too, but this
|
|
126
|
+
// grammar has no tokens for them, so they still parse as names.
|
|
127
|
+
reserved: {
|
|
128
|
+
global: () => [
|
|
129
|
+
'as',
|
|
130
|
+
'break',
|
|
131
|
+
'class',
|
|
132
|
+
'continue',
|
|
133
|
+
'do',
|
|
134
|
+
'else',
|
|
135
|
+
'for',
|
|
136
|
+
'fun',
|
|
137
|
+
'if',
|
|
138
|
+
'in',
|
|
139
|
+
'interface',
|
|
140
|
+
'is',
|
|
141
|
+
'object',
|
|
142
|
+
'package',
|
|
143
|
+
'return',
|
|
144
|
+
'super',
|
|
145
|
+
'this',
|
|
146
|
+
'throw',
|
|
147
|
+
'try',
|
|
148
|
+
'typealias',
|
|
149
|
+
'val',
|
|
150
|
+
'var',
|
|
151
|
+
'when',
|
|
152
|
+
'while',
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
|
|
125
156
|
rules: {
|
|
126
157
|
source_file: ($) =>
|
|
127
158
|
seq(
|
|
@@ -370,8 +401,9 @@ module.exports = grammar({
|
|
|
370
401
|
statement: ($) =>
|
|
371
402
|
choice($.declaration, $.assignment, $.for_statement, $.while_statement, $.do_while_statement, $.expression),
|
|
372
403
|
|
|
373
|
-
//
|
|
374
|
-
// readings parse, so the one in which
|
|
404
|
+
// Modifiers before a declaration may also read as an annotated expression statement (`@A (b)`) or, for modifier
|
|
405
|
+
// keywords that `_reserved_identifier` accepts, as names, and both readings parse, so the one in which they modify
|
|
406
|
+
// the declaration takes dynamic precedence, as in Kotlin.
|
|
375
407
|
modifiers: ($) =>
|
|
376
408
|
prec.dynamic(
|
|
377
409
|
1,
|
|
@@ -392,22 +424,17 @@ module.exports = grammar({
|
|
|
392
424
|
)
|
|
393
425
|
),
|
|
394
426
|
|
|
395
|
-
|
|
396
|
-
// an infix call as well, since `interface` lexes as an identifier where no keyword is valid, so the modifier
|
|
397
|
-
// reading takes dynamic precedence. The name takes none: it would outweigh the modifiers again wherever a
|
|
398
|
-
// reading has more names, such as `get` calls in a class body misread as a trailing lambda.
|
|
399
|
-
class_modifier: () => prec.dynamic(1, choice('enum', 'sealed', 'annotation', 'data', 'inner', 'value')),
|
|
427
|
+
class_modifier: () => choice('enum', 'sealed', 'annotation', 'data', 'inner', 'value'),
|
|
400
428
|
|
|
401
|
-
function_modifier: () =>
|
|
402
|
-
prec.dynamic(1, prec.right(choice('tailrec', 'operator', 'infix', 'inline', 'external', 'suspend'))),
|
|
429
|
+
function_modifier: () => prec.right(choice('tailrec', 'operator', 'infix', 'inline', 'external', 'suspend')),
|
|
403
430
|
|
|
404
|
-
property_modifier: () =>
|
|
431
|
+
property_modifier: () => 'const',
|
|
405
432
|
|
|
406
|
-
visibility_modifier: () =>
|
|
433
|
+
visibility_modifier: () => choice('public', 'private', 'protected', 'internal'),
|
|
407
434
|
|
|
408
|
-
inheritance_modifier: () =>
|
|
435
|
+
inheritance_modifier: () => choice('abstract', 'final', 'open'),
|
|
409
436
|
|
|
410
|
-
member_modifier: () =>
|
|
437
|
+
member_modifier: () => choice('override', 'lateinit'),
|
|
411
438
|
|
|
412
439
|
parameter_modifiers: ($) => repeat1(choice($.annotation, $.parameter_modifier)),
|
|
413
440
|
|
|
@@ -415,7 +442,7 @@ module.exports = grammar({
|
|
|
415
442
|
|
|
416
443
|
reification_modifier: () => 'reified',
|
|
417
444
|
|
|
418
|
-
platform_modifier: () =>
|
|
445
|
+
platform_modifier: () => choice('expect', 'actual'),
|
|
419
446
|
|
|
420
447
|
type_modifiers: ($) => prec.right(repeat1(choice($.annotation, 'suspend'))),
|
|
421
448
|
|
|
@@ -445,7 +472,8 @@ module.exports = grammar({
|
|
|
445
472
|
_receiver_type: ($) =>
|
|
446
473
|
seq(optional($.type_modifiers), choice($.user_type, 'dynamic', $.parenthesized_type, $.nullable_type)),
|
|
447
474
|
|
|
448
|
-
|
|
475
|
+
// `a<B>(c)` also reads as comparisons (`a < B > (c)`); like Kotlin's parser, prefer the type arguments.
|
|
476
|
+
type_arguments: ($) => prec.dynamic(1, seq('<', commaSep1($.type_projection), '>')),
|
|
449
477
|
|
|
450
478
|
type_projection: ($) => choice(seq(repeat($.variance_modifier), $.type), '*'),
|
|
451
479
|
|
package/package.json
CHANGED
package/tree-sitter-kotlin.wasm
CHANGED
|
Binary file
|