Skip to main content

Kotlin Grammar for Tree-sitter

Build NPM crates.io

Kotlin language grammar for Tree-sitter. You can try it out directly on the web.

Icon

The grammar is based on the official language grammar.

Project Structure

File Description
grammar.js The Tree-sitter grammar
grammar-reference.js A direct translation of the Kotlin language grammar that is, however, ambiguous to Tree-sitter
src The generated parser

Setup

npm install

Python Package

Install the Python package from PyPI:

pip install ts-kotlin

The package includes the highlight queries bundled with it. You can access the highlights.scm file using the command-line entry point:

ts-kotlin-highlights

This will print the contents of the queries/highlights.scm file to stdout. The queries directory is automatically included when installing the package via pip.

Usage

from tree_sitter import Parser, Language
from tree_sitter_kotlin import language

# Create parser
lang = Language(language())
parser = Parser(lang)

# Parse Kotlin code
code = b"""
fun greet(name: String): String {
    return "Hello, $name!"
}
"""

tree = parser.parse(code)
print(tree.root_node.sexp())  # Print syntax tree

Development

Compilation

To (re-)compile the grammar, run:

npm run generate

Note that the grammar is written completely in JavaScript (grammar.js), the other source files are generated by tree-sitter.

Testing

To run the unit tests, run:

npm run test

It is also helpful to run the parser on a real Kotlin project's source files.

./node_modules/.bin/tree-sitter parse "/path/to/some/project/**/*.kt"  --quiet --stat

WebAssembly

Compilation

First make sure to have Emscripten installed. If you use Homebrew, you can brew install emscripten. Then run:

npm run build-wasm

Playground

After compiling the grammar to WebAssembly, you can invoke

npm run playground

to launch an interactive editing environment that displays the parsed syntax tree on-the-fly in the browser. You can also view a deployed version of this playground on the web.

Screenshot

Documentation

More documentation on how to create Tree-sitter grammars can be found here.

See also

Metadata

Release files for ts-kotlin 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ts-kotlin 0.0.1
File Size Uploaded Provenance
ts_kotlin-0.0.1.tar.gz 1.7 MB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for ts-kotlin 0.0.1
File
ts_kotlin-0.0.1-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
ts_kotlin-0.0.1-cp38-abi3-win32.whl CPython 3.8 abi3 Windows x86-32 Details
ts_kotlin-0.0.1-cp38-abi3-musllinux_1_2_x86_64.whl CPython 3.8 abi3 Linux musl 1.2+ x86-64 Details
ts_kotlin-0.0.1-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
ts_kotlin-0.0.1-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details

Total release size: 4.0 MB

Release files / ts_kotlin-0.0.1.tar.gz

Download URL ts_kotlin-0.0.1.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
0da21fef22b4aa86cc3e12830c3411db668392c29cfd99f7c784565de42ac51b
BLAKE2b-256 checksum
How to use checksums
77b2004af5a72634f149057827204aaa805f059c327a1737791d29c450ef4240
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Release files / ts_kotlin-0.0.1-cp38-abi3-win_amd64.whl

Download URL ts_kotlin-0.0.1-cp38-abi3-win_amd64.whl
Size 439.5 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
c54c9af526bd53b89cff2ec93217b9ece3166b8044e9af19b8f80800733c6e5d
BLAKE2b-256 checksum
How to use checksums
da59577473a5e05e05516fee2d8b744e47b149de4a9ce7aaeb950577fa56a8bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Release files / ts_kotlin-0.0.1-cp38-abi3-win32.whl

Download URL ts_kotlin-0.0.1-cp38-abi3-win32.whl
Size 440.1 kB
Tags CPython 3.8 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
a9edb8d8f1e1be1278657a187f85bf62e54abb2b72b89743b8641fe8d761f3cb
BLAKE2b-256 checksum
How to use checksums
48579495ffa8d6b4357593d66dd8824f0f9e9f466066bf593d83f72dddc5904e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Release files / ts_kotlin-0.0.1-cp38-abi3-musllinux_1_2_x86_64.whl

Download URL ts_kotlin-0.0.1-cp38-abi3-musllinux_1_2_x86_64.whl
Size 458.8 kB
Tags CPython 3.8 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
77e5a1013346dc39043a0f2831165e0845fd8e3206a164d71ab1cc8d0b804bcb
BLAKE2b-256 checksum
How to use checksums
81d39f048bb9751d24c4cc0517faa57bc333adf90cd2b0f2c3a844516940e08f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Release files / ts_kotlin-0.0.1-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL ts_kotlin-0.0.1-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 459.6 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
ca65cd919d636eeb1a48453145f7e9c04ed72e63d1d6df5bb96038ba20fb251f
BLAKE2b-256 checksum
How to use checksums
c1f196b6dc45e354b24f85acc9d1121486025b6c0799733608a7cdd32fc5289a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Release files / ts_kotlin-0.0.1-cp38-abi3-macosx_11_0_arm64.whl

Download URL ts_kotlin-0.0.1-cp38-abi3-macosx_11_0_arm64.whl
Size 478.0 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b1349d1b2209f458e9ea11c79fad3b6cb5444fe05ad9ae97ebcb1ff92149b0ab
BLAKE2b-256 checksum
How to use checksums
8ca40ee66f515dae99f4f6808b07f060c886cd6923dbeffc0bf0e8801f247674
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Security for ts-kotlin 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.0.1 This release

6 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page