From 745afe981aa2e752c94bc51330bcfa0806c40a8b Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 10 Oct 2019 17:50:20 -0700 Subject: [PATCH] Got compilation working again --- schala-lang/language/src/parsing.rs | 6 ++-- schala-lang/language/src/reduced_ast.rs | 44 +++++++++++-------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index d5dc93f..50f2ef4 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -814,9 +814,9 @@ impl Parser { fn if_expr(&mut self) -> ParseResult { expect!(self, Keyword(Kw::If)); let discriminator = if let LCurlyBrace = self.token_handler.peek_kind() { - Some(Box::new(self.expression()?)) - } else { None + } else { + Some(Box::new(self.expression()?)) }; let body = Box::new(self.if_expr_body()?); Ok(Expression::new(self.id_store.fresh(), ExpressionKind::IfExpression { discriminator, body })) @@ -902,7 +902,7 @@ impl Parser { self.token_handler.next(); Condition::Pattern(self.pattern()?) }, - 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.token_handler.next().kind).unwrap(); let expr = self.expression()?; Condition::TruncatedOp(op, expr) diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index c83d714..0aa0031 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -237,27 +237,27 @@ impl<'a> Reducer<'a> { let symbol_table = self.symbol_table; let cond = Box::new(match discriminator { Some(expr) => self.expression(expr), - None => Expr::Lit(Lit::Bool(true)), + None => return Expr::ReductionError(format!("blank cond if-expr not supported")), }); - match *body { + match body { IfExpressionBody::SimpleConditional { then_case, else_case } => { - let then_clause = self.block(then_case); - let else_clause = match else_case { + let then_clause = self.block(&then_case); + let else_clause = match else_case.as_ref() { None => vec![], - Some(stmts) => self.block(stmts), + Some(stmts) => self.block(&stmts), }; Expr::Conditional { cond, then_clause, else_clause } }, - IfExpressionBody::SimplePatternMatch(ref pat, ref then_clause, ref else_clause) => { - let then_clause = self.block(then_clause); - let else_clause = match else_clause { + IfExpressionBody::SimplePatternMatch { pattern, then_case, else_case } => { + let then_clause = self.block(&then_case); + let else_clause = match else_case.as_ref() { None => vec![], - Some(stmts) => self.block(stmts), + Some(stmts) => self.block(&stmts), }; let alternatives = vec![ - pat.to_alternative(then_clause, symbol_table), + pattern.to_alternative(then_clause, symbol_table), Alternative { matchable: Subpattern { tag: None, @@ -274,26 +274,22 @@ impl<'a> Reducer<'a> { alternatives, } }, - IfExpressionBody::GuardList(ref guard_arms) => { + IfExpressionBody::CondList(ref condition_arms) => { let mut alternatives = vec![]; - for arm in guard_arms { - match arm.guard { - Guard::None => { - let item = self.block(&arm.body); - let alt = Alternative { - item, matchable: Subpattern { - tag: None, subpatterns: vec![], - bound_vars: vec![], guard: None, - } - }; - alternatives.push(alt); + for arm in condition_arms { + match arm.condition { + Condition::Expression(ref _expr) => { + return Expr::UnimplementedSigilValue }, - Guard::Pat(ref p) => { + Condition::Pattern(ref p) => { let item = self.block(&arm.body); let alt = p.to_alternative(item, symbol_table); alternatives.push(alt); }, - Guard::HalfExpr(HalfExpr { op: _, expr: _ }) => { + Condition::TruncatedOp(_, _) => { + return Expr::UnimplementedSigilValue + }, + Condition::Else => { return Expr::UnimplementedSigilValue } }