Got compilation working again

This commit is contained in:
greg 2019-10-10 17:50:20 -07:00
parent a6c86d6447
commit 745afe981a
2 changed files with 23 additions and 27 deletions

View File

@ -814,9 +814,9 @@ impl Parser {
fn if_expr(&mut self) -> ParseResult<Expression> {
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)

View File

@ -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
}
}