Testing simple grammar

This commit is contained in:
2026-04-14 02:23:37 +02:00
parent a9c9c03fd3
commit 511895d0f8
5 changed files with 43 additions and 19 deletions
+3 -8
View File
@@ -2,7 +2,7 @@ WHITESPACE = _{ " " | "\t" | "\r" | "\n" }
COMMENT = _{ "//" ~ (!"\n" ~ ANY)* }
program = { SOI ~ item* ~ EOI }
item = _{ import_decl | function_decl | struct_decl }
item = _{ import_decl | function_decl }
// primitives
identifier = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
@@ -16,20 +16,15 @@ inner_str = @{ (!"\"" ~ ANY)* }
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
"function" ~ identifier ~ "(" ~ param_list? ~ ")" ~ (":" ~ type_expr)? ~ block
}
// ================= STATEMENTS =================
block = { "{" ~ statement* ~ "}" }
block = { "{" ~ "}" }
statement = _{ "idk" }