From 321fd80219e024cabb7ee539e701bc6b4a258751 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Fri, 9 Mar 2012 16:11:56 -0800 Subject: Add an infinite loop construct Add a loop {} construct for infinite loops, and use it in test cases. See #1906 for details. --- src/rustc/syntax/parse/parser.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/rustc/syntax/parse') 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 { 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 } -- cgit 1.4.1-3-g733a5