diff --git a/parser/src/grammar.pest b/parser/src/grammar.pest index 8d0d291..f3a50a3 100644 --- a/parser/src/grammar.pest +++ b/parser/src/grammar.pest @@ -37,7 +37,17 @@ class_decl = { // ================= TOP LEVEL ================= -top_level = { (attributes ~ (import | function_decl | struct_decl | class_decl | mod_package)) | mod_attribute } +enum_named = { identifier } +enum_tuple = { identifier ~ tuple_type } +enum_struct = { identifier ~ "{" ~ field_list ~ "}" } + +enum_field = _{ enum_tuple | enum_struct | enum_named } + +enum_fields = _{ enum_field ~ ("," ~ enum_field)* ~ ","? } + +enum_decl = { export? ~ "enum" ~ identifier ~ "{" ~ enum_fields ~ "}" } + +top_level = { (attributes ~ (import | function_decl | struct_decl | enum_decl | class_decl | mod_package)) | mod_attribute } attribute = { "#" ~ "[" ~ meta ~ "]" diff --git a/test/src/my_class.mist b/test/src/my_class.mist index 48a2c7b..0c31846 100644 --- a/test/src/my_class.mist +++ b/test/src/my_class.mist @@ -9,3 +9,9 @@ class MyClass { println!("{}", self.message); } } + +enum MyEnum { + Named, + Tuple(i32, String), + Struct { i32 x } +}