mirror of https://github.com/lark-parser/lark.git
Updated Grammar Reference (markdown)
parent
3cfcc1c86f
commit
a06ea6a1b4
|
@ -24,7 +24,7 @@ Names of rules are always in lowercase, while names of terminals are always in u
|
|||
|
||||
### Rules
|
||||
|
||||
Syntax:
|
||||
**Syntax:**
|
||||
```haskell
|
||||
name : items to match
|
||||
| more items -> optional_alias
|
||||
|
@ -46,7 +46,7 @@ Each item is one of:
|
|||
* item* - Zero or more instances of item
|
||||
* item+ - One or more instances of item
|
||||
|
||||
Examples:
|
||||
**Examples:**
|
||||
```haskell
|
||||
hello_world: "hello" "world"
|
||||
mul: [mul "*"] number // Left-recursion is allowed!
|
||||
|
@ -56,7 +56,7 @@ expr: expr operator expr
|
|||
|
||||
## Terminals
|
||||
|
||||
Syntax:
|
||||
**Syntax:**
|
||||
|
||||
```haskell
|
||||
NAME : literals to match
|
||||
|
@ -70,15 +70,16 @@ Literals can be one of:
|
|||
* "case-insensitive string"i
|
||||
* /case-insensitive re/i
|
||||
|
||||
When using a standard lexer, it is the grammar-author's responsibility to make sure the literals don't collide, or that if they do, they are matched in the desired order. Literals will be matched according to the following order:
|
||||
#### Terminals when using a lexer:
|
||||
|
||||
* Highest priority first (priority is specified as: TERM.number: ...)
|
||||
* Length of literal (for regexps, the longest theoretical match is used)
|
||||
* Length of literal / pattern
|
||||
* Name
|
||||
When using a lexer (standard or contextual), it is the grammar-author's responsibility to make sure the literals don't collide, or that if they do, they are matched in the desired order. Literals are matched in an order according to the following criteria:
|
||||
|
||||
Examples:
|
||||
1. Highest priority first (priority is specified as: TERM.number: ...)
|
||||
2. Length of literal (for regexps, the longest theoretical match is used)
|
||||
3. Length of literal / pattern
|
||||
4. Name
|
||||
|
||||
**Examples:**
|
||||
```haskell
|
||||
IF: "if"
|
||||
INTEGER : /[0-9]+/
|
||||
|
@ -93,11 +94,11 @@ SQL_SELECT: "select"i
|
|||
|
||||
All occurrences of the terminal will be ignored, and won't be part of the parse.
|
||||
|
||||
Syntax:
|
||||
**Syntax:**
|
||||
```haskell
|
||||
%ignore TERMINAL
|
||||
```
|
||||
Example:
|
||||
**Examples:**
|
||||
```haskell
|
||||
%ignore " "
|
||||
COMMENT: "#" /[^\n]/*
|
||||
|
@ -111,11 +112,11 @@ Future versions will allow to import from arbitrary files.
|
|||
|
||||
Future versions will allow to import rules and macros*.
|
||||
|
||||
Syntax:
|
||||
**Syntax:**
|
||||
```haskell
|
||||
%import module.TOKEN
|
||||
```
|
||||
Example:
|
||||
**Example:**
|
||||
```haskell
|
||||
%import common.NUMBER
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue