Lark.js
Generate LALR(1) parsers in Javascript
Lark is a popular parsing toolkit for Python.
This project is a live port of the Lark standalone parser to Javascript.
Lark.js takes a .lark grammar, and from it generates a standalone Javascript parser.
The LALR(1) algorithm guarantees O(n) running time (proportional to input length), and minimal memory consumption.
Lark grammars
Lark grammars are written in an augmented EBNF (a textual format), and usually use the .lark extension.
Because they are purely declarative, and don't contain code, they are entirely portable between languages.
It is now possible to use Lark grammars in 3 languages: Python, Javascript, and Julia.
"Hello World" Grammar
The following Lark grammar will match the string "Hello, World!" --
// A bunch of words
start: word+
// Allow optional punctuation after each word
word: WORD ["," | "!"]
// imports WORD from library
%import common.WORD
// Disregard spaces in text
%ignore " "
Quick links
- Documentation
- Examples
- Online IDE
- Gitter chat - A place to ask questions and discuss
- Lark - The Python library
Install Lark.js
Install lark-js on Python:
pip install lark-js --upgrade
Generate a Javascript LALR(1) parser
lark-js my_grammar.lark -o my_parser.js
For help, run:
lark-js --help
Features
- LALR(1) parser - Fast and light
- EBNF grammar
- Builds a parse-tree (AST) automagically, based on the structure of the grammar
- Usable in the browser and in Node.js
- Interactive parsing (step-by-step)
- Error handling
- Tree utilities (including transformers & visitors)
- Line & column tracking
- Standard library of terminals (strings, numbers, names, etc.)
- Import grammars from Nearley.js
Planned features:
- Support for Earley
Syntax Highlighting
Lark provides syntax highlighting for its grammar files (*.lark):
Live Port
Usually, ports from one language to another are at risk of falling out of sync as time goes on.
But Lark.js wasn't translated by hand -- 98% of the lines were transpiled directly from Lark's Python code!
That means that futures updates to Lark-Python (fixes, features, etc.) will automatically sync to Lark.js.
License
Lark.js uses the MIT license.
Contribute
Lark.js is accepting pull-requests. If you would like to help, open an issue or find us on gitter.
Sponsoring
Lark.js was made possible with the help of a generous donation by Smore ❤️
If you like Lark, and want to see it grow, please consider sponsoring us!
Metadata
Release files for lark-js 0.1.4
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 |
|---|---|---|---|---|
| Lark-js-0.1.4.tar.gz | 31.3 kB | Without provenance | Details for Lark-js-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Lark_js-0.1.4-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for Lark_js-0.1.4-py2.py3-none-any.whl |
Total release size: 62.5 kB
Release files / Lark-js-0.1.4.tar.gz
| Download URL | Lark-js-0.1.4.tar.gz |
|---|---|
| Size | 31.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
92899106dbae74db81fd5bc9c4c358f84944c404f5287d66a2ee054a68993386
|
|
BLAKE2b-256 checksum How to use checksums |
9e8548c62bc0f500d36a0ceff3128b480c47f3cb511f4290fad7d1be4ef7ef23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.0 Windows/10
|
Release files / Lark_js-0.1.4-py2.py3-none-any.whl
| Download URL | Lark_js-0.1.4-py2.py3-none-any.whl |
|---|---|
| Size | 31.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
598f88dfb86af21995b61f76084839bcefb623615897751fd3ab7331685585f9
|
|
BLAKE2b-256 checksum How to use checksums |
c4ef4816dc4387219413ff9221a710fbe71687caadd71a1f57a775577e6f8c5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.0 Windows/10
|
Security for lark-js 0.1.4
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.