Class impl

This commit is contained in:
2026-05-10 17:35:33 +02:00
parent bb9ad547a3
commit 28d4d784f2
4 changed files with 53 additions and 9 deletions
+7 -1
View File
@@ -94,10 +94,16 @@ pub enum TopLevelKind {
generics: Generics,
fields: Vec<FieldDeclStmt>,
constructor: ClassConstructor,
items: Vec<FunctionDecl>,
items: Vec<ClassItem>,
},
}
#[derive(Debug, Clone, Serialize)]
pub enum ClassItem {
Method(FunctionDecl),
ImplDecl(ImplDecl),
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct Generics(pub Vec<Generic>);
+15 -1
View File
@@ -289,7 +289,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for TopLevelKind {
.map(FieldDeclStmt::from)
.collect(),
constructor: ClassConstructor::from(inner.next().unwrap()),
items: inner.into_iter().map(FunctionDecl::from).collect(),
items: inner.into_iter().map(ClassItem::from).collect(),
},
Rule::enum_decl => TopLevelKind::EnumDecl {
@@ -310,6 +310,20 @@ impl From<pest::iterators::Pair<'_, Rule>> for TopLevelKind {
}
}
impl From<pest::iterators::Pair<'_, Rule>> for ClassItem {
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
let rule = pair.as_rule();
match rule {
Rule::impl_decl | Rule::impl_for_decl => ClassItem::ImplDecl(ImplDecl::from(pair)),
Rule::method => ClassItem::Method(FunctionDecl::from(pair)),
_ => unimplemented!("{rule:#?}"),
}
}
}
impl From<pest::iterators::Pair<'_, Rule>> for ImplDecl {
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
let rule = pair.as_rule();