corollary icon indicating copy to clipboard operation
corollary copied to clipboard

expr_explode doesn't take into account operator precedence

Open tcr opened this issue 8 years ago • 3 comments

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
}

tcr avatar May 12 '17 22:05 tcr

Oh so that's what Spans are.

pshc avatar May 12 '17 22:05 pshc

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.

tcr avatar May 13 '17 02:05 tcr

Yeah, doing it all in the parser would be nicest.

pshc avatar May 13 '17 03:05 pshc