Prefix parsing

This commit is contained in:
2026-05-04 19:58:34 +02:00
parent c083a547d7
commit ba24db481c
4 changed files with 47 additions and 4 deletions
+26 -1
View File
@@ -275,11 +275,24 @@ impl From<pest::iterators::Pair<'_, Rule>> for Expression {
match pair.as_rule() {
Rule::expr => {
let mut inner = pair.into_inner();
let mut prefixes = Vec::new();
while inner
.peek()
.map(|v| v.as_rule() == Rule::prefix)
.unwrap_or_default()
{
prefixes.push(PreFix::from(inner.next().unwrap()));
}
println!("{:#?}", prefixes);
let exp = Expression::from(inner.next().unwrap());
if inner.len() > 0 {
Expression::Postfix {
Expression::Fix {
initial: Box::new(exp),
prefixes,
postfixes: inner.map(|p| Postfix::from(p)).collect(),
}
} else {
@@ -313,6 +326,18 @@ impl From<pest::iterators::Pair<'_, Rule>> for Expression {
}
}
impl From<pest::iterators::Pair<'_, Rule>> for PreFix {
fn from(pair: pest::iterators::Pair<Rule>) -> Self {
match pair.as_rule() {
Rule::prefix => Self::from(pair.into_inner().next().unwrap()),
Rule::deref_px => Self::Deref,
Rule::mut_ref_px => Self::RefMut,
Rule::ref_px => Self::Ref,
_ => unimplemented!("{pair:#?}"),
}
}
}
impl From<pest::iterators::Pair<'_, Rule>> for Postfix {
fn from(pair: pest::iterators::Pair<Rule>) -> Self {
match pair.as_rule() {