// Does an entire sequence of additions reduce to a string literal
Does an entire sequence of additions reduce to a string literal
Does an entire sequence of additions reduce to a string literal
fn reduces_to_string<'a>(
        mut op: BinOp,
        mut left: &'a AstExpr,
        mut right: &'a AstExpr,
    ) -> Option<String> {
        let mut results = Vec::new();
        loop {
            if op != BinOp::Add {
                return None;
            }
            // a + b + c  associates as  (a + b) + c
            let x = right.unpack_string_literal()?;
            results.push(x.to_owned());
            match &left.node {
                Expr::Op(left2, op2, right2) => {
                    op = *op2;
                    left = left2;
                    right = right2;
                }
                _ => {
                    let x = left.unpack_string_literal()?;
                    results.push(x.to_owned());
                    break;
                }
            }
        }
        results.reverse();
        Some(results.concat())
    }
fn reduces_to_string < ' a > ( mut op : BinOp , mut left : & ' a AstExpr , mut right : & ' a AstExpr , ) -> Option < String > { let mut results = Vec :: new ( ) ; loop { if op != BinOp :: Add { return None ; } // a + b + c  associates as  (a + b) + c let x = right . unpack_string_literal ( ) ? ; results . push ( x . to_owned ( ) ) ; match & left . node { Expr :: Op ( left2 , op2 , right2 ) => { op = * op2 ; left = left2 ; right = right2 ; } _ => { let x = left . unpack_string_literal ( ) ? ; results . push ( x . to_owned ( ) ) ; break ; } } } results . reverse ( ) ; Some ( results . concat ( ) ) }
Does an entire sequence of additions reduce to a string literal
Does an entire sequence of additions reduce to a string literal
op
BinOp
left
&'a AstExpr
right
&'a AstExpr