@@ -25,12 +25,21 @@ Example: | |||||
Lark(...) | Lark(...) | ||||
``` | ``` | ||||
#### parse(self, text) | |||||
#### parse(self, text, start=None, on_error=None) | |||||
Return a complete parse tree for the text (of type Tree) | |||||
Parse the given text, according to the options provided. | |||||
Returns a complete parse tree for the text (of type Tree) | |||||
If a transformer is supplied to `__init__`, returns whatever is the result of the transformation. | If a transformer is supplied to `__init__`, returns whatever is the result of the transformation. | ||||
Parameters: | |||||
* start: str - required if Lark was given multiple possible start symbols (using the start option). | |||||
* on_error: function - if provided, will be called on UnexpectedToken error. Return true to resume parsing. LALR only. | |||||
(See `examples/error_puppet.py` for an example of how to use `on_error`.) | |||||
#### save(self, f) / load(cls, f) | #### save(self, f) / load(cls, f) | ||||
@@ -160,6 +169,8 @@ See the [visitors page](visitors.md) | |||||
## UnexpectedToken | ## UnexpectedToken | ||||
TODO: Explain puppet mechanism (related to on_error) | |||||
## UnexpectedException | ## UnexpectedException | ||||
- `UnexpectedInput` | - `UnexpectedInput` | ||||
@@ -6,6 +6,7 @@ | |||||
- EBNF-inspired grammar, with extra features (See: [Grammar Reference](grammar.md)) | - EBNF-inspired grammar, with extra features (See: [Grammar Reference](grammar.md)) | ||||
- Builds a parse-tree (AST) automagically based on the grammar | - Builds a parse-tree (AST) automagically based on the grammar | ||||
- Stand-alone parser generator - create a small independent parser to embed in your project. | - Stand-alone parser generator - create a small independent parser to embed in your project. | ||||
- Flexible error handling by using a "puppet parser" mechanism (LALR only) | |||||
- Automatic line & column tracking (for both tokens and matched rules) | - Automatic line & column tracking (for both tokens and matched rules) | ||||
- Automatic terminal collision resolution | - Automatic terminal collision resolution | ||||
- Standard library of terminals (strings, numbers, names, etc.) | - Standard library of terminals (strings, numbers, names, etc.) | ||||
@@ -364,7 +364,7 @@ class Lark(Serialize): | |||||
Parameters: | Parameters: | ||||
start: str - required if Lark was given multiple possible start symbols (using the start option). | start: str - required if Lark was given multiple possible start symbols (using the start option). | ||||
on_error: function - if provided, will be called on UnexpectedToken error. Return true to resume parsing. | |||||
on_error: function - if provided, will be called on UnexpectedToken error. Return true to resume parsing. LALR only. | |||||
Returns a tree, unless specified otherwise. | Returns a tree, unless specified otherwise. | ||||
""" | """ | ||||