Files
mist/src/parser/grammar.pest
T
2026-04-14 02:28:15 +02:00

37 lines
1011 B
Plaintext

WHITESPACE = _{ " " | "\t" | "\r" | "\n" }
COMMENT = _{ "//" ~ (!"\n" ~ ANY)* }
program = { SOI ~ item* ~ EOI }
item = _{ import_decl | function_decl }
// primitives
identifier = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
integer = @{ ASCII_DIGIT+ }
float = @{ ASCII_DIGIT+ ~ "." ~ ASCII_DIGIT+ }
boolean = { "true" | "false" }
string_lit = { "\"" ~ inner_str ~ "\"" }
inner_str = @{ (!"\"" ~ ANY)* }
// ================= TOP LEVEL =================
export = { "export"? }
import_decl = { "import" ~ string_lit ~ ";" }
param_list = { param ~ ("," ~ param)* ~ ","? }
param = { identifier ~ ":" ~ type_expr }
function_decl = {
export ~ "function" ~ identifier ~ "(" ~ param_list? ~ ")" ~ (":" ~ type_expr)? ~ block
}
// ================= STATEMENTS =================
block = { "{" ~ "}" }
statement = _{ "idk" }
// ================= EXPRESSIONS =================
type_expr = _{ identifier }
expr = { identifier | integer | float | boolean | string_lit }