diff options
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/classify.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 19 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 6 |
3 files changed, 25 insertions, 1 deletions
diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index c7c556c9728..0bf87f10597 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -28,6 +28,7 @@ pub fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool { | ast::expr_block(_) | ast::expr_while(*) | ast::expr_loop(*) + | ast::expr_for_loop(*) | ast::expr_call(_, _, ast::DoSugar) | ast::expr_call(_, _, ast::ForSugar) | ast::expr_method_call(_, _, _, _, _, ast::DoSugar) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 61dc6f47549..6ff4b91ec97 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -29,7 +29,7 @@ use ast::{expr_method_call, expr_paren, expr_path, expr_repeat}; use ast::{expr_ret, expr_self, expr_struct, expr_tup, expr_unary}; use ast::{expr_vec, expr_vstore, expr_vstore_mut_box}; use ast::{expr_vstore_slice, expr_vstore_box}; -use ast::{expr_vstore_mut_slice, expr_while, extern_fn, Field, fn_decl}; +use ast::{expr_vstore_mut_slice, expr_while, expr_for_loop, extern_fn, Field, fn_decl}; use ast::{expr_vstore_uniq, Onceness, Once, Many}; use ast::{foreign_item, foreign_item_static, foreign_item_fn, foreign_mod}; use ast::{ident, impure_fn, inherited, item, item_, item_static}; @@ -1622,6 +1622,8 @@ impl Parser { hi = self.span.hi; } else if self.eat_keyword(keywords::If) { return self.parse_if_expr(); + } else if self.eat_keyword(keywords::ForEach) { + return self.parse_for_expr(); } else if self.eat_keyword(keywords::For) { return self.parse_sugary_call_expr(lo, ~"for", ForSugar, expr_loop_body); @@ -2323,6 +2325,21 @@ impl Parser { } } + // parse a 'foreach' .. 'in' expression ('foreach' token already eaten) + pub fn parse_for_expr(&self) -> @expr { + // Parse: `foreach <src_pat> in <src_expr> <src_loop_block>` + + let lo = self.last_span.lo; + let pat = self.parse_pat(); + self.expect_keyword(keywords::In); + let expr = self.parse_expr(); + let loop_block = self.parse_block(); + let hi = self.span.hi; + + self.mk_expr(lo, hi, expr_for_loop(pat, expr, loop_block)) + } + + // parse a 'for' or 'do'. // the 'for' and 'do' expressions parse as calls, but look like // function calls followed by a closure expression. diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 52b6d4459bf..a9f0db32d3e 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -474,6 +474,8 @@ fn mk_fresh_ident_interner() -> @ident_interner { "while", // 64 "be", // 65 + "in", // 66 + "foreach", // 67 ]; @ident_interner { @@ -570,8 +572,10 @@ pub mod keywords { False, Fn, For, + ForEach, If, Impl, + In, Let, __Log, Loop, @@ -612,8 +616,10 @@ pub mod keywords { False => ident { name: 40, ctxt: 0 }, Fn => ident { name: 41, ctxt: 0 }, For => ident { name: 42, ctxt: 0 }, + ForEach => ident { name: 67, ctxt: 0 }, If => ident { name: 43, ctxt: 0 }, Impl => ident { name: 44, ctxt: 0 }, + In => ident { name: 66, ctxt: 0 }, Let => ident { name: 45, ctxt: 0 }, __Log => ident { name: 46, ctxt: 0 }, Loop => ident { name: 47, ctxt: 0 }, |
