Last active
December 23, 2018 23:14
-
-
Save aziis98/74e91da6f255300c749e19c2826c4e3c to your computer and use it in GitHub Desktop.
Generate the parser with https://pegjs.org/documentation
This file contains hidden or 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
| Expression | |
| = _ expression:(BinaryExpression / Macro / UnaryExpression / BraceBlock / Value) _ { | |
| return expression; | |
| } | |
| ArgBlock | |
| = BraceBlock / BracketBlock | |
| BracketBlock | |
| = "[" expression:Expression "]" { | |
| return { | |
| __type__: 'bracket-argument', | |
| expression | |
| } | |
| } | |
| BraceBlock | |
| = "{" expression:Expression "}" { | |
| return { | |
| __type__: 'brace-argument', | |
| expression | |
| } | |
| } | |
| Macro | |
| = "\\" name:Identifier args:ArgBlock* { | |
| return { | |
| __type__: 'macro', | |
| name, args | |
| }; | |
| } | |
| UnaryExpression | |
| = op:Operator expression:Expression { | |
| return { | |
| __type__: 'unary', | |
| op, expression | |
| }; | |
| } | |
| BinaryExpression | |
| = left:(_ (Macro / UnaryExpression / Value) _) _ op:Operator _ right:Expression { | |
| return { | |
| __type__: 'binary', | |
| left: left[1], | |
| op, | |
| right | |
| }; | |
| } | |
| Operator | |
| = [\+\-*/=<>%$!?^_]+ { | |
| return text(); | |
| } | |
| Value | |
| = [0-9]+ ("." [0-9]*)? { | |
| return { | |
| __type__: 'value', | |
| value: parseFloat(text()) | |
| }; | |
| } | |
| Identifier | |
| = [a-zA-Z][a-zA-Z0-9]* { | |
| return text(); | |
| } | |
| _ "whitespace" | |
| = [ \t\n\r]* | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment