@willbooster/tree-sitter-kotlin 1.1.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/README.md +14 -8
- package/package.json +8 -23
- package/tree-sitter-kotlin.wasm +0 -0
- package/tree-sitter.json +6 -6
- 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 -6541
- package/src/parser.c +0 -4
- package/src/scanner.c +0 -466
- 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/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,21 @@ 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
|
+
|
|
26
33
|
In Rust, depend on the Git repository; the crate is not published to crates.io:
|
|
27
34
|
|
|
28
35
|
```toml
|
|
@@ -53,16 +60,15 @@ cargo test
|
|
|
53
60
|
- an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case at random,
|
|
54
61
|
reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
|
|
55
62
|
`TREE_SITTER_EDITS` run other or more edits;
|
|
56
|
-
- the Node.js binding test;
|
|
57
63
|
- a check that real-world Kotlin files cloned into `examples/` fail to parse exactly as listed in
|
|
58
64
|
`script/known-failures.txt`. The first run clones them. The example repositories are pinned to commits in
|
|
59
65
|
`script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples` rewrites
|
|
60
66
|
it; review its diff before committing;
|
|
61
67
|
- a performance check (`test/unit/performance.test.ts`) that recovering from an error on each of 10,000 lines takes
|
|
62
|
-
linear time, since consumers parse files while they are being edited. It loads the
|
|
63
|
-
`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.
|
|
64
70
|
|
|
65
|
-
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
|
|
66
72
|
(`.github/workflows/robustness.yml`).
|
|
67
73
|
|
|
68
74
|
### References
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-kotlin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Kotlin grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -14,30 +14,21 @@
|
|
|
14
14
|
},
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"author": "WillBooster Inc.",
|
|
17
|
-
"main": "bindings/node",
|
|
18
|
-
"types": "bindings/node",
|
|
19
17
|
"files": [
|
|
20
18
|
"grammar.js",
|
|
21
19
|
"tree-sitter.json",
|
|
22
|
-
"
|
|
23
|
-
"prebuilds/**",
|
|
24
|
-
"bindings/node/*",
|
|
25
|
-
"queries/*",
|
|
26
|
-
"src/**",
|
|
20
|
+
"src/node-types.json",
|
|
27
21
|
"*.wasm"
|
|
28
22
|
],
|
|
29
23
|
"scripts": {
|
|
30
|
-
"build-prebuilds": "prebuildify --napi --strip --name tree-sitter-kotlin",
|
|
31
24
|
"build-wasm": "tree-sitter build --wasm",
|
|
32
|
-
"build/ci": "tree-sitter generate &&
|
|
25
|
+
"build/ci": "tree-sitter generate && tree-sitter build --wasm",
|
|
33
26
|
"cleanup": "bun wb lint --fix --format",
|
|
34
27
|
"format": "bun wb lint --format",
|
|
35
|
-
"install": "node-gyp-build",
|
|
36
28
|
"lint": "bun wb lint",
|
|
37
29
|
"lint-fix": "bun wb lint --fix",
|
|
38
30
|
"prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
|
|
39
31
|
"release": "wb release",
|
|
40
|
-
"release-test": "node node_modules/semantic-release/bin/semantic-release.js --dry-run --plugins @semantic-release/commit-analyzer @semantic-release/release-notes-generator",
|
|
41
32
|
"prestart": "bun run build-wasm",
|
|
42
33
|
"start": "tree-sitter playground",
|
|
43
34
|
"test": "bun wb test",
|
|
@@ -46,10 +37,6 @@
|
|
|
46
37
|
"verify": "bun wb verify",
|
|
47
38
|
"verify-full": "bun wb verify --full"
|
|
48
39
|
},
|
|
49
|
-
"dependencies": {
|
|
50
|
-
"node-addon-api": "^8.3.0",
|
|
51
|
-
"node-gyp-build": "^4.8.4"
|
|
52
|
-
},
|
|
53
40
|
"devDependencies": {
|
|
54
41
|
"@semantic-release/exec": "7.1.0",
|
|
55
42
|
"@tsconfig/bun": "1.0.11",
|
|
@@ -59,22 +46,20 @@
|
|
|
59
46
|
"@willbooster/wb": "22.8.0",
|
|
60
47
|
"conventional-changelog-conventionalcommits": "10.4.0",
|
|
61
48
|
"lefthook": "2.1.14",
|
|
62
|
-
"node-gyp": "13.0.2",
|
|
63
49
|
"oxfmt": "0.68.0",
|
|
64
50
|
"oxlint": "1.83.0",
|
|
65
51
|
"oxlint-tsgolint": "7.0.2002",
|
|
66
|
-
"prebuildify": "^6.0.1",
|
|
67
52
|
"semantic-release": "25.0.9",
|
|
68
53
|
"sort-package-json": "4.0.0",
|
|
69
|
-
"tree-sitter": "
|
|
70
|
-
"
|
|
71
|
-
"
|
|
54
|
+
"tree-sitter-cli": "0.27.0",
|
|
55
|
+
"typescript": "7.0.2",
|
|
56
|
+
"web-tree-sitter": "0.27.0"
|
|
72
57
|
},
|
|
73
58
|
"peerDependencies": {
|
|
74
|
-
"tree-sitter": "^0.
|
|
59
|
+
"web-tree-sitter": "^0.27.0"
|
|
75
60
|
},
|
|
76
61
|
"peerDependenciesMeta": {
|
|
77
|
-
"tree-sitter": {
|
|
62
|
+
"web-tree-sitter": {
|
|
78
63
|
"optional": true
|
|
79
64
|
}
|
|
80
65
|
},
|
package/tree-sitter-kotlin.wasm
CHANGED
|
Binary file
|
package/tree-sitter.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
],
|
|
15
15
|
"metadata": {
|
|
16
|
-
"version": "1.
|
|
16
|
+
"version": "1.2.0",
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"description": "Kotlin grammar for tree-sitter",
|
|
19
19
|
"authors": [
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"bindings": {
|
|
29
|
-
"c":
|
|
30
|
-
"go":
|
|
29
|
+
"c": false,
|
|
30
|
+
"go": false,
|
|
31
31
|
"java": false,
|
|
32
|
-
"node":
|
|
33
|
-
"python":
|
|
32
|
+
"node": false,
|
|
33
|
+
"python": false,
|
|
34
34
|
"rust": true,
|
|
35
|
-
"swift":
|
|
35
|
+
"swift": false,
|
|
36
36
|
"zig": false
|
|
37
37
|
}
|
|
38
38
|
}
|
package/binding.gyp
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"targets": [
|
|
3
|
-
{
|
|
4
|
-
"target_name": "tree_sitter_kotlin_binding",
|
|
5
|
-
"dependencies": [
|
|
6
|
-
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
|
|
7
|
-
],
|
|
8
|
-
"include_dirs": [
|
|
9
|
-
"src",
|
|
10
|
-
],
|
|
11
|
-
"sources": [
|
|
12
|
-
"bindings/node/binding.cc",
|
|
13
|
-
"src/parser.c",
|
|
14
|
-
"src/scanner.c",
|
|
15
|
-
],
|
|
16
|
-
"conditions": [
|
|
17
|
-
["OS!='win'", {
|
|
18
|
-
"cflags_c": [
|
|
19
|
-
"-std=c11",
|
|
20
|
-
],
|
|
21
|
-
}, { # OS == "win"
|
|
22
|
-
"cflags_c": [
|
|
23
|
-
"/std:c11",
|
|
24
|
-
"/utf-8",
|
|
25
|
-
],
|
|
26
|
-
}],
|
|
27
|
-
],
|
|
28
|
-
}
|
|
29
|
-
]
|
|
30
|
-
}
|
package/bindings/node/binding.cc
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#include <napi.h>
|
|
2
|
-
|
|
3
|
-
typedef struct TSLanguage TSLanguage;
|
|
4
|
-
|
|
5
|
-
extern "C" TSLanguage *tree_sitter_kotlin();
|
|
6
|
-
|
|
7
|
-
// "tree-sitter", "language" hashed with BLAKE2
|
|
8
|
-
const napi_type_tag LANGUAGE_TYPE_TAG = {
|
|
9
|
-
0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
13
|
-
exports["name"] = Napi::String::New(env, "kotlin");
|
|
14
|
-
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_kotlin());
|
|
15
|
-
language.TypeTag(&LANGUAGE_TYPE_TAG);
|
|
16
|
-
exports["language"] = language;
|
|
17
|
-
return exports;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
NODE_API_MODULE(tree_sitter_kotlin_binding, Init)
|
package/bindings/node/index.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
type BaseNode = {
|
|
2
|
-
type: string;
|
|
3
|
-
named: boolean;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
type ChildNode = {
|
|
7
|
-
multiple: boolean;
|
|
8
|
-
required: boolean;
|
|
9
|
-
types: BaseNode[];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
type NodeInfo =
|
|
13
|
-
| (BaseNode & {
|
|
14
|
-
subtypes: BaseNode[];
|
|
15
|
-
})
|
|
16
|
-
| (BaseNode & {
|
|
17
|
-
fields: { [name: string]: ChildNode };
|
|
18
|
-
children: ChildNode[];
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
type Language = {
|
|
22
|
-
name: string;
|
|
23
|
-
language: unknown;
|
|
24
|
-
nodeTypeInfo: NodeInfo[];
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
declare const language: Language;
|
|
28
|
-
export = language;
|
package/bindings/node/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const root = require("path").join(__dirname, "..", "..");
|
|
2
|
-
|
|
3
|
-
module.exports =
|
|
4
|
-
typeof process.versions.bun === "string"
|
|
5
|
-
// Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time
|
|
6
|
-
? require(`../../prebuilds/${process.platform}-${process.arch}/tree-sitter-kotlin.node`)
|
|
7
|
-
: require("node-gyp-build")(root);
|
|
8
|
-
|
|
9
|
-
try {
|
|
10
|
-
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
|
11
|
-
} catch (_) {}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|