Files
mist-script/src/parser/grammar.pest
T
2026-04-14 02:12:46 +02:00

38 lines
1.0 KiB
Plaintext

WHITESPACE = _{ " " | "\t" | "\r" | "\n" }
COMMENT = _{ "//" ~ (!"\n" ~ ANY)* }
program = { SOI ~ item* ~ EOI }
item = _{ import_decl | function_decl | struct_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 =================
import_decl = { "import" ~ string_lit ~ ";" }
struct_field = { identifier ~ ":" ~ type_expr ~ ";" }
struct_decl = {
"struct" ~ identifier ~ "{" ~ struct_field* ~ "}"
}
param_list = { param ~ ("," ~ param)* ~ ","? }
param = { identifier ~ ":" ~ type_expr }
function_decl = {
"function" ~ identifier ~ "(" ~ param_list? ~ ")" ~ ("->" ~ type_expr)? ~ block
}
// ================= STATEMENTS =================
block = { "{" ~ statement* ~ "}" }
statement = _{ "idk" }
// ================= EXPRESSIONS =================
type_expr = _{ identifier }