lark/examples
Erez Sh 9cc57abd8a Added 'cache' option to Lark (Issue #479) 2020-03-31 00:03:16 +03:00
..
relative-imports Examples: add import example 2019-03-03 17:10:36 +01:00
standalone Added 'cache' option to Lark (Issue #479) 2020-03-31 00:03:16 +03:00
README.md Added python_bytecode example + Tiny bugfix 2020-01-12 16:03:16 +02:00
__init__.py Added examples (calc, json) 2017-02-05 13:40:19 +02:00
calc.py Improved documentation and code style (minor) 2018-06-27 16:37:41 +03:00
conf_earley.py Improved documentation and code style (minor) 2018-06-27 16:37:41 +03:00
conf_lalr.py Improved documentation and code style (minor) 2018-06-27 16:37:41 +03:00
custom_lexer.py Added Token.end_pos, and updated docs regarding recent commits 2019-11-17 16:18:27 +02:00
error_reporting_lalr.py Fixed examples for error reporting 2018-06-27 17:04:23 +03:00
fruitflies.png Improved Readme 2017-11-02 13:47:05 +02:00
fruitflies.py Improved Readme 2017-11-02 13:47:05 +02:00
indented_tree.py Added option to provide a custom lexer (with example) 2018-07-10 14:52:40 +03:00
json_parser.py Make the JSON parser fast again 2019-12-25 11:19:10 +02:00
lark.lark Updated lark.lark + added template_lark.lark, showcasing templates 2020-03-29 01:59:39 +01:00
lark_grammar.py Examples: add import example 2019-03-03 17:10:36 +01:00
python2.lark Trimmed whitespaces and ensured a new line on the end of the file 2018-12-20 21:41:35 -02:00
python3.lark Added python_bytecode example + Tiny bugfix 2020-01-12 16:03:16 +02:00
python_bytecode.py Added python_bytecode example + Tiny bugfix 2020-01-12 16:03:16 +02:00
python_parser.py Merge branch 'file-ext-change' of https://github.com/RobRoseKnows/lark into RobRoseKnows-file-ext-change 2018-05-27 11:59:40 +03:00
qscintilla_json.py Improved docs 2018-08-03 16:31:17 +03:00
reconstruct_json.py propagate_positions & maybe_placeholders are now true by default, updated docs, tests & examples accordingly (Issue #449, #451) 2019-11-16 09:38:22 +02:00
template_lark.lark Updated lark.lark + added template_lark.lark, showcasing templates 2020-03-29 01:59:39 +01:00
turtle_dsl.py Earley now uses dynamic lexer by default. Bump to version 0.3.0 2017-08-04 16:05:40 +03:00

README.md

Examples for Lark

How to run the examples

After cloning the repo, open the terminal into the root directory of the project, and run the following:

[lark]$ python -m examples.<name_of_example>

For example, the following will parse all the Python files in the standard library of your local installation:

[lark]$ python -m examples.python_parser

Beginners

  • calc.py - A simple example of a REPL calculator
  • json_parser.py - A simple JSON parser (comes with a tutorial, see docs)
  • indented_tree.py - A demonstration of parsing indentation ("whitespace significant" language)
  • fruitflies.py - A demonstration of ambiguity
  • turtle_dsl.py - Implements a LOGO-like toy language for Python's turtle, with interpreter.
  • lark_grammar.py + lark.lark - A reference implementation of the Lark grammar (using LALR(1) + standard lexer)

Advanced

  • error_reporting_lalr.py - A demonstration of example-driven error reporting with the LALR parser
  • python_parser.py - A fully-working Python 2 & 3 parser (but not production ready yet!)
  • python_bytecode.py - A toy example showing how to compile Python directly to bytecode
  • conf_lalr.py - Demonstrates the power of LALR's contextual lexer on a toy configuration language
  • conf_earley.py - Demonstrates the power of Earley's dynamic lexer on a toy configuration language
  • custom_lexer.py - Demonstrates using a custom lexer to parse a non-textual stream of data
  • reconstruct_json.py - Demonstrates the experimental text-reconstruction feature