diff --git a/parser/src/ast.rs b/parser/src/ast.rs index 53fc170..0dc7f6a 100644 --- a/parser/src/ast.rs +++ b/parser/src/ast.rs @@ -13,7 +13,7 @@ pub struct Block(pub Vec); #[derive(Debug, Clone, Serialize)] pub enum TypeExpr { - Identifier(String), + Path(StaticPath), } #[derive(Debug, Clone, Serialize)] diff --git a/parser/src/lib.rs b/parser/src/lib.rs index d260193..cc0eb69 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -39,26 +39,20 @@ impl TryFrom> for TypeExpr { let inner = pair.into_inner().next().unwrap(); TypeExpr::try_from(inner)? } - Rule::identifier => TypeExpr::Identifier(pair.as_str().to_string()), + Rule::static_path => TypeExpr::Path(StaticPath::from(pair)), _ => unimplemented!("{pair:#?}"), }) } } -impl TryFrom> for StaticPath { - type Error = (); - - fn try_from(pair: pest::iterators::Pair<'_, Rule>) -> Result { - if pair.as_str() == "void" { - return Err(()); - } - - Ok(match pair.as_rule() { +impl From> for StaticPath { + fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self { + match pair.as_rule() { Rule::static_path => { StaticPath(pair.into_inner().map(|i| i.as_str().to_string()).collect()) } _ => unimplemented!("{pair:#?}"), - }) + } } }