Inheritance parsing
This commit is contained in:
@@ -325,6 +325,7 @@ impl GenRust for TopLevelKind {
|
||||
visibility,
|
||||
name,
|
||||
generics,
|
||||
inherits,
|
||||
fields,
|
||||
constructor,
|
||||
items,
|
||||
|
||||
@@ -54,6 +54,7 @@ pub enum TopLevelKind {
|
||||
visibility: Visibility,
|
||||
name: Identifier,
|
||||
generics: GenericsDecl,
|
||||
inherits: Option<TypeExpr>,
|
||||
fields: Vec<Spanned<FieldDeclStmt>>,
|
||||
constructor: Spanned<ClassConstructor>,
|
||||
items: Vec<ClassItem>,
|
||||
|
||||
@@ -285,7 +285,7 @@ class_item = _{
|
||||
}
|
||||
|
||||
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* ~ "}"
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
|
||||
@@ -69,6 +69,10 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevelKind {
|
||||
.transpose()
|
||||
.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()),
|
||||
|
||||
constructor: inner.next().unwrap().try_into(),
|
||||
|
||||
Reference in New Issue
Block a user