about summary refs log tree commit diff
path: root/src/rustc/syntax/parse
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-03-09 16:11:56 -0800
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-03-09 16:40:58 -0800
commit321fd80219e024cabb7ee539e701bc6b4a258751 (patch)
treea0dc81403ffd175f75c704e1a26765339b63907a /src/rustc/syntax/parse
parent4ffcb959744194413ca20223274d2c351ad7686c (diff)
downloadrust-321fd80219e024cabb7ee539e701bc6b4a258751.tar.gz
rust-321fd80219e024cabb7ee539e701bc6b4a258751.zip
Add an infinite loop construct
Add a loop {} construct for infinite loops, and use it in test
cases. See #1906 for details.
Diffstat (limited to 'src/rustc/syntax/parse')
-rw-r--r--src/rustc/syntax/parse/parser.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/rustc/syntax/parse/parser.rs b/src/rustc/syntax/parse/parser.rs
index 95c7383cb66..53f75d8f7c3 100644
--- a/src/rustc/syntax/parse/parser.rs
+++ b/src/rustc/syntax/parse/parser.rs
@@ -146,11 +146,11 @@ fn new_parser(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader,
 fn bad_expr_word_table() -> hashmap<str, ()> {
     let words = new_str_hash();
     for word in ["alt", "assert", "be", "break", "check", "claim",
-                 "class", "const", "cont", "copy", "do", "else", "enum",
-                 "export", "fail", "fn", "for", "if",  "iface", "impl",
-                 "import", "let", "log", "mod", "mutable", "native", "pure",
-                 "resource", "ret", "trait", "type", "unchecked", "unsafe",
-                 "while", "crust", "mut"] {
+                 "class", "const", "cont", "copy", "crust", "do", "else",
+                 "enum", "export", "fail", "fn", "for", "if",  "iface",
+                 "impl", "import", "let", "log", "loop", "mod", "mut",
+                 "mutable", "native", "pure", "resource", "ret", "trait",
+                 "type", "unchecked", "unsafe", "while"] {
         words.insert(word, ());
     }
     words
@@ -839,6 +839,8 @@ fn parse_bottom_expr(p: parser) -> pexpr {
         ret pexpr(parse_while_expr(p));
     } else if eat_word(p, "do") {
         ret pexpr(parse_do_while_expr(p));
+    } else if eat_word(p, "loop") {
+        ret pexpr(parse_loop_expr(p));
     } else if eat_word(p, "alt") {
         ret pexpr(parse_alt_expr(p));
     } else if eat_word(p, "fn") {
@@ -1399,6 +1401,13 @@ fn parse_do_while_expr(p: parser) -> @ast::expr {
     ret mk_expr(p, lo, hi, ast::expr_do_while(body, cond));
 }
 
+fn parse_loop_expr(p: parser) -> @ast::expr {
+    let lo = p.last_span.lo;
+    let body = parse_block_no_value(p);
+    let hi = body.span.hi;
+    ret mk_expr(p, lo, hi, ast::expr_loop(body));
+}
+
 fn parse_alt_expr(p: parser) -> @ast::expr {
     let lo = p.last_span.lo;
     let mode = if eat_word(p, "check") { ast::alt_check }
@@ -1691,7 +1700,7 @@ fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool {
       ast::expr_if(_, _, _) | ast::expr_if_check(_, _, _)
       | ast::expr_alt(_, _, _) | ast::expr_block(_)
       | ast::expr_do_while(_, _) | ast::expr_while(_, _)
-      | ast::expr_for(_, _, _)
+      | ast::expr_loop(_) | ast::expr_for(_, _, _)
       | ast::expr_call(_, _, true) {
         false
       }