External impl

This commit is contained in:
2026-05-10 17:25:34 +02:00
parent 6f7f11719d
commit bb9ad547a3
3 changed files with 27 additions and 5 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ pub enum TopLevelKind {
generics: Generics,
fields: Vec<FieldDeclStmt>,
constructor: ClassConstructor,
methods: Vec<FunctionDecl>,
items: Vec<FunctionDecl>,
},
}
+25 -3
View File
@@ -289,7 +289,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for TopLevelKind {
.map(FieldDeclStmt::from)
.collect(),
constructor: ClassConstructor::from(inner.next().unwrap()),
methods: inner.into_iter().map(FunctionDecl::from).collect(),
items: inner.into_iter().map(FunctionDecl::from).collect(),
},
Rule::enum_decl => TopLevelKind::EnumDecl {
@@ -303,14 +303,36 @@ impl From<pest::iterators::Pair<'_, Rule>> for TopLevelKind {
Rule::mod_package => TopLevelKind::Mod(Identifier::from(inner.next().unwrap())),
Rule::impl_for_decl => TopLevelKind::ImplDecl(ImplDecl {
Rule::impl_for_decl | Rule::impl_decl => TopLevelKind::ImplDecl(ImplDecl::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();
let mut inner = pair.clone().into_inner();
match rule {
Rule::impl_for_decl => ImplDecl {
generics: consume_rule(&mut inner, Rule::generics)
.map(Generics::from)
.unwrap_or_default(),
trait_: Some(TypeExpr::from(inner.next().unwrap())),
target: TypeExpr::from(inner.next().unwrap()),
methods: inner.map(FunctionDecl::from).collect(),
}),
},
Rule::impl_decl => ImplDecl {
generics: consume_rule(&mut inner, Rule::generics)
.map(Generics::from)
.unwrap_or_default(),
trait_: None,
target: TypeExpr::from(inner.next().unwrap()),
methods: inner.map(FunctionDecl::from).collect(),
},
_ => unimplemented!("{rule:#?}"),
}
+1 -1
View File
@@ -364,7 +364,7 @@ impl ToRust for TopLevelKind {
generics,
fields,
constructor,
methods,
items: methods,
} => {
// Struct decl
cg.addln(&format!(