Last active
June 1, 2023 12:01
-
-
Save iambenkay/ef76f3162cc9da0d83c1a7f7854d0f49 to your computer and use it in GitHub Desktop.
WASL Parsing Expression Grammar for Pest.rs
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
ws = _{ " " | "\t" } | |
wsln = _{ ws | "\n" } | |
COMMENT = _{ "/*" ~ (!"*/" ~ ANY)* ~ "*/" | "//" ~ (!"\n" ~ ANY)* ~ "\n"+ } | |
Program = _{ SOI ~ wsln* ~ (Stmt ~ wsln*)* ~ Stmt? ~ EOI } | |
Stmt = { AssignmentExpr | ForExpr } | |
Identifier = @{ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* } | |
Type = { Identifier } | |
Declaration = { "let" } | |
AssignmentExpr = { Declaration ~ ws+ ~ Identifier ~ ws* ~ "=" ~ ws* ~ Expr ~ ";" } | |
StandaloneExpr = { Expr ~ ";" } | |
NumberExpr = { Float | Integer } | |
Integer = { ASCII_DIGIT+ } | |
Expr = _{ ArithmeticExpr } | |
Float = { ASCII_DIGIT* ~ "." ~ ASCII_DIGIT+ } | |
ArithmeticExpr = { AddExpr } | |
ForExpr = { | |
"for" ~ ws* ~ "(" ~ ws* ~ InExpr | |
~ ws* ~ ")" ~ ws* ~ "{" ~ wsln* ~ (Stmt ~ wsln*)* ~ "}" | |
} | |
InExpr = { Declaration ~ ws+ | |
~ Identifier ~ ws+ ~ "in" ~ ws+ ~ Identifier } | |
AddExpr = { | |
MulExpr ~ ws* ~ "+" ~ ws* ~ AddExpr | |
| MulExpr ~ ws* ~ "-" ~ ws* ~ AddExpr | |
| MulExpr | |
} | |
ArrayExpr = { "[" ~ wsln* ~ (ArithmeticExpr ~ ws* ~ "," ~ wsln*)* | |
~ (ArithmeticExpr ~ ws* ~ ","* ~ wsln*)* ~ "]" } | |
UnitExpr = { | |
"(" ~ ws* ~ ArithmeticExpr ~ ws* ~ ")" | |
| "+" ~ ws* ~ UnitExpr | |
| "-" ~ ws* ~ UnitExpr | |
| Identifier | |
| NumberExpr | |
| ArrayExpr | |
} | |
MulExpr = { | |
UnitExpr ~ ws* ~ "*" ~ ws* ~ MulExpr | |
| UnitExpr ~ ws* ~ "/" ~ ws* ~ MulExpr | |
| UnitExpr | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment