@willbooster/tree-sitter-kotlin 1.3.2 → 1.4.0
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 +38 -5
- package/package.json +13 -7
- package/tree-sitter-kotlin.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# @willbooster/tree-sitter-kotlin
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@willbooster/tree-sitter-kotlin)
|
|
4
|
-
[](https://crates.io/crates/willbooster-tree-sitter-kotlin)
|
|
5
4
|
[](https://www.npmjs.com/package/@willbooster/tree-sitter-kotlin)
|
|
6
5
|
[](https://github.com/WillBooster/tree-sitter-kotlin/actions/workflows/test.yml)
|
|
7
6
|
[](https://github.com/WillBooster/tree-sitter-kotlin/actions/workflows/test-rust.yml)
|
|
8
7
|
[](https://github.com/semantic-release/semantic-release)
|
|
9
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
9
|
+
[](https://crates.io/crates/willbooster-tree-sitter-kotlin)
|
|
10
10
|
|
|
11
11
|
Kotlin grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
|
|
12
12
|
[tree-sitter-grammars/tree-sitter-kotlin](https://github.com/tree-sitter-grammars/tree-sitter-kotlin). We are grateful
|
|
@@ -16,11 +16,15 @@ This fork fixes parsing bugs and raises conformance with the Kotlin grammar.
|
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
|
-
The npm package ships `tree-sitter-kotlin.wasm` for
|
|
19
|
+
The npm package ships `tree-sitter-kotlin.wasm` for
|
|
20
|
+
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter), which runs in Node.js, Bun,
|
|
21
|
+
browsers, and Cloudflare Workers.
|
|
22
|
+
|
|
23
|
+
In Node.js and Bun:
|
|
20
24
|
|
|
21
25
|
```js
|
|
22
26
|
import { fileURLToPath } from 'node:url';
|
|
23
|
-
import { Language, Parser } from 'web-tree-sitter';
|
|
27
|
+
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
24
28
|
|
|
25
29
|
await Parser.init();
|
|
26
30
|
const parser = new Parser();
|
|
@@ -29,6 +33,31 @@ parser.setLanguage(await Language.load(wasmPath));
|
|
|
29
33
|
const tree = parser.parse('fun main() = println("Hello")\n');
|
|
30
34
|
```
|
|
31
35
|
|
|
36
|
+
In browsers, load both `.wasm` files by URL. With Vite:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
40
|
+
import runtimeUrl from '@willbooster/web-tree-sitter/web-tree-sitter.wasm?url';
|
|
41
|
+
import kotlinUrl from '@willbooster/tree-sitter-kotlin/tree-sitter-kotlin.wasm?url';
|
|
42
|
+
|
|
43
|
+
await Parser.init({ locateFile: () => runtimeUrl });
|
|
44
|
+
const parser = new Parser();
|
|
45
|
+
parser.setLanguage(await Language.load(kotlinUrl));
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
In Cloudflare Workers, which do not allow compiling Wasm at run time, import both `.wasm` files as modules (with or
|
|
49
|
+
without Node.js compatibility):
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
53
|
+
import runtime from '@willbooster/web-tree-sitter/web-tree-sitter.wasm';
|
|
54
|
+
import kotlin from '@willbooster/tree-sitter-kotlin/tree-sitter-kotlin.wasm';
|
|
55
|
+
|
|
56
|
+
await Parser.init({ wasmModule: runtime });
|
|
57
|
+
const parser = new Parser();
|
|
58
|
+
parser.setLanguage(await Language.load(kotlin));
|
|
59
|
+
```
|
|
60
|
+
|
|
32
61
|
The package also ships the node types in `src/node-types.json`.
|
|
33
62
|
|
|
34
63
|
In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-kotlin):
|
|
@@ -49,6 +78,7 @@ parser.set_language(&tree_sitter_kotlin::LANGUAGE.into())?;
|
|
|
49
78
|
```sh
|
|
50
79
|
mise install
|
|
51
80
|
bun install --frozen-lockfile
|
|
81
|
+
bun run test/ci-setup
|
|
52
82
|
bun run build/ci
|
|
53
83
|
bun run test
|
|
54
84
|
script/parse-examples
|
|
@@ -67,7 +97,10 @@ cargo test
|
|
|
67
97
|
it; review its diff before committing;
|
|
68
98
|
- a performance check (`test/unit/performance.test.ts`) that recovering from an error on each of 10,000 lines takes
|
|
69
99
|
linear time, since consumers parse files while they are being edited. It loads the Wasm build through
|
|
70
|
-
web-tree-sitter, which `bun run build/ci` rebuilds after regenerating the parser
|
|
100
|
+
@willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after regenerating the parser;
|
|
101
|
+
- checks that the Wasm build parses Kotlin through @willbooster/web-tree-sitter in Chromium
|
|
102
|
+
(`test/unit/browser.test.ts`) and in Cloudflare Workers with and without
|
|
103
|
+
Node.js compatibility (`test/unit/workers.test.ts`).
|
|
71
104
|
|
|
72
105
|
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
|
|
73
106
|
(`.github/workflows/robustness.yml`).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-kotlin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Kotlin grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"start": "tree-sitter playground",
|
|
34
34
|
"test": "bun wb test",
|
|
35
35
|
"test/ci": "bun wb test-on-ci",
|
|
36
|
+
"test/ci-setup": "playwright install --with-deps chromium",
|
|
36
37
|
"typecheck": "bun wb typecheck",
|
|
37
38
|
"verify": "bun wb verify",
|
|
38
39
|
"verify-full": "bun wb verify --full"
|
|
@@ -41,25 +42,30 @@
|
|
|
41
42
|
"@semantic-release/exec": "7.1.0",
|
|
42
43
|
"@tsconfig/bun": "1.0.11",
|
|
43
44
|
"@types/bun": "1.4.2",
|
|
45
|
+
"@vitest/browser-playwright": "5.0.1",
|
|
44
46
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
45
47
|
"@willbooster/oxlint-config": "1.4.8",
|
|
46
|
-
"@willbooster/wb": "22.
|
|
48
|
+
"@willbooster/wb": "22.11.5",
|
|
49
|
+
"@willbooster/web-tree-sitter": "1.0.0",
|
|
47
50
|
"conventional-changelog-conventionalcommits": "10.4.0",
|
|
48
51
|
"lefthook": "2.1.14",
|
|
49
|
-
"oxfmt": "0.
|
|
50
|
-
"oxlint": "1.
|
|
52
|
+
"oxfmt": "0.70.0",
|
|
53
|
+
"oxlint": "1.85.0",
|
|
51
54
|
"oxlint-tsgolint": "7.0.2002",
|
|
55
|
+
"playwright": "1.63.0",
|
|
52
56
|
"semantic-release": "25.0.9",
|
|
53
57
|
"sort-package-json": "4.0.0",
|
|
54
58
|
"tree-sitter-cli": "0.27.0",
|
|
55
59
|
"typescript": "7.0.2",
|
|
56
|
-
"
|
|
60
|
+
"vite": "8.3.0",
|
|
61
|
+
"vitest": "5.0.1",
|
|
62
|
+
"wrangler": "4.136.2"
|
|
57
63
|
},
|
|
58
64
|
"peerDependencies": {
|
|
59
|
-
"web-tree-sitter": "^0.
|
|
65
|
+
"@willbooster/web-tree-sitter": "^1.0.0"
|
|
60
66
|
},
|
|
61
67
|
"peerDependenciesMeta": {
|
|
62
|
-
"web-tree-sitter": {
|
|
68
|
+
"@willbooster/web-tree-sitter": {
|
|
63
69
|
"optional": true
|
|
64
70
|
}
|
|
65
71
|
},
|
package/tree-sitter-kotlin.wasm
CHANGED
|
Binary file
|