about summary refs log tree commit diff
path: root/src/comp/syntax
diff options
context:
space:
mode:
authorPaul Woolcock <pwoolcoc+github@gmail.com>2012-01-30 11:40:54 -0500
committerMarijn Haverbeke <marijnh@gmail.com>2012-01-30 18:21:19 +0100
commit6ba3d2435556ae4ea72eeb6095e95b5c14a3c1f7 (patch)
tree31aa2e040ad356b1d6c2dc34dadbd4970d39eaea /src/comp/syntax
parenta02493b96919bae8c27a2508a08709dbabdfc744 (diff)
downloadrust-6ba3d2435556ae4ea72eeb6095e95b5c14a3c1f7.tar.gz
rust-6ba3d2435556ae4ea72eeb6095e95b5c14a3c1f7.zip
Remove ternary operator
`expr_ternary`, `ternary_to_if`, and all parses & lexer definitions have
been removed.
Diffstat (limited to 'src/comp/syntax')
-rw-r--r--src/comp/syntax/ast.rs1
-rw-r--r--src/comp/syntax/ast_util.rs17
-rw-r--r--src/comp/syntax/fold.rs4
-rw-r--r--src/comp/syntax/parse/lexer.rs4
-rw-r--r--src/comp/syntax/parse/parser.rs15
-rw-r--r--src/comp/syntax/parse/token.rs2
-rw-r--r--src/comp/syntax/print/pprust.rs18
-rw-r--r--src/comp/syntax/visit.rs5
8 files changed, 5 insertions, 61 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs
index 4ff96c17daa..ee93a3e0e29 100644
--- a/src/comp/syntax/ast.rs
+++ b/src/comp/syntax/ast.rs
@@ -213,7 +213,6 @@ enum expr_ {
     expr_lit(@lit),
     expr_cast(@expr, @ty),
     expr_if(@expr, blk, option::t<@expr>),
-    expr_ternary(@expr, @expr, @expr),
     expr_while(@expr, blk),
     expr_for(@local, @expr, blk),
     expr_do_while(blk, @expr),
diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs
index 32df1e95fdd..68b157cecb8 100644
--- a/src/comp/syntax/ast_util.rs
+++ b/src/comp/syntax/ast_util.rs
@@ -205,23 +205,6 @@ fn default_block(stmts1: [@stmt], expr1: option::t<@expr>, id1: node_id) ->
     {view_items: [], stmts: stmts1, expr: expr1, id: id1, rules: default_blk}
 }
 
-// This is a convenience function to transfor ternary expressions to if
-// expressions so that they can be treated the same
-fn ternary_to_if(e: @expr) -> @expr {
-    alt e.node {
-      expr_ternary(cond, then, els) {
-        let then_blk = block_from_expr(then);
-        let els_blk = block_from_expr(els);
-        let els_expr =
-            @{id: els.id, node: expr_block(els_blk), span: els.span};
-        ret @{id: e.id,
-              node: expr_if(cond, then_blk, option::some(els_expr)),
-              span: e.span};
-      }
-      _ { fail; }
-    }
-}
-
 // FIXME this doesn't handle big integer/float literals correctly (nor does
 // the rest of our literal handling)
 enum const_val {
diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs
index b24f3aae473..a6e10d183c3 100644
--- a/src/comp/syntax/fold.rs
+++ b/src/comp/syntax/fold.rs
@@ -352,10 +352,6 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
             expr_if(fld.fold_expr(cond), fld.fold_block(tr),
                     option::map(fl, fld.fold_expr))
           }
-          expr_ternary(cond, tr, fl) {
-            expr_ternary(fld.fold_expr(cond), fld.fold_expr(tr),
-                         fld.fold_expr(fl))
-          }
           expr_while(cond, body) {
             expr_while(fld.fold_expr(cond), fld.fold_block(body))
           }
diff --git a/src/comp/syntax/parse/lexer.rs b/src/comp/syntax/parse/lexer.rs
index c7c0f32cff9..ae31f1b3434 100644
--- a/src/comp/syntax/parse/lexer.rs
+++ b/src/comp/syntax/parse/lexer.rs
@@ -328,10 +328,6 @@ fn next_token_inner(rdr: reader) -> token::token {
 
 
       // One-byte tokens.
-      '?' {
-        rdr.bump();
-        ret token::QUES;
-      }
       ';' { rdr.bump(); ret token::SEMI; }
       ',' { rdr.bump(); ret token::COMMA; }
       '.' {
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 9678c69b1df..272d65707dd 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -1097,18 +1097,6 @@ fn parse_prefix_expr(p: parser) -> pexpr {
     ret mk_pexpr(p, lo, hi, ex);
 }
 
-fn parse_ternary(p: parser) -> @ast::expr {
-    let cond_expr = parse_binops(p);
-    if p.token == token::QUES {
-        p.bump();
-        let then_expr = parse_expr(p);
-        expect(p, token::COLON);
-        let else_expr = parse_expr(p);
-        ret mk_expr(p, cond_expr.span.lo, else_expr.span.hi,
-                    ast::expr_ternary(cond_expr, then_expr, else_expr));
-    } else { ret cond_expr; }
-}
-
 type op_spec = {tok: token::token, op: ast::binop, prec: int};
 
 
@@ -1143,7 +1131,6 @@ fn parse_binops(p: parser) -> @ast::expr {
 const unop_prec: int = 100;
 
 const as_prec: int = 5;
-const ternary_prec: int = 0;
 
 fn parse_more_binops(p: parser, plhs: pexpr, min_prec: int) ->
    @ast::expr {
@@ -1174,7 +1161,7 @@ fn parse_more_binops(p: parser, plhs: pexpr, min_prec: int) ->
 
 fn parse_assign_expr(p: parser) -> @ast::expr {
     let lo = p.span.lo;
-    let lhs = parse_ternary(p);
+    let lhs = parse_binops(p);
     alt p.token {
       token::EQ {
         p.bump();
diff --git a/src/comp/syntax/parse/token.rs b/src/comp/syntax/parse/token.rs
index 0965697f8c8..3b38f314ecf 100644
--- a/src/comp/syntax/parse/token.rs
+++ b/src/comp/syntax/parse/token.rs
@@ -43,7 +43,6 @@ enum token {
     SEMI,
     COLON,
     MOD_SEP,
-    QUES,
     RARROW,
     LARROW,
     DARROW,
@@ -114,7 +113,6 @@ fn to_str(r: reader, t: token) -> str {
       SEMI { ret ";"; }
       COLON { ret ":"; }
       MOD_SEP { ret "::"; }
-      QUES { ret "?"; }
       RARROW { ret "->"; }
       LARROW { ret "<-"; }
       DARROW { ret "<->"; }
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index 5b62cef2d3b..94095b6ab40 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -855,15 +855,6 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
       ast::expr_if_check(test, blk, elseopt) {
         print_if(s, test, blk, elseopt, true);
       }
-      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);
-      }
       ast::expr_while(test, blk) {
         head(s, "while");
         print_maybe_parens_discrim(s, test);
@@ -1044,8 +1035,8 @@ fn print_expr_parens_if_not_bot(s: ps, ex: @ast::expr) {
     let parens = alt ex.node {
       ast::expr_fail(_) | ast::expr_ret(_) |
       ast::expr_binary(_, _, _) | ast::expr_unary(_, _) |
-      ast::expr_ternary(_, _, _) | ast::expr_move(_, _) |
-      ast::expr_copy(_) | ast::expr_assign(_, _) | ast::expr_be(_) |
+      ast::expr_move(_, _) | ast::expr_copy(_) |
+      ast::expr_assign(_, _) | ast::expr_be(_) |
       ast::expr_assign_op(_, _, _) | ast::expr_swap(_, _) |
       ast::expr_log(_, _, _) | ast::expr_assert(_) |
       ast::expr_call(_, _, true) |
@@ -1395,7 +1386,6 @@ fn need_parens(expr: @ast::expr, outer_prec: int) -> bool {
     alt expr.node {
       ast::expr_binary(op, _, _) { operator_prec(op) < outer_prec }
       ast::expr_cast(_, _) { parse::parser::as_prec < outer_prec }
-      ast::expr_ternary(_, _, _) { parse::parser::ternary_prec < outer_prec }
       // This may be too conservative in some cases
       ast::expr_assign(_, _) { true }
       ast::expr_move(_, _) { true }
@@ -1757,8 +1747,8 @@ fn ends_in_lit_int(ex: @ast::expr) -> bool {
     alt ex.node {
       ast::expr_lit(@{node: ast::lit_int(_, ast::ty_i), _}) { true }
       ast::expr_binary(_, _, sub) | ast::expr_unary(_, sub) |
-      ast::expr_ternary(_, _, sub) | ast::expr_move(_, sub) |
-      ast::expr_copy(sub) | ast::expr_assign(_, sub) | ast::expr_be(sub) |
+      ast::expr_move(_, sub) | ast::expr_copy(sub) |
+      ast::expr_assign(_, sub) | ast::expr_be(sub) |
       ast::expr_assign_op(_, _, sub) | ast::expr_swap(_, sub) |
       ast::expr_log(_, _, sub) | ast::expr_assert(sub) |
       ast::expr_check(_, sub) { ends_in_lit_int(sub) }
diff --git a/src/comp/syntax/visit.rs b/src/comp/syntax/visit.rs
index ba995192859..1fb6991256e 100644
--- a/src/comp/syntax/visit.rs
+++ b/src/comp/syntax/visit.rs
@@ -312,11 +312,6 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
         v.visit_block(b, e, v);
         visit_expr_opt(eo, e, v);
       }
-      expr_ternary(c, t, el) {
-        v.visit_expr(c, e, v);
-        v.visit_expr(t, e, v);
-        v.visit_expr(el, e, v);
-      }
       expr_while(x, b) { v.visit_expr(x, e, v); v.visit_block(b, e, v); }
       expr_for(dcl, x, b) {
         v.visit_local(dcl, e, v);