rustc: Pretty-print ternary operator
This commit is contained in:
parent
b9fc4dfc54
commit
3aa8d7ff45
@ -1119,6 +1119,7 @@ fn parse_binops(&parser p) -> @ast::expr {
|
||||
const int unop_prec = 100;
|
||||
|
||||
const int as_prec = 5;
|
||||
const int ternary_prec = 0;
|
||||
|
||||
fn parse_more_binops(&parser p, @ast::expr lhs, int min_prec) -> @ast::expr {
|
||||
auto peeked = p.peek();
|
||||
@ -1552,6 +1553,7 @@ fn stmt_ends_with_semi(&ast::stmt stmt) -> bool {
|
||||
case (ast::expr_lit(_)) { true }
|
||||
case (ast::expr_cast(_, _)) { true }
|
||||
case (ast::expr_if(_, _, _)) { false }
|
||||
case (ast::expr_ternary(_, _, _)) { true }
|
||||
case (ast::expr_for(_, _, _)) { false }
|
||||
case (ast::expr_for_each(_, _, _)) { false }
|
||||
case (ast::expr_while(_, _)) { false }
|
||||
|
@ -673,6 +673,15 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
||||
case (ast::expr_if_check(?test, ?block, ?elseopt)) {
|
||||
print_if(s, test, block, elseopt, true);
|
||||
}
|
||||
case (ast::expr_ternary(?test, ?then, ?els)) {
|
||||
print_expr(s, test);
|
||||
space(s.s);
|
||||
word_space(s, "?");
|
||||
print_expr(s, then);
|
||||
space(s.s);
|
||||
word_space(s, ":");
|
||||
print_expr(s, els);
|
||||
}
|
||||
case (ast::expr_while(?test, ?block)) {
|
||||
head(s, "while");
|
||||
popen(s);
|
||||
@ -1113,6 +1122,9 @@ fn print_maybe_parens(&ps s, &@ast::expr expr, int outer_prec) {
|
||||
case (ast::expr_cast(_, _)) {
|
||||
add_them = front::parser::as_prec < outer_prec;
|
||||
}
|
||||
case (ast::expr_ternary(_, _, _)) {
|
||||
add_them = front::parser::ternary_prec < outer_prec;
|
||||
}
|
||||
case (_) { add_them = false; }
|
||||
}
|
||||
if (add_them) { popen(s); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user