@willbooster/tree-sitter-kotlin 1.0.0 → 1.2.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/LICENSE +1 -0
- package/README.md +28 -8
- package/grammar.js +583 -891
- package/package.json +16 -22
- package/src/node-types.json +153 -56
- package/tree-sitter-kotlin.wasm +0 -0
- package/tree-sitter.json +9 -7
- package/binding.gyp +0 -30
- package/bindings/node/binding.cc +0 -20
- package/bindings/node/binding_test.js +0 -9
- package/bindings/node/index.d.ts +0 -28
- package/bindings/node/index.js +0 -11
- package/prebuilds/darwin-arm64/tree-sitter-kotlin.node +0 -0
- package/prebuilds/darwin-x64/tree-sitter-kotlin.node +0 -0
- package/prebuilds/linux-arm64/tree-sitter-kotlin.node +0 -0
- package/prebuilds/linux-x64/tree-sitter-kotlin.node +0 -0
- package/src/grammar.json +0 -6445
- package/src/parser.c +0 -677806
- package/src/scanner.c +0 -463
- package/src/tree_sitter/alloc.h +0 -54
- package/src/tree_sitter/array.h +0 -336
- package/src/tree_sitter/parser.h +0 -286
package/LICENSE
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2024 Amaan Qureshi <amaanq12@gmail.com>
|
|
4
|
+
Copyright (c) 2026 WillBooster Inc.
|
|
4
5
|
|
|
5
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
7
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@willbooster/tree-sitter-kotlin)
|
|
4
4
|
[](https://www.npmjs.com/package/@willbooster/tree-sitter-kotlin)
|
|
5
5
|
[](https://github.com/WillBooster/tree-sitter-kotlin/actions/workflows/test.yml)
|
|
6
|
+
[](https://github.com/WillBooster/tree-sitter-kotlin/actions/workflows/test-rust.yml)
|
|
6
7
|
[](https://github.com/semantic-release/semantic-release)
|
|
7
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
8
9
|
|
|
9
10
|
Kotlin grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
|
|
10
11
|
[tree-sitter-grammars/tree-sitter-kotlin](https://github.com/tree-sitter-grammars/tree-sitter-kotlin). We are grateful
|
|
@@ -14,15 +15,34 @@ This fork fixes parsing bugs and raises conformance with the Kotlin grammar.
|
|
|
14
15
|
|
|
15
16
|
## Usage
|
|
16
17
|
|
|
18
|
+
The npm package ships `tree-sitter-kotlin.wasm` for [web-tree-sitter](https://www.npmjs.com/package/web-tree-sitter):
|
|
19
|
+
|
|
17
20
|
```js
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
22
|
+
import { Language, Parser } from 'web-tree-sitter';
|
|
20
23
|
|
|
24
|
+
await Parser.init();
|
|
21
25
|
const parser = new Parser();
|
|
22
|
-
|
|
26
|
+
const wasmPath = fileURLToPath(import.meta.resolve('@willbooster/tree-sitter-kotlin/tree-sitter-kotlin.wasm'));
|
|
27
|
+
parser.setLanguage(await Language.load(wasmPath));
|
|
23
28
|
const tree = parser.parse('fun main() = println("Hello")\n');
|
|
24
29
|
```
|
|
25
30
|
|
|
31
|
+
The package also ships the node types in `src/node-types.json`.
|
|
32
|
+
|
|
33
|
+
In Rust, depend on the Git repository; the crate is not published to crates.io:
|
|
34
|
+
|
|
35
|
+
```toml
|
|
36
|
+
[dependencies]
|
|
37
|
+
tree-sitter = "0.27"
|
|
38
|
+
tree-sitter-kotlin = { package = "willbooster-tree-sitter-kotlin", git = "https://github.com/WillBooster/tree-sitter-kotlin", tag = "v1.1.0" }
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```rust
|
|
42
|
+
let mut parser = tree_sitter::Parser::new();
|
|
43
|
+
parser.set_language(&tree_sitter_kotlin::LANGUAGE.into())?;
|
|
44
|
+
```
|
|
45
|
+
|
|
26
46
|
## Development
|
|
27
47
|
|
|
28
48
|
```sh
|
|
@@ -31,6 +51,7 @@ bun install --frozen-lockfile
|
|
|
31
51
|
bun run build/ci
|
|
32
52
|
bun run test
|
|
33
53
|
script/parse-examples
|
|
54
|
+
cargo test
|
|
34
55
|
```
|
|
35
56
|
|
|
36
57
|
`bun run test` runs:
|
|
@@ -39,16 +60,15 @@ script/parse-examples
|
|
|
39
60
|
- an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case at random,
|
|
40
61
|
reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
|
|
41
62
|
`TREE_SITTER_EDITS` run other or more edits;
|
|
42
|
-
- the Node.js binding test;
|
|
43
63
|
- a check that real-world Kotlin files cloned into `examples/` fail to parse exactly as listed in
|
|
44
64
|
`script/known-failures.txt`. The first run clones them. The example repositories are pinned to commits in
|
|
45
65
|
`script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples` rewrites
|
|
46
66
|
it; review its diff before committing;
|
|
47
67
|
- a performance check (`test/unit/performance.test.ts`) that recovering from an error on each of 10,000 lines takes
|
|
48
|
-
linear time, since consumers parse files while they are being edited. It loads the
|
|
49
|
-
`bun run build/ci` rebuilds after regenerating the parser.
|
|
68
|
+
linear time, since consumers parse files while they are being edited. It loads the Wasm build through
|
|
69
|
+
web-tree-sitter, which `bun run build/ci` rebuilds after regenerating the parser.
|
|
50
70
|
|
|
51
|
-
CI also runs these tests on
|
|
71
|
+
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
|
|
52
72
|
(`.github/workflows/robustness.yml`).
|
|
53
73
|
|
|
54
74
|
### References
|