Inheritance parsing
This commit is contained in:
@@ -325,6 +325,7 @@ impl GenRust for TopLevelKind {
|
|||||||
visibility,
|
visibility,
|
||||||
name,
|
name,
|
||||||
generics,
|
generics,
|
||||||
|
inherits,
|
||||||
fields,
|
fields,
|
||||||
constructor,
|
constructor,
|
||||||
items,
|
items,
|
||||||
|
|||||||
@@ -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>,
|
||||||
|
|||||||
@@ -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* ~ "}"
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
|||||||
@@ -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(),
|
||||||
|
|||||||
Reference in New Issue
Block a user