traits
This commit is contained in:
+2
-8
@@ -80,7 +80,7 @@ pub enum TopLevelKind {
|
||||
name: Identifier,
|
||||
generics: Generics,
|
||||
requirements: Vec<TypeExpr>,
|
||||
items: Vec<TraitItem>,
|
||||
items: Vec<FunctionDecl>,
|
||||
},
|
||||
EnumDecl {
|
||||
visibility: Visibility,
|
||||
@@ -105,12 +105,6 @@ pub enum TopLevelKind {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum TraitItem {
|
||||
WithBody(FunctionDecl),
|
||||
NoBody(FunctionDecl),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum ClassItem {
|
||||
Method(FunctionDecl),
|
||||
@@ -158,7 +152,7 @@ pub struct FunctionDecl {
|
||||
pub generics: Generics,
|
||||
pub params: ParamList,
|
||||
pub return_type: TypeExpr,
|
||||
pub body: Block,
|
||||
pub body: Option<Block>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
||||
+2
-15
@@ -314,7 +314,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for TopLevelKind {
|
||||
requirements: consume_rule(&mut inner, Rule::trait_requirements)
|
||||
.map(|pair| pair.into_inner().map(TypeExpr::from).collect())
|
||||
.unwrap_or_default(),
|
||||
items: inner.map(TraitItem::from).collect(),
|
||||
items: inner.map(FunctionDecl::from).collect(),
|
||||
},
|
||||
|
||||
_ => unimplemented!("{rule:#?}"),
|
||||
@@ -322,19 +322,6 @@ impl From<pest::iterators::Pair<'_, Rule>> for TopLevelKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pest::iterators::Pair<'_, Rule>> for TraitItem {
|
||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
||||
let rule = pair.as_rule();
|
||||
|
||||
match rule {
|
||||
Rule::method => TraitItem::WithBody(FunctionDecl::from(pair)),
|
||||
Rule::method_no_body => TraitItem::NoBody(FunctionDecl::from(pair)),
|
||||
|
||||
_ => unimplemented!("{rule:#?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pest::iterators::Pair<'_, Rule>> for ClassItem {
|
||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
||||
let rule = pair.as_rule();
|
||||
@@ -789,7 +776,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for FunctionDecl {
|
||||
})
|
||||
.unwrap_or_else(|| ParamList(self_param.into_iter().collect()));
|
||||
|
||||
let body = Block::from(inner.next().unwrap());
|
||||
let body = inner.next().map(Block::from);
|
||||
|
||||
Self {
|
||||
visibility,
|
||||
|
||||
Reference in New Issue
Block a user