An extension to Lark that generates a Javascript standalone
Likely abandoned. No release or commit for years (last release over 4 years ago).
pip install lark-jsLark.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)