@willbooster/tree-sitter-kotlin 0.0.0-placeholder.0 → 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Amaan Qureshi <amaanq12@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,56 @@
1
1
  # @willbooster/tree-sitter-kotlin
2
2
 
3
- Placeholder that reserves the package name. Use version 1.0.0 or later: https://github.com/WillBooster/tree-sitter-kotlin
3
+ [![npm version](https://img.shields.io/npm/v/@willbooster/tree-sitter-kotlin.svg)](https://www.npmjs.com/package/@willbooster/tree-sitter-kotlin)
4
+ [![license](https://img.shields.io/npm/l/@willbooster/tree-sitter-kotlin.svg)](https://www.npmjs.com/package/@willbooster/tree-sitter-kotlin)
5
+ [![Test](https://github.com/WillBooster/tree-sitter-kotlin/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-kotlin/actions/workflows/test.yml)
6
+ [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
7
+ [![wbfy](https://img.shields.io/badge/wbfy-20.21.1-1e90ff.svg)](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
+ ## Development
27
+
28
+ ```sh
29
+ mise install
30
+ bun install --frozen-lockfile
31
+ bun run build/ci
32
+ bun run test
33
+ script/parse-examples
34
+ ```
35
+
36
+ `bun run test` runs:
37
+
38
+ - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
39
+ - an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case at random,
40
+ reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
41
+ `TREE_SITTER_EDITS` run other or more edits;
42
+ - the Node.js binding test;
43
+ - a check that real-world Kotlin files cloned into `examples/` fail to parse exactly as listed in
44
+ `script/known-failures.txt`. The first run clones them. The example repositories are pinned to commits in
45
+ `script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples` rewrites
46
+ it; review its diff before committing;
47
+ - 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 Node.js addon, which
49
+ `bun run build/ci` rebuilds after regenerating the parser.
50
+
51
+ CI also runs these tests on every platform that gets a prebuild, and fuzzes the parser with libFuzzer and sanitizers
52
+ (`.github/workflows/robustness.yml`).
53
+
54
+ ### References
55
+
56
+ - [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,9 @@
1
+ const assert = require("node:assert");
2
+ const { test } = require("node:test");
3
+
4
+ const Parser = require("tree-sitter");
5
+
6
+ test("can load grammar", () => {
7
+ const parser = new Parser();
8
+ assert.doesNotThrow(() => parser.setLanguage(require(".")));
9
+ });
@@ -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 (_) {}