Kotlin parser in pure Python
Project description
Kopyt
Kopyt is a Kotlin programming language parser in pure Python, inspired by javalang library.
Installation
pip install -U kopyt
Features
- Supports Kotlin 1.5
- Zero dependency
Requirements
- Python 3.7+
Usage
from kopyt import Parser, node
code = """\
package main
import a.b
import x.y.z.*
fun main() {
println("Hello, world!")
}
"""
parser = Parser(code)
result = parser.parse()
assert result.package is not None
assert result.package.name == "main"
assert len(result.imports) == 2
assert result.imports[0].name == "a.b"
assert result.imports[1].name == "x.y.z"
assert result.imports[1].wildcard
assert len(result.declarations) == 1
assert isinstance(result.declarations[0], node.FunctionDeclaration)
assert result.declarations[0].name == "main"
assert result.declarations[0].position.line == 6
print(result) # this will output a string similar to the original code
All nodes and its members can be found on kopyt/node.py.
Partial Parsing
It is possible to parse partial Kotlin code, for example you want to parse a function declaration:
from kopyt import Parser, node
code = "fun plusOne(x: Int) = x + 1"
parser = Parser(code)
result = parser.parse_function_declaration()
assert result.name == "plusOne"
assert len(result.parameters) == 1
assert result.parameters[0].name == "x"
All parse functions can be found on kopyt/parser.py.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
kopyt-0.0.2.tar.gz
(32.9 kB
view details)
Built Distribution
kopyt-0.0.2-py3-none-any.whl
(33.8 kB
view details)
File details
Details for the file kopyt-0.0.2.tar.gz
.
File metadata
- Download URL: kopyt-0.0.2.tar.gz
- Upload date:
- Size: 32.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89e053382180bf8c06b1d6c4e9c553acd3a748a7ca0f82c4076b86325f9ee060 |
|
MD5 | c734d32fa2b1392c5870fab814ad8e15 |
|
BLAKE2b-256 | eb402ff256f68c96bf24c7c0eca65b453daf03d434b6d484c451355f278f93bb |
File details
Details for the file kopyt-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: kopyt-0.0.2-py3-none-any.whl
- Upload date:
- Size: 33.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c13538ef8edf5d8448bb8b1f63139142bef49c1d57bea45daeca5c0c6829a89 |
|
MD5 | 3873b02da2f7eaebe446ddc9b5e8e47e |
|
BLAKE2b-256 | 933180d702aad8042391b47a329bd3f7c3764e7bfadb47c4e9e966e220b25b30 |