Handle HalfExpr closer to correct

This commit is contained in:
greg 2018-10-19 11:02:10 -07:00
parent 354148c5ba
commit dca9ad06c3
3 changed files with 26 additions and 11 deletions

View File

@ -79,6 +79,15 @@ impl BinOp {
default
}))
}
pub fn get_precedence(&self) -> i32 {
let s: &str = &self.sigil;
let default = 10_000_000;
BINOPS.get(s).map(|x| x.2.clone()).unwrap_or_else(|| {
println!("Warning: operator {} not defined", s);
default
})
}
}
#[derive(Debug, PartialEq, Clone)]

View File

@ -744,11 +744,13 @@ impl Parser {
},
ref tok if BinOp::from_sigil_token(tok).is_some() => {
let op = BinOp::from_sigil_token(&self.next()).unwrap();
let Expression(expr, _) = self.expression()?;
let precedence = op.get_precedence();
let Expression(expr, _) = self.precedence_expr(precedence)?;
Guard::HalfExpr(HalfExpr { op: Some(op), expr })
},
_ => {
let Expression(expr, _) = self.expression()?;
x => {
//TODO - I think there's a better way to do this involving the precedence of ->
let Expression(expr, _) = self.prefix_expr()?;
Guard::HalfExpr(HalfExpr { op: None, expr })
}
})

View File

@ -171,15 +171,19 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody,
}
},
IfExpressionBody::GuardList(ref guard_arms) => {
let alternatives = guard_arms.iter().map(|arm| match arm.guard {
let mut alternatives = vec![];
for arm in guard_arms {
match arm.guard {
Guard::Pat(ref p) => {
let item = arm.body.iter().map(|expr| expr.reduce(symbol_table)).collect();
p.to_alternative(&cond, item, symbol_table)
let alt = p.to_alternative(&cond, item, symbol_table);
alternatives.push(alt);
},
Guard::HalfExpr(HalfExpr { op: _, expr: _ }) => {
unimplemented!()
return Expr::UnimplementedSigilValue
}
}
}
}).collect();
Expr::CaseMatch { cond, alternatives }
}
}