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