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.
Metadata
Release files for kopyt 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kopyt-0.0.2.tar.gz | 32.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kopyt-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 66.6 kB
Release files / kopyt-0.0.2.tar.gz
| Download URL | kopyt-0.0.2.tar.gz |
|---|---|
| Size | 32.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
89e053382180bf8c06b1d6c4e9c553acd3a748a7ca0f82c4076b86325f9ee060
|
|
BLAKE2b-256 checksum How to use checksums |
eb402ff256f68c96bf24c7c0eca65b453daf03d434b6d484c451355f278f93bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / kopyt-0.0.2-py3-none-any.whl
| Download URL | kopyt-0.0.2-py3-none-any.whl |
|---|---|
| Size | 33.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9c13538ef8edf5d8448bb8b1f63139142bef49c1d57bea45daeca5c0c6829a89
|
|
BLAKE2b-256 checksum How to use checksums |
933180d702aad8042391b47a329bd3f7c3764e7bfadb47c4e9e966e220b25b30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|