diff options
| author | John Gallagher <jgallagher@bignerdranch.com> | 2014-10-02 22:45:46 -0400 |
|---|---|---|
| committer | John Gallagher <jgallagher@bignerdranch.com> | 2014-10-10 20:30:31 -0400 |
| commit | 0c2c8116a307e88f8327e0ea846d2c9c135193b7 (patch) | |
| tree | b9f17f6dc86f3e98b77b0eaf18a7d5ecb05bd7a4 /src/libsyntax/parse | |
| parent | 78a7676898d9f80ab540c6df5d4c9ce35bb50463 (diff) | |
| download | rust-0c2c8116a307e88f8327e0ea846d2c9c135193b7.tar.gz rust-0c2c8116a307e88f8327e0ea846d2c9c135193b7.zip | |
Teach libsyntax about `while let`
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/classify.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 18 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index cb57318445e..d46d078c776 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::ExprMatch(..) | ast::ExprBlock(_) | ast::ExprWhile(..) + | ast::ExprWhileLet(..) | ast::ExprLoop(..) | ast::ExprForLoop(..) => false, _ => true diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e7f40cf0722..5f304fb0aeb 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -26,7 +26,7 @@ use ast::{ExprField, ExprTupField, ExprFnBlock, ExprIf, ExprIfLet, ExprIndex, Ex use ast::{ExprLit, ExprLoop, ExprMac}; use ast::{ExprMethodCall, ExprParen, ExprPath, ExprProc}; use ast::{ExprRepeat, ExprRet, ExprStruct, ExprTup, ExprUnary, ExprUnboxedFn}; -use ast::{ExprVec, ExprWhile, ExprForLoop, Field, FnDecl}; +use ast::{ExprVec, ExprWhile, ExprWhileLet, ExprForLoop, Field, FnDecl}; use ast::{Once, Many}; use ast::{FnUnboxedClosureKind, FnMutUnboxedClosureKind}; use ast::{FnOnceUnboxedClosureKind}; @@ -2935,7 +2935,11 @@ impl<'a> Parser<'a> { self.mk_expr(lo, hi, ExprForLoop(pat, expr, loop_block, opt_ident)) } + /// Parse a 'while' or 'while let' expression ('while' token already eaten) pub fn parse_while_expr(&mut self, opt_ident: Option<ast::Ident>) -> P<Expr> { + if self.is_keyword(keywords::Let) { + return self.parse_while_let_expr(opt_ident); + } let lo = self.last_span.lo; let cond = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL); let body = self.parse_block(); @@ -2943,6 +2947,18 @@ impl<'a> Parser<'a> { return self.mk_expr(lo, hi, ExprWhile(cond, body, opt_ident)); } + /// Parse a 'while let' expression ('while' token already eaten) + pub fn parse_while_let_expr(&mut self, opt_ident: Option<ast::Ident>) -> P<Expr> { + let lo = self.last_span.lo; + self.expect_keyword(keywords::Let); + let pat = self.parse_pat(); + self.expect(&token::EQ); + let expr = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL); + let body = self.parse_block(); + let hi = body.span.hi; + return self.mk_expr(lo, hi, ExprWhileLet(pat, expr, body, opt_ident)); + } + pub fn parse_loop_expr(&mut self, opt_ident: Option<ast::Ident>) -> P<Expr> { let lo = self.last_span.lo; let body = self.parse_block(); |
