Optional constructor
This commit is contained in:
@@ -56,7 +56,7 @@ pub enum TopLevelKind {
|
||||
generics: GenericsDecl,
|
||||
inherits: Option<ExprPath>,
|
||||
fields: Vec<Spanned<FieldDeclStmt>>,
|
||||
constructor: Spanned<ClassConstructor>,
|
||||
constructor: Option<Spanned<ClassConstructor>>,
|
||||
items: Vec<ClassItem>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ class_item = _{
|
||||
}
|
||||
|
||||
class_decl = {
|
||||
visibility? ~ "class" ~ identifier ~ generics_decl? ~ (":" ~ expr_path)? ~ "{" ~ class_fields ~ class_constructor ~ class_item* ~ "}"
|
||||
visibility? ~ "class" ~ identifier ~ generics_decl? ~ (":" ~ expr_path)? ~ "{" ~ class_fields ~ class_constructor? ~ class_item* ~ "}"
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
|
||||
@@ -75,7 +75,9 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevelKind {
|
||||
|
||||
fields: collect_recovered(inner.next().unwrap().into_inner()),
|
||||
|
||||
constructor: inner.next().unwrap().try_into(),
|
||||
constructor: consume_rule(&mut inner, Rule::class_constructor)
|
||||
.map(Spanned::try_from)
|
||||
.transpose(),
|
||||
|
||||
items: collect_recovered(inner),
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user