diff --git a/schala-lang/language/src/builtin.rs b/schala-lang/language/src/builtin.rs index 498ca88..f2df113 100644 --- a/schala-lang/language/src/builtin.rs +++ b/schala-lang/language/src/builtin.rs @@ -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)] diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index c045e77..d55c48a 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -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 }) } }) diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index 99f80c3..4ae50ae 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -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 } } }