From d4f069588dfdbee08d1bffb377dbcfca17cc8fc2 Mon Sep 17 00:00:00 2001 From: Erez Shinan Date: Sun, 6 Jan 2019 14:19:56 +0200 Subject: [PATCH] Improved docs --- docs/how_to_use.md | 36 ++++++------------------------------ docs/index.md | 3 +++ 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/docs/how_to_use.md b/docs/how_to_use.md index 782e54f..c2987df 100644 --- a/docs/how_to_use.md +++ b/docs/how_to_use.md @@ -18,39 +18,15 @@ This is the recommended process for working with Lark: Of course, some specific use-cases may deviate from this process. Feel free to suggest these cases, and I'll add them to this page. -## Basic API Usage +## Getting started -For common use, you only need to know 3 classes: Lark, Tree, Transformer ([[Classes Reference]]) +Browse the [Examples](https://github.com/lark-parser/lark/tree/master/examples) to find a template that suits your purposes. -Here is some mock usage of them. You can see a real example in the [[examples]] +Read the tutorials to get a better understanding of how everything works. (links in the [main page](/)) -```python -from lark import Lark, Transformer - -grammar = """start: rules and more rules - - rule1: other rules AND TOKENS - | rule1 "+" rule2 -> add - | some value [maybe] - - rule2: rule1 "-" (rule2 | "whatever")* - - TOKEN1: "a literal" - TOKEN2: TOKEN1 "and literals" - """ +Use the [Cheatsheet (PDF)](lark_cheatsheet.pdf) for quick reference. -parser = Lark(grammar) - -tree = parser.parse("some input string") - -class MyTransformer(Transformer): - def rule1(self, matches): - return matches[0] + matches[1] - - # I don't have to implement rule2 if I don't feel like it! - -new_tree = MyTransformer().transform(tree) -``` +Use the reference pages for more in-depth explanations. (links in the [main page](/)] ## LALR usage @@ -64,7 +40,7 @@ logging.basicConfig(level=logging.DEBUG) collision_grammar = ''' start: as as as: a* -a: 'a' +a: "a" ''' p = Lark(collision_grammar, parser='lalr', debug=True) ``` diff --git a/docs/index.md b/docs/index.md index 7b513f6..fbaef83 100644 --- a/docs/index.md +++ b/docs/index.md @@ -36,6 +36,8 @@ $ pip install lark-parser * Tutorials * [How to write a DSL](http://blog.erezsh.com/how-to-write-a-dsl-in-python-with-lark/) - Implements a toy LOGO-like language with an interpreter * [How to write a JSON parser](json_tutorial.md) + * External + * [Program Synthesis is Possible](https://www.cs.cornell.edu/~asampson/blog/minisynth.html) - Creates a DSL for Z3 * Guides * [How to use Lark](how_to_use.md) * Reference @@ -44,4 +46,5 @@ $ pip install lark-parser * [Classes](classes.md) * [Cheatsheet (PDF)](lark_cheatsheet.pdf) * Discussion + * [Gitter](https://gitter.im/lark-parser/Lobby) * [Forum (Google Groups)](https://groups.google.com/forum/#!forum/lark-parser)