Browse Source

Added templates documentation

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.10.0
Erez Sh 5 years ago
parent
commit
aac5fc7e87
1 changed files with 24 additions and 0 deletions
  1. +24
    -0
      docs/grammar.md

+ 24
- 0
docs/grammar.md View File

@@ -83,6 +83,29 @@ Terminals also support grammar operators, such as `|`, `+`, `*` and `?`.

Terminals are a linear construct, and therefore may not contain themselves (recursion isn't allowed).

### Templates

Templates are expanded when preprocessing the grammar.

Definition syntax:

```ebnf
my_template{param1, param2, ...}: <EBNF EXPRESSION>
```

Use syntax:

```ebnf
some_rule: my_template{arg1, arg2, ...}
```

Example:
```ebnf
_seperated{x, sep}: x (sep x)* // Define a sequence of 'x sep x sep x ...'

num_list: "[" _seperated{NUMBER, ","} "]" // Will match "[1, 2, 3]" etc.
```

### Priority

Terminals can be assigned priority only when using a lexer (future versions may support Earley's dynamic lexing).
@@ -256,3 +279,4 @@ Note that `%ignore` directives cannot be imported. Imported rules will abide by
### %declare

Declare a terminal without defining it. Useful for plugins.


Loading…
Cancel
Save