Handle HalfExpr closer to correct
This commit is contained in:
parent
354148c5ba
commit
dca9ad06c3
@ -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)]
|
||||
|
@ -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 })
|
||||
}
|
||||
})
|
||||
|
@ -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 {
|
||||
Guard::Pat(ref p) => {
|
||||
let item = arm.body.iter().map(|expr| expr.reduce(symbol_table)).collect();
|
||||
p.to_alternative(&cond, item, symbol_table)
|
||||
},
|
||||
Guard::HalfExpr(HalfExpr { op: _, expr: _ }) => {
|
||||
unimplemented!()
|
||||
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();
|
||||
let alt = p.to_alternative(&cond, item, symbol_table);
|
||||
alternatives.push(alt);
|
||||
},
|
||||
Guard::HalfExpr(HalfExpr { op: _, expr: _ }) => {
|
||||
return Expr::UnimplementedSigilValue
|
||||
}
|
||||
}
|
||||
}).collect();
|
||||
}
|
||||
Expr::CaseMatch { cond, alternatives }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user