@willbooster/tree-sitter-kotlin 1.6.0 → 1.6.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/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 of 10,000 lines takes
102
- linear time, since consumers parse files while they are being edited. It loads the Wasm build through
103
- @willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after regenerating the parser;
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
- Node.js compatibility (`test/unit/workers.test.ts`).
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
- CI also runs these tests on Linux arm64 and macOS, where the Rust binding compiles the parser natively, and fuzzes the parser with libFuzzer and sanitizers
109
- (`.github/workflows/robustness.yml`).
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
- // Above PREC.CALL so that, as in Kotlin, a `{` after the delegation expression starts the class body instead of a
313
- // trailing lambda. The last operand of an operator expression still takes the lambda (#29).
314
- explicit_delegation: ($) => prec(PREC.DELEGATION, seq($.type, 'by', $.expression)),
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,10 @@ module.exports = grammar({
410
413
  optional($.class_body)
411
414
  ),
412
415
 
413
- value_arguments: ($) => seq('(', optionalCommaSep1($.value_argument), ')'),
416
+ // Whether a call takes a trailing lambda depends on the token after its arguments, which the lookahead of the
417
+ // scanned `)` reaches, so an edit there makes incremental parsing reparse the call instead of reusing a call without
418
+ // the lambda.
419
+ value_arguments: ($) => seq('(', optionalCommaSep1($.value_argument), alias($._arguments_end, ')')),
414
420
 
415
421
  value_argument: ($) => seq(optional(seq($._identifier, '=')), optional('*'), $.expression),
416
422
 
@@ -636,8 +642,10 @@ module.exports = grammar({
636
642
 
637
643
  infix_expression: ($) => prec.left(PREC.INFIX, seq($.expression, $.identifier, $.expression)),
638
644
 
645
+ // Right-associative so that a trailing lambda after arguments belongs to the same call (`f(x) { … }`), as in
646
+ // Kotlin, instead of calling the result of `f(x)`.
639
647
  call_expression: ($) =>
640
- prec.left(
648
+ prec.right(
641
649
  PREC.CALL,
642
650
  seq(
643
651
  $.expression,
@@ -664,7 +672,7 @@ module.exports = grammar({
664
672
  $.function_value_parameters,
665
673
  optional(seq(':', $.type)),
666
674
  optional($.type_constraints),
667
- optional($.function_body)
675
+ $.function_body
668
676
  )
669
677
  ),
670
678
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-kotlin",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "Kotlin grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -28,7 +28,7 @@
28
28
  "lint": "bun wb lint",
29
29
  "lint-fix": "bun wb lint --fix",
30
30
  "prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
31
- "release": "node script/release.mjs",
31
+ "release": "wb release",
32
32
  "prestart": "bun run build-wasm",
33
33
  "start": "tree-sitter playground",
34
34
  "test": "bun wb test",
@@ -39,14 +39,13 @@
39
39
  "verify-full": "bun wb verify --full"
40
40
  },
41
41
  "devDependencies": {
42
- "@semantic-release/exec": "7.1.0",
43
42
  "@tsconfig/bun": "1.0.11",
44
43
  "@types/bun": "1.4.2",
45
44
  "@vitest/browser-playwright": "5.0.1",
46
45
  "@willbooster/oxfmt-config": "1.2.2",
47
46
  "@willbooster/oxlint-config": "1.4.8",
48
- "@willbooster/wb": "22.11.5",
49
- "@willbooster/web-tree-sitter": "1.0.7",
47
+ "@willbooster/wb": "22.13.1",
48
+ "@willbooster/web-tree-sitter": "1.0.8",
50
49
  "conventional-changelog-conventionalcommits": "10.4.0",
51
50
  "lefthook": "2.1.14",
52
51
  "oxfmt": "0.70.0",
Binary file
package/tree-sitter.json CHANGED
@@ -13,7 +13,7 @@
13
13
  }
14
14
  ],
15
15
  "metadata": {
16
- "version": "1.6.0",
16
+ "version": "1.6.2",
17
17
  "license": "MIT",
18
18
  "description": "Kotlin grammar for tree-sitter",
19
19
  "authors": [