Skip to content

Commit 3c5e7a1

Browse files
authored
Merge pull request #637 from ratmice/lex_syntax_docs
Add some docs on lex syntax
2 parents 8858a0c + ed28792 commit 3c5e7a1

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

doc/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Extensions](lexextensions.md)
88
- [Hand-written lexers](manuallexer.md)
99
- [Start States](start_states.md)
10+
- [Syntax](lexsyntax.md)
1011
- [Parsing](parsing.md)
1112
- [Yacc compatibility](yacccompatibility.md)
1213
- [Extensions](yaccextensions.md)

doc/src/lexsyntax.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
The syntax of the lrlex `.l` format, aims to be familiar to the format used by posix lex.
2+
It uses the same basic structure as lex.
3+
4+
```
5+
Definitions
6+
%%
7+
Rules
8+
%%
9+
User Subroutines
10+
```
11+
12+
## Definitions
13+
14+
Within the definitions section, you can add an option `%grmtools` section
15+
documented in [extensions](./lexextensions.md)
16+
17+
## Rules
18+
19+
Each rule is given by the following elements in sequence:
20+
21+
1. Optional Start State, a name given between angle brackets for example `<Start_State>` documented in [Start States](./start_states.md)
22+
2. Regex, syntax defined by the rust [regex](https://docs.rs/regex) crate with optional escaping for any character.
23+
3. Separator space, any horizontal space character in the unicode `Pattern_White_Space` character set
24+
4. Optional State operator, given between angle brackets documented in [Start States](./start_states.md)
25+
+ `<+STATE>` Push the state given by `STATE` to the top of the stack.
26+
+ `<-STATE>` Pop the state off the top of the stack.
27+
+ `<STATE>` Replace the state stack with the state `STATE`
28+
5. Token Name, for example `"token"` any non-space character between double quotes, including double quotes.
29+
6. End of line, finishes each rule.
30+
31+
## User Subroutines
32+
33+
Since lrlex doesn't support user actions, it doesn't support User Subroutines either.

0 commit comments

Comments
 (0)