Browse Source

Added docs for on_error

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.9.0
Erez Sh 5 years ago
parent
commit
3b3a8c1c92
3 changed files with 15 additions and 3 deletions
  1. +13
    -2
      docs/classes.md
  2. +1
    -0
      docs/features.md
  3. +1
    -1
      lark/lark.py

+ 13
- 2
docs/classes.md View File

@@ -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`


+ 1
- 0
docs/features.md View File

@@ -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.)


+ 1
- 1
lark/lark.py View File

@@ -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.
""" """


Loading…
Cancel
Save