Skip to content

Commit fae2cb5

Browse files
committed
---
yaml --- r: 3327 b: refs/heads/master c: 3aa8d7f h: refs/heads/master i: 3325: 2a663bf 3323: bc2ba5e 3319: fd9c989 3311: bc6e8d2 3295: 9157c73 3263: 4275550 3199: 01f0cbf 3071: fa4a634 v: v3
1 parent b8daf8b commit fae2cb5

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: b9fc4dfc549ba6268a30209cd75f8a043e2f61fc
2+
refs/heads/master: 3aa8d7ff4579137b483640969019463cce36f54b

trunk/src/comp/front/parser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@ fn parse_binops(&parser p) -> @ast::expr {
11191119
const int unop_prec = 100;
11201120

11211121
const int as_prec = 5;
1122+
const int ternary_prec = 0;
11221123

11231124
fn parse_more_binops(&parser p, @ast::expr lhs, int min_prec) -> @ast::expr {
11241125
auto peeked = p.peek();
@@ -1552,6 +1553,7 @@ fn stmt_ends_with_semi(&ast::stmt stmt) -> bool {
15521553
case (ast::expr_lit(_)) { true }
15531554
case (ast::expr_cast(_, _)) { true }
15541555
case (ast::expr_if(_, _, _)) { false }
1556+
case (ast::expr_ternary(_, _, _)) { true }
15551557
case (ast::expr_for(_, _, _)) { false }
15561558
case (ast::expr_for_each(_, _, _)) { false }
15571559
case (ast::expr_while(_, _)) { false }

trunk/src/comp/pretty/pprust.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,15 @@ fn print_expr(&ps s, &@ast::expr expr) {
673673
case (ast::expr_if_check(?test, ?block, ?elseopt)) {
674674
print_if(s, test, block, elseopt, true);
675675
}
676+
case (ast::expr_ternary(?test, ?then, ?els)) {
677+
print_expr(s, test);
678+
space(s.s);
679+
word_space(s, "?");
680+
print_expr(s, then);
681+
space(s.s);
682+
word_space(s, ":");
683+
print_expr(s, els);
684+
}
676685
case (ast::expr_while(?test, ?block)) {
677686
head(s, "while");
678687
popen(s);
@@ -1113,6 +1122,9 @@ fn print_maybe_parens(&ps s, &@ast::expr expr, int outer_prec) {
11131122
case (ast::expr_cast(_, _)) {
11141123
add_them = front::parser::as_prec < outer_prec;
11151124
}
1125+
case (ast::expr_ternary(_, _, _)) {
1126+
add_them = front::parser::ternary_prec < outer_prec;
1127+
}
11161128
case (_) { add_them = false; }
11171129
}
11181130
if (add_them) { popen(s); }

0 commit comments

Comments
 (0)