diff --git a/parser/src/ast.rs b/parser/src/ast.rs index a21380d..2e0ed0c 100644 --- a/parser/src/ast.rs +++ b/parser/src/ast.rs @@ -92,6 +92,14 @@ pub enum TopLevelKind { }, } +#[derive(Debug, Clone, Serialize)] +pub enum Pattern { + Tuple(Path, Vec), + Struct(Path, Vec), + Path(Path), + Id(Identifier), +} + #[derive(Debug, Clone, Serialize)] pub enum EnumItem { Named(Identifier), diff --git a/parser/src/grammar.pest b/parser/src/grammar.pest index f3a50a3..5dc2706 100644 --- a/parser/src/grammar.pest +++ b/parser/src/grammar.pest @@ -12,10 +12,15 @@ string_lit = { "\"" ~ inner_str ~ "\"" } inner_str = @{ (!"\"" ~ ("\\\"" | ANY))* } 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" } mutable = { "mut" } var = { "var" } -var_decl = { (var | type_expr) ~ mutable? ~ identifier } +var_decl = { (var | type_expr) ~ mutable? ~ pattern } semicolon = _{ ";" } // ================= CLASS =================