@willbooster/tree-sitter-kotlin 0.0.0-placeholder.0 → 1.1.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 +22 -0
- package/README.md +68 -1
- package/binding.gyp +30 -0
- package/bindings/node/binding.cc +20 -0
- package/bindings/node/binding_test.js +9 -0
- package/bindings/node/index.d.ts +28 -0
- package/bindings/node/index.js +11 -0
- package/grammar.js +823 -0
- package/package.json +78 -3
- 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 +6541 -0
- package/src/node-types.json +3190 -0
- package/src/parser.c +4 -0
- package/src/scanner.c +466 -0
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +336 -0
- package/src/tree_sitter/parser.h +286 -0
- package/tree-sitter-kotlin.wasm +0 -0
- package/tree-sitter.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Amaan Qureshi <amaanq12@gmail.com>
|
|
4
|
+
Copyright (c) 2026 WillBooster Inc.
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,70 @@
|
|
|
1
1
|
# @willbooster/tree-sitter-kotlin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@willbooster/tree-sitter-kotlin)
|
|
4
|
+
[](https://www.npmjs.com/package/@willbooster/tree-sitter-kotlin)
|
|
5
|
+
[](https://github.com/WillBooster/tree-sitter-kotlin/actions/workflows/test.yml)
|
|
6
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
7
|
+
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
8
|
+
|
|
9
|
+
Kotlin grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
|
|
10
|
+
[tree-sitter-grammars/tree-sitter-kotlin](https://github.com/tree-sitter-grammars/tree-sitter-kotlin). We are grateful
|
|
11
|
+
to its authors and contributors. This is not an official release of that project.
|
|
12
|
+
|
|
13
|
+
This fork fixes parsing bugs and raises conformance with the Kotlin grammar.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const Parser = require('tree-sitter');
|
|
19
|
+
const Kotlin = require('@willbooster/tree-sitter-kotlin');
|
|
20
|
+
|
|
21
|
+
const parser = new Parser();
|
|
22
|
+
parser.setLanguage(Kotlin);
|
|
23
|
+
const tree = parser.parse('fun main() = println("Hello")\n');
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
In Rust, depend on the Git repository; the crate is not published to crates.io:
|
|
27
|
+
|
|
28
|
+
```toml
|
|
29
|
+
[dependencies]
|
|
30
|
+
tree-sitter = "0.27"
|
|
31
|
+
tree-sitter-kotlin = { package = "willbooster-tree-sitter-kotlin", git = "https://github.com/WillBooster/tree-sitter-kotlin", tag = "v1.1.0" }
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```rust
|
|
35
|
+
let mut parser = tree_sitter::Parser::new();
|
|
36
|
+
parser.set_language(&tree_sitter_kotlin::LANGUAGE.into())?;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Development
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
mise install
|
|
43
|
+
bun install --frozen-lockfile
|
|
44
|
+
bun run build/ci
|
|
45
|
+
bun run test
|
|
46
|
+
script/parse-examples
|
|
47
|
+
cargo test
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`bun run test` runs:
|
|
51
|
+
|
|
52
|
+
- the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
|
|
53
|
+
- an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case at random,
|
|
54
|
+
reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
|
|
55
|
+
`TREE_SITTER_EDITS` run other or more edits;
|
|
56
|
+
- the Node.js binding test;
|
|
57
|
+
- a check that real-world Kotlin files cloned into `examples/` fail to parse exactly as listed in
|
|
58
|
+
`script/known-failures.txt`. The first run clones them. The example repositories are pinned to commits in
|
|
59
|
+
`script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples` rewrites
|
|
60
|
+
it; review its diff before committing;
|
|
61
|
+
- 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 Node.js addon, which
|
|
63
|
+
`bun run build/ci` rebuilds after regenerating the parser.
|
|
64
|
+
|
|
65
|
+
CI also runs these tests on every platform that gets a prebuild, and fuzzes the parser with libFuzzer and sanitizers
|
|
66
|
+
(`.github/workflows/robustness.yml`).
|
|
67
|
+
|
|
68
|
+
### References
|
|
69
|
+
|
|
70
|
+
- [Kotlin Grammar](https://kotlinlang.org/docs/reference/grammar.html)
|
package/binding.gyp
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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)
|
|
@@ -0,0 +1,28 @@
|
|
|
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;
|
|
@@ -0,0 +1,11 @@
|
|
|
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 (_) {}
|