Optional constructor

This commit is contained in:
2026-06-12 18:25:26 +02:00
parent d4992e76fc
commit ddcffaea92
4 changed files with 28 additions and 20 deletions
+1 -1
View File
@@ -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>,
},
}
+1 -1
View File
@@ -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* ~ "}"
}
// ======================================================
+3 -1
View File
@@ -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),
}),