lakai
Lakai is a wrapper around Lark that provides a convenient API.
Installation
$ pip install lakai
Usage
import lakai
grammar = r"""
%ignore /\s+/
%import common.INT
?atom: INT
?!product: atom | product "*" atom | product "/" atom
?!sum: product | sum "+" product | sum "-" product
"""
parser = lakai.from_string(grammar, start="sum")
tree = parser.parse("1 + 3 * 2 + 4 / 2")
lakai.pprint(tree)
Gives
sum
sum
INT: '1'
PLUS: '+'
product
INT: '3'
STAR: '*'
INT: '2'
PLUS: '+'
product
INT: '4'
SLASH: '/'
INT: '2'
To evaluate the expression, you can use a lakai.Transformer:
import operator
class Computer(lakai.Transformer):
operators = {"/": operator.truediv, "*": operator.mul, "-": operator.sub, "+": operator.add}
def visit_INT(self, leaf: lakai.Leaf) -> int:
return int(leaf.value)
def visit_product(self, node: lakai.Node[Any]) -> int:
return self.operators[node.children[1].value](node.children[0], node.children[2])
visit_sum = visit_product
assert Computer().visit(tree) == 9
To use Lakai with a Lark standalone parser:
import lakai
from ._standalone import Lark_Standalone
parser = lakai.Lakai(Lark_Standalone())
Metadata
Release files for lakai 0.1.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 | Provenance | Actions |
|---|---|---|---|---|
| lakai-0.1.2.tar.gz | 4.5 kB | Without provenance | Details for lakai-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lakai-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for lakai-0.1.2-py3-none-any.whl |
Total release size: 8.8 kB
Release files / lakai-0.1.2.tar.gz
| Download URL | lakai-0.1.2.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f652eedbf25dcbcb315ce39d77fc268ec82cb970b11b7f34958f0363f04552ee
|
|
BLAKE2b-256 checksum How to use checksums |
0fe1d20ade582ca64d8d2d889ea850bf44e93f90ed88b421146f0adaa7a28d0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
|
Release files / lakai-0.1.2-py3-none-any.whl
| Download URL | lakai-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f5f76c44605f53c094964f72261f6eb2d958b247a15f01c4e6fef23819cdf6df
|
|
BLAKE2b-256 checksum How to use checksums |
48bd10283b5b7856093fc8c816bd881400549adbda3b08ae781020a39320b5a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
|
Security for lakai 0.1.2
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.