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 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)] #[derive(Debug, PartialEq, Clone)]

View File

@ -744,11 +744,13 @@ impl Parser {
}, },
ref tok if BinOp::from_sigil_token(tok).is_some() => { ref tok if BinOp::from_sigil_token(tok).is_some() => {
let op = BinOp::from_sigil_token(&self.next()).unwrap(); 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 }) Guard::HalfExpr(HalfExpr { op: Some(op), expr })
}, },
_ => { x => {
let Expression(expr, _) = self.expression()?; //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 }) 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) => { IfExpressionBody::GuardList(ref guard_arms) => {
let alternatives = guard_arms.iter().map(|arm| match arm.guard { let mut alternatives = vec![];
Guard::Pat(ref p) => { for arm in guard_arms {
let item = arm.body.iter().map(|expr| expr.reduce(symbol_table)).collect(); match arm.guard {
p.to_alternative(&cond, item, symbol_table) Guard::Pat(ref p) => {
}, let item = arm.body.iter().map(|expr| expr.reduce(symbol_table)).collect();
Guard::HalfExpr(HalfExpr { op: _, expr: _ }) => { let alt = p.to_alternative(&cond, item, symbol_table);
unimplemented!() alternatives.push(alt);
},
Guard::HalfExpr(HalfExpr { op: _, expr: _ }) => {
return Expr::UnimplementedSigilValue
}
} }
}).collect(); }
Expr::CaseMatch { cond, alternatives } Expr::CaseMatch { cond, alternatives }
} }
} }