Tools (Stand-alone, Nearley)

Stand-alone parser

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.

Run using:

python -m

For a play-by-play, read the tutorial

Importing grammars from Nearley.js

Lark comes with a tool to convert grammars from Nearley, a popular Earley library for Javascript. It uses Js2Py to convert and run the Javascript postprocessing code segments.


  1. Install Lark with the nearley component:

pip install lark[nearley]
  1. Acquire a copy of the Nearley codebase. This can be done using:

git clone


The tool can be run using:

python -m <> <start_rule> <path_to_nearley_repo>

Here’s an example of how to import nearley’s calculator example into Lark:

git clone
python -m nearley/examples/calculator/ main ./nearley >

You can use the output as a regular python module:

>>> import ncalc
>>> ncalc.parse('sin(pi/4) ^ e')

The Nearley converter also supports an experimental converter for newer JavaScript (ES6+), using the --es6 flag:

git clone
python -m nearley/examples/calculator/ main nearley --es6 >


  • 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.