Browse Source

Improved docs

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.66
Erez Shinan 6 years ago
parent
commit
d4f069588d
2 changed files with 9 additions and 30 deletions
  1. +6
    -30
      docs/how_to_use.md
  2. +3
    -0
      docs/index.md

+ 6
- 30
docs/how_to_use.md View File

@@ -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. 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 ## LALR usage


@@ -64,7 +40,7 @@ logging.basicConfig(level=logging.DEBUG)
collision_grammar = ''' collision_grammar = '''
start: as as start: as as
as: a* as: a*
a: 'a'
a: "a"
''' '''
p = Lark(collision_grammar, parser='lalr', debug=True) p = Lark(collision_grammar, parser='lalr', debug=True)
``` ```

+ 3
- 0
docs/index.md View File

@@ -36,6 +36,8 @@ $ pip install lark-parser
* Tutorials * 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 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) * [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 * Guides
* [How to use Lark](how_to_use.md) * [How to use Lark](how_to_use.md)
* Reference * Reference
@@ -44,4 +46,5 @@ $ pip install lark-parser
* [Classes](classes.md) * [Classes](classes.md)
* [Cheatsheet (PDF)](lark_cheatsheet.pdf) * [Cheatsheet (PDF)](lark_cheatsheet.pdf)
* Discussion * Discussion
* [Gitter](https://gitter.im/lark-parser/Lobby)
* [Forum (Google Groups)](https://groups.google.com/forum/#!forum/lark-parser) * [Forum (Google Groups)](https://groups.google.com/forum/#!forum/lark-parser)

Loading…
Cancel
Save