diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-08-18 23:28:49 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-08-19 10:16:38 -0700 |
| commit | 09e21fe2b93e926b77f105939f6d7f2fb6f7dcc9 (patch) | |
| tree | bce18a31d616bf74aaad117cab8f2c62e37acf44 /src/comp/syntax | |
| parent | 832741641113590e66b61aba3054fa3c5cb456c0 (diff) | |
Pretty-print parens around more things that need disambiguation
Ridiculous stuff like (ret 0) == (log "error")
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/print/pprust.rs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index e9c1dee1f54..21d446c9c5c 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -1377,18 +1377,28 @@ fn operator_prec(op: ast::binop) -> int { } fn need_parens(expr: &@ast::expr, outer_prec: int) -> bool { - let add_them; alt expr.node { ast::expr_binary(op, _, _) { - add_them = operator_prec(op) < outer_prec; + operator_prec(op) < outer_prec } - ast::expr_cast(_, _) { add_them = parse::parser::as_prec < outer_prec; } + ast::expr_cast(_, _) { parse::parser::as_prec < outer_prec } ast::expr_ternary(_, _, _) { - add_them = parse::parser::ternary_prec < outer_prec; - } - _ { add_them = false; } + parse::parser::ternary_prec < outer_prec + } + + // This may be too conservative in some cases + ast::expr_assign(_, _) { true } + ast::expr_move(_, _) { true } + ast::expr_swap(_, _) { true } + ast::expr_assign_op(_, _, _) { true } + ast::expr_ret(_) { true } + ast::expr_put(_) { true } + ast::expr_be(_) { true } + ast::expr_assert(_) { true } + ast::expr_check(_, _) { true } + ast::expr_log(_, _) { true } + _ { false } } - ret add_them; } fn print_maybe_parens(s: &ps, expr: &@ast::expr, outer_prec: int) { |
