/// Ignore WHITESPACE = _{ " " | "\t" | NEWLINE } COMMENT = _{ "//" ~ (!"\n" ~ ANY)* } STMT_TERM = _{ ";"+ } /// Atomics integer = @{ ASCII_DIGIT+ } identifier = @{ !"let" ~ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC)* } /// Unary operations unary_op = _{ minus } // arithmetic minus = { "-" } /// Binary operations bin_op = _{ add | subtract | multiply | divide | modulo | power | eq | ne | eval } // arithmetic add = { "+" } subtract = { "-" } multiply = { "*" } divide = { "/" } modulo = { "%" } power = { "^" } // comparators eq = { "==" } ne = { "!=" } // evaluation eval = { "@" } /// Expression expr = { atom ~ (bin_op ~ atom)* } atom = _{ unary_op? ~ primary } primary = _{ integer | identifier | "(" ~ expr ~ ")" } /// Statements polenta_stmts = { let_poly_stmt | let_stmt | expr_stmt | assert_stmt } expr_stmt = { expr ~ STMT_TERM } let_stmt = { "let" ~ identifier ~ "=" ~ expr ~ STMT_TERM } let_poly_stmt = { "let" ~ identifier ~ "(" ~ identifier ~ ")" ~ "=" ~ expr ~ STMT_TERM } assert_stmt = { "assert" ~ expr ~ STMT_TERM } /// Main rule polenta = _{ SOI ~ polenta_stmts+ ~ EOI }