Tools (Stand-alone, Nearley)¶
Lark can generate a stand-alone LALR(1) parser from a grammar.
The resulting module provides the same interface as Lark, but with a fixed grammar, and reduced functionality.
python -m lark.tools.standalone
For a play-by-play, read the tutorial
Importing grammars from Nearley.js¶
Install Lark with the
pip install lark[nearley]
Acquire a copy of the Nearley codebase. This can be done using:
git clone https://github.com/Hardmath123/nearley
The tool can be run using:
python -m lark.tools.nearley <grammar.ne> <start_rule> <path_to_nearley_repo>
Here’s an example of how to import nearley’s calculator example into Lark:
git clone https://github.com/Hardmath123/nearley python -m lark.tools.nearley nearley/examples/calculator/arithmetic.ne main ./nearley > ncalc.py
You can use the output as a regular python module:
>>> import ncalc >>> ncalc.parse('sin(pi/4) ^ e') 0.38981434460254655
git clone https://github.com/Hardmath123/nearley python -m lark.tools.nearley nearley/examples/calculator/arithmetic.ne main nearley --es6 > ncalc.py
Lark currently cannot import templates from Nearley
Lark currently cannot export grammars to Nearley
These might get added in the future, if enough users ask for them.