Created
September 19, 2018 17:09
-
-
Save bdowning/4dca9f006f230bc7e8c18a2b9c95ff8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const grammar = compileGrammar` | |
| |
Expr | |
= Alternation ${ nth(1) } | |
| |
Alternation | |
= Alternation '|' Sequence ${ leftAssoc(pick('alternation', 1, 3)) } | |
| Sequence ${ nth(1) } | |
| |
Sequence | |
= Sequence Kleene ${ leftAssoc(pick('seq', 1, 2)) } | |
| Kleene ${ nth(1) } | |
| |
Kleene | |
= Element '*' ${ pick('kleene', 1) } | |
| Element '?' ${ pick('alternation', 1, null) } | |
| Element '+' ${ pick('plus', 1) } | |
| Element '{' 'int' '}' ${ pick('repeat', 1, 3) } | |
| Element '{' 'int' ',' '}' ${ pick('repeat', 1, 3, true) } | |
| Element ${ nth(1) } | |
| |
Element | |
= '(' Expr ')' ${ pick('group', 2) } | |
| Charset ${ nth(1) } | |
| '.' ${ () => 'any' } | |
| 'char' ${ nth(1) } | |
| |
Charset | |
= '[' CharsetInner ']' ${ pick('charset', -2) } | |
| '[' '^' CharsetInner ']' ${ pick('charset^', -3) } | |
| |
CharsetInner | |
= CharsetInner 'char' '-' 'char' ${ pick(-1, ['range', 2, 4]) } | |
| CharsetInner 'char' ${ pick(-1, 2) } | |
| null ${ () => [] } | |
| |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment