Static path parsing

This commit is contained in:
2026-05-04 16:42:59 +02:00
parent 8faf663589
commit 8506170d34
2 changed files with 6 additions and 12 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ pub struct Block(pub Vec<Statement>);
#[derive(Debug, Clone, Serialize)]
pub enum TypeExpr {
Identifier(String),
Path(StaticPath),
}
#[derive(Debug, Clone, Serialize)]
+5 -11
View File
@@ -39,26 +39,20 @@ impl TryFrom<pest::iterators::Pair<'_, Rule>> 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<pest::iterators::Pair<'_, Rule>> for StaticPath {
type Error = ();
fn try_from(pair: pest::iterators::Pair<'_, Rule>) -> Result<Self, Self::Error> {
if pair.as_str() == "void" {
return Err(());
}
Ok(match pair.as_rule() {
impl From<pest::iterators::Pair<'_, Rule>> 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:#?}"),
})
}
}
}