@willbooster/tree-sitter-kotlin 1.6.1 → 1.6.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/README.md +13 -7
- package/grammar.js +35 -8
- package/package.json +2 -2
- package/tree-sitter-kotlin.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -98,15 +98,21 @@ cargo test
|
|
|
98
98
|
`script/known-failures.txt`. The first run clones them. The example repositories are pinned to commits in
|
|
99
99
|
`script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples` rewrites
|
|
100
100
|
it; review its diff before committing;
|
|
101
|
-
- a performance check (`test/unit/performance.test.ts`) that recovering from an error on each
|
|
102
|
-
|
|
103
|
-
@willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after regenerating
|
|
101
|
+
- a performance check (`test/unit/performance.test.ts`) that recovering from an error on each line takes linear time
|
|
102
|
+
(ten times the lines take about ten times the CPU time, under a ceiling), since consumers parse files while they are being edited.
|
|
103
|
+
It loads the Wasm build through @willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after regenerating
|
|
104
|
+
the parser;
|
|
105
|
+
- a check that comments containing NUL characters parse (`test/unit/nulCharacters.test.ts`);
|
|
106
|
+
- a check that `package.json` and `Cargo.lock` test the same runtime version (`test/unit/runtimeVersion.test.ts`);
|
|
104
107
|
- checks that the Wasm build parses Kotlin through @willbooster/web-tree-sitter in Chromium
|
|
105
|
-
(`test/unit/browser.test.ts`) and in Cloudflare Workers with and without
|
|
106
|
-
|
|
108
|
+
(`test/unit/browser.test.ts`) and in Cloudflare Workers with and without Node.js compatibility
|
|
109
|
+
(`test/unit/workers.test.ts`).
|
|
107
110
|
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
|
|
112
|
+
by every checkout.
|
|
113
|
+
|
|
114
|
+
CI also runs these tests on Linux arm64 and macOS, where the Rust binding compiles the parser natively, and fuzzes the
|
|
115
|
+
parser with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
|
|
110
116
|
|
|
111
117
|
### References
|
|
112
118
|
|
package/grammar.js
CHANGED
|
@@ -16,7 +16,6 @@ const PREC = {
|
|
|
16
16
|
AS: 12,
|
|
17
17
|
CALL: 13,
|
|
18
18
|
UNARY: 14,
|
|
19
|
-
DELEGATION: 15,
|
|
20
19
|
};
|
|
21
20
|
|
|
22
21
|
// oxlint-disable-next-line unicorn/prefer-module -- This package is CommonJS, so tree-sitter loads grammar.js as CommonJS.
|
|
@@ -108,6 +107,10 @@ module.exports = grammar({
|
|
|
108
107
|
'val',
|
|
109
108
|
// never scanned: it tells the scanner where a primary constructor may start
|
|
110
109
|
$._primary_constructor_position,
|
|
110
|
+
// empty: it ends a delegation expression in a class header before `{` (see `explicit_delegation`)
|
|
111
|
+
$._delegation_end,
|
|
112
|
+
// the `)` that ends a call's arguments (see `value_arguments`)
|
|
113
|
+
$._arguments_end,
|
|
111
114
|
],
|
|
112
115
|
|
|
113
116
|
inline: ($) => [$._statements, $._identifier, $._control_structure_body],
|
|
@@ -309,9 +312,9 @@ module.exports = grammar({
|
|
|
309
312
|
|
|
310
313
|
property_delegate: ($) => seq('by', $.expression),
|
|
311
314
|
|
|
312
|
-
//
|
|
313
|
-
//
|
|
314
|
-
explicit_delegation: ($) =>
|
|
315
|
+
// As in Kotlin, a `{` after the delegation expression starts the class body, never a trailing lambda, also after the
|
|
316
|
+
// last operand of an operator (`B by a ?: b { … }`): the scanner ends the expression before it.
|
|
317
|
+
explicit_delegation: ($) => seq($.type, 'by', $.expression, optional($._delegation_end)),
|
|
315
318
|
|
|
316
319
|
getter: ($) =>
|
|
317
320
|
prec.right(
|
|
@@ -410,7 +413,7 @@ module.exports = grammar({
|
|
|
410
413
|
optional($.class_body)
|
|
411
414
|
),
|
|
412
415
|
|
|
413
|
-
value_arguments: ($) =>
|
|
416
|
+
value_arguments: ($) => valueArguments($, '('),
|
|
414
417
|
|
|
415
418
|
value_argument: ($) => seq(optional(seq($._identifier, '=')), optional('*'), $.expression),
|
|
416
419
|
|
|
@@ -474,7 +477,15 @@ module.exports = grammar({
|
|
|
474
477
|
use_site_target: () =>
|
|
475
478
|
seq(choice('field', 'property', 'get', 'set', 'receiver', 'param', 'setparam', 'delegate'), ':'),
|
|
476
479
|
|
|
477
|
-
|
|
480
|
+
// As in Kotlin, a `(` right after an annotation's name always starts its arguments; lexing it as a separate immediate
|
|
481
|
+
// token keeps an annotated parenthesized expression from being read there. After whitespace, Kotlin's reading
|
|
482
|
+
// depends on the context, so both readings remain.
|
|
483
|
+
_unescaped_annotation: ($) =>
|
|
484
|
+
choice($.constructor_invocation, alias($._annotation_invocation, $.constructor_invocation), $.type),
|
|
485
|
+
|
|
486
|
+
_annotation_invocation: ($) => seq($.type, alias($._annotation_arguments, $.value_arguments)),
|
|
487
|
+
|
|
488
|
+
_annotation_arguments: ($) => valueArguments($, alias(token.immediate('('), '(')),
|
|
478
489
|
|
|
479
490
|
type: ($) =>
|
|
480
491
|
choice($.user_type, $.nullable_type, $.function_type, $.non_nullable_type, $.parenthesized_type, 'dynamic'),
|
|
@@ -636,8 +647,10 @@ module.exports = grammar({
|
|
|
636
647
|
|
|
637
648
|
infix_expression: ($) => prec.left(PREC.INFIX, seq($.expression, $.identifier, $.expression)),
|
|
638
649
|
|
|
650
|
+
// Right-associative so that a trailing lambda after arguments belongs to the same call (`f(x) { … }`), as in
|
|
651
|
+
// Kotlin, instead of calling the result of `f(x)`.
|
|
639
652
|
call_expression: ($) =>
|
|
640
|
-
prec.
|
|
653
|
+
prec.right(
|
|
641
654
|
PREC.CALL,
|
|
642
655
|
seq(
|
|
643
656
|
$.expression,
|
|
@@ -664,7 +677,7 @@ module.exports = grammar({
|
|
|
664
677
|
$.function_value_parameters,
|
|
665
678
|
optional(seq(':', $.type)),
|
|
666
679
|
optional($.type_constraints),
|
|
667
|
-
|
|
680
|
+
$.function_body
|
|
668
681
|
)
|
|
669
682
|
),
|
|
670
683
|
|
|
@@ -956,3 +969,17 @@ function commaSep1(rule) {
|
|
|
956
969
|
function optionalCommaSep1(rule) {
|
|
957
970
|
return optional(seq(rule, repeat(seq(',', rule)), optional(',')));
|
|
958
971
|
}
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* Creates the arguments of a call or an annotation. Whether a call takes a trailing lambda depends on the token after
|
|
975
|
+
* its arguments, which the lookahead of the scanned `)` reaches, so an edit there makes incremental parsing reparse the
|
|
976
|
+
* call instead of reusing a call without the lambda.
|
|
977
|
+
*
|
|
978
|
+
* @param {GrammarSymbols<string>} $
|
|
979
|
+
* @param {RuleOrLiteral} open
|
|
980
|
+
*
|
|
981
|
+
* @returns {SeqRule}
|
|
982
|
+
*/
|
|
983
|
+
function valueArguments($, open) {
|
|
984
|
+
return seq(open, optionalCommaSep1($.value_argument), alias($._arguments_end, ')'));
|
|
985
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-kotlin",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"description": "Kotlin grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
46
46
|
"@willbooster/oxlint-config": "1.4.8",
|
|
47
47
|
"@willbooster/wb": "22.13.1",
|
|
48
|
-
"@willbooster/web-tree-sitter": "1.0.
|
|
48
|
+
"@willbooster/web-tree-sitter": "1.0.8",
|
|
49
49
|
"conventional-changelog-conventionalcommits": "10.4.0",
|
|
50
50
|
"lefthook": "2.1.14",
|
|
51
51
|
"oxfmt": "0.70.0",
|
package/tree-sitter-kotlin.wasm
CHANGED
|
Binary file
|