pattern grammar and ast

This commit is contained in:
2026-05-07 22:01:12 +02:00
parent cba78c2ac9
commit c51ff01ce8
2 changed files with 14 additions and 1 deletions
+8
View File
@@ -92,6 +92,14 @@ pub enum TopLevelKind {
}, },
} }
#[derive(Debug, Clone, Serialize)]
pub enum Pattern {
Tuple(Path, Vec<Identifier>),
Struct(Path, Vec<Identifier>),
Path(Path),
Id(Identifier),
}
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
pub enum EnumItem { pub enum EnumItem {
Named(Identifier), Named(Identifier),
+6 -1
View File
@@ -12,10 +12,15 @@ string_lit = { "\"" ~ inner_str ~ "\"" }
inner_str = @{ (!"\"" ~ ("\\\"" | ANY))* } inner_str = @{ (!"\"" ~ ("\\\"" | ANY))* }
static_path = { identifier ~ ("::" ~ identifier)* } static_path = { identifier ~ ("::" ~ identifier)* }
// pattern
tuple_pattern = { static_path ~ "(" ~ (identifier ~ ("," ~ identifier)*)? ~ ")" }
struct_pattern = { static_path ~ "{" ~ (identifier ~ ("," ~ identifier)*)? ~ "}" }
pattern = _{ tuple_pattern | struct_pattern | identifier }
export = { "public" } export = { "public" }
mutable = { "mut" } mutable = { "mut" }
var = { "var" } var = { "var" }
var_decl = { (var | type_expr) ~ mutable? ~ identifier } var_decl = { (var | type_expr) ~ mutable? ~ pattern }
semicolon = _{ ";" } semicolon = _{ ";" }
// ================= CLASS ================= // ================= CLASS =================