Updated Grammar Reference (markdown)

Erez Shinan 2017-10-30 18:33:35 +02:00
parent 3cfcc1c86f
commit a06ea6a1b4
1 changed files with 14 additions and 13 deletions

@ -24,7 +24,7 @@ Names of rules are always in lowercase, while names of terminals are always in u
### Rules ### Rules
Syntax: **Syntax:**
```haskell ```haskell
name : items to match name : items to match
| more items -> optional_alias | more items -> optional_alias
@ -46,7 +46,7 @@ Each item is one of:
* item* - Zero or more instances of item * item* - Zero or more instances of item
* item+ - One or more instances of item * item+ - One or more instances of item
Examples: **Examples:**
```haskell ```haskell
hello_world: "hello" "world" hello_world: "hello" "world"
mul: [mul "*"] number // Left-recursion is allowed! mul: [mul "*"] number // Left-recursion is allowed!
@ -56,7 +56,7 @@ expr: expr operator expr
## Terminals ## Terminals
Syntax: **Syntax:**
```haskell ```haskell
NAME : literals to match NAME : literals to match
@ -70,15 +70,16 @@ Literals can be one of:
* "case-insensitive string"i * "case-insensitive string"i
* /case-insensitive re/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: ...) 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:
* Length of literal (for regexps, the longest theoretical match is used)
* Length of literal / pattern
* Name
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 ```haskell
IF: "if" IF: "if"
INTEGER : /[0-9]+/ 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. All occurrences of the terminal will be ignored, and won't be part of the parse.
Syntax: **Syntax:**
```haskell ```haskell
%ignore TERMINAL %ignore TERMINAL
``` ```
Example: **Examples:**
```haskell ```haskell
%ignore " " %ignore " "
COMMENT: "#" /[^\n]/* COMMENT: "#" /[^\n]/*
@ -111,11 +112,11 @@ Future versions will allow to import from arbitrary files.
Future versions will allow to import rules and macros*. Future versions will allow to import rules and macros*.
Syntax: **Syntax:**
```haskell ```haskell
%import module.TOKEN %import module.TOKEN
``` ```
Example: **Example:**
```haskell ```haskell
%import common.NUMBER %import common.NUMBER
``` ```