@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 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
  [![npm version](https://img.shields.io/npm/v/@willbooster/tree-sitter-kotlin.svg)](https://www.npmjs.com/package/@willbooster/tree-sitter-kotlin)
4
4
  [![license](https://img.shields.io/npm/l/@willbooster/tree-sitter-kotlin.svg)](https://www.npmjs.com/package/@willbooster/tree-sitter-kotlin)
5
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
+ [![Test rust](https://github.com/WillBooster/tree-sitter-kotlin/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-kotlin/actions/workflows/test-rust.yml)
6
7
  [![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
+ [![wbfy](https://img.shields.io/badge/wbfy-20.23.2-1e90ff.svg)](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
- const Parser = require('tree-sitter');
19
- const Kotlin = require('@willbooster/tree-sitter-kotlin');
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
- parser.setLanguage(Kotlin);
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 Node.js addon, which
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 every platform that gets a prebuild, and fuzzes the parser with libFuzzer and sanitizers
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