Inheritance parsing

This commit is contained in:
2026-05-28 15:55:00 +02:00
parent 86a781c3f2
commit b0f3dccc87
4 changed files with 7 additions and 1 deletions
+1
View File
@@ -325,6 +325,7 @@ impl GenRust for TopLevelKind {
visibility, visibility,
name, name,
generics, generics,
inherits,
fields, fields,
constructor, constructor,
items, items,
+1
View File
@@ -54,6 +54,7 @@ pub enum TopLevelKind {
visibility: Visibility, visibility: Visibility,
name: Identifier, name: Identifier,
generics: GenericsDecl, generics: GenericsDecl,
inherits: Option<TypeExpr>,
fields: Vec<Spanned<FieldDeclStmt>>, fields: Vec<Spanned<FieldDeclStmt>>,
constructor: Spanned<ClassConstructor>, constructor: Spanned<ClassConstructor>,
items: Vec<ClassItem>, items: Vec<ClassItem>,
+1 -1
View File
@@ -285,7 +285,7 @@ class_item = _{
} }
class_decl = { class_decl = {
visibility? ~ "class" ~ identifier ~ generics_decl? ~ "{" ~ class_fields ~ class_constructor ~ class_item* ~ "}" visibility? ~ "class" ~ identifier ~ generics_decl? ~ (":" ~ type_expr)? ~ "{" ~ class_fields ~ class_constructor ~ class_item* ~ "}"
} }
// ====================================================== // ======================================================
+4
View File
@@ -69,6 +69,10 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevelKind {
.transpose() .transpose()
.map(|v| v.unwrap_or_default()), .map(|v| v.unwrap_or_default()),
inherits: consume_rule(&mut inner, Rule::type_expr)
.map(TypeExpr::try_from)
.transpose(),
fields: collect_recovered(inner.next().unwrap().into_inner()), fields: collect_recovered(inner.next().unwrap().into_inner()),
constructor: inner.next().unwrap().try_into(), constructor: inner.next().unwrap().try_into(),