Enum grammar
This commit is contained in:
+11
-1
@@ -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 ~ "]"
|
||||
|
||||
@@ -9,3 +9,9 @@ class MyClass {
|
||||
println!("{}", self.message);
|
||||
}
|
||||
}
|
||||
|
||||
enum MyEnum {
|
||||
Named,
|
||||
Tuple(i32, String),
|
||||
Struct { i32 x }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user