corollary
corollary copied to clipboard
expr_explode doesn't take into account operator precedence
Right now it does a linear scan for the first operator, then splits an expression into two. Operator precedence would split at the highest-precedence operators first, then iterate on the subsections.
fn expr_explode(span: Vec<Expr>) -> Vec<Expr> {
...
for i in 0..span.len() {
if let &ast::Expr::Operator(ref op) = &span[i] {
return vec![ast::Expr::Op(
Box::new(Expr::Span(expr_explode(span[0..i].to_vec().clone()))),
op.to_string(),
Box::new(Expr::Span(expr_explode(span[i+1..].to_vec().clone()))),
)];
}
}
span
}
Oh so that's what Spans are.
Haha, yeah. I think Spans should be refactored into type + arguments or expr + argument vectors, and operator parsing and precedence should be imposed by LALRPOP (see its tutorials for examples). The concept works in practice but isn't really correct.
Yeah, doing it all in the parser would be nicest.