Enums and impl decl
This commit is contained in:
@@ -91,83 +91,6 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Generics {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for ImplDecl {
|
||||
type Error = ParseError<'a>;
|
||||
|
||||
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||
let rule = pair.as_rule();
|
||||
let mut inner = pair.clone().into_inner();
|
||||
|
||||
match rule {
|
||||
Rule::impl_for_decl => Ok(ImplDecl {
|
||||
generics: consume_rule(&mut inner, Rule::generics)
|
||||
.map(Generics::try_from)
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
trait_: Some(TypeExpr::try_from(inner.next().unwrap())?),
|
||||
target: TypeExpr::try_from(inner.next().unwrap())?,
|
||||
methods: inner
|
||||
.map(FunctionDecl::try_from)
|
||||
.collect::<ParseResult<'a, Vec<_>>>()?,
|
||||
}),
|
||||
|
||||
Rule::impl_decl => Ok(ImplDecl {
|
||||
generics: consume_rule(&mut inner, Rule::generics)
|
||||
.map(Generics::try_from)
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
trait_: None,
|
||||
target: TypeExpr::try_from(inner.next().unwrap())?,
|
||||
methods: inner
|
||||
.map(FunctionDecl::try_from)
|
||||
.collect::<ParseResult<'a, Vec<_>>>()?,
|
||||
}),
|
||||
|
||||
_ => unimplemented!("{rule:#?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for EnumItem {
|
||||
type Error = ParseError<'a>;
|
||||
|
||||
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||
let rule = pair.as_rule();
|
||||
let mut inner = pair.clone().into_inner();
|
||||
|
||||
match rule {
|
||||
Rule::enum_named => Ok(EnumItem::Named(Identifier::try_from(
|
||||
inner.next().unwrap(),
|
||||
)?)),
|
||||
|
||||
Rule::enum_tuple => Ok(EnumItem::Tuple(
|
||||
Identifier::try_from(inner.next().unwrap())?,
|
||||
inner
|
||||
.next()
|
||||
.unwrap()
|
||||
.into_inner()
|
||||
.map(TypeExpr::try_from)
|
||||
.collect::<ParseResult<'a, Vec<_>>>()?,
|
||||
)),
|
||||
|
||||
Rule::enum_struct => Ok(EnumItem::Struct(
|
||||
Identifier::try_from(inner.next().unwrap())?,
|
||||
inner
|
||||
.next()
|
||||
.map(|pair| {
|
||||
pair.into_inner()
|
||||
.map(FieldDecl::try_from)
|
||||
.collect::<ParseResult<'a, Vec<_>>>()
|
||||
})
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
)),
|
||||
|
||||
_ => unimplemented!("{rule:#?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Block {
|
||||
type Error = ParseError<'a>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user