diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2016-12-26 14:34:03 +0100 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2017-07-28 15:46:23 +0200 |
| commit | d861982ca6a1fa5773373362771aa08b9f732de0 (patch) | |
| tree | 06d990dc877d7a629a152185b1c039edb073c4ec /src/libsyntax/parse | |
| parent | 6f815ca771b59fe652a5f88f198810b5dc37a4c9 (diff) | |
| download | rust-d861982ca6a1fa5773373362771aa08b9f732de0.tar.gz rust-d861982ca6a1fa5773373362771aa08b9f732de0.zip | |
Generator literal support
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 1 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d1591a219b3..c377a77d87f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2146,6 +2146,12 @@ impl<'a> Parser<'a> { assert!(self.eat_keyword(keywords::Catch)); return self.parse_catch_expr(lo, attrs); } + if self.is_gen_arg() { + assert!(self.eat_keyword(keywords::Gen)); + assert!(self.eat_keyword(keywords::Arg)); + let hi = self.prev_span; + return Ok(self.mk_expr(lo.to(hi), ExprKind::ImplArg, attrs)); + } if self.eat_keyword(keywords::Return) { if self.token.can_begin_expr() { let e = self.parse_expr()?; @@ -2175,6 +2181,14 @@ impl<'a> Parser<'a> { }; ex = ExprKind::Break(lt, e); hi = self.prev_span; + } else if self.eat_keyword(keywords::Yield) { + if self.token.can_begin_expr() { + let e = self.parse_expr()?; + hi = e.span; + ex = ExprKind::Yield(Some(e)); + } else { + ex = ExprKind::Yield(None); + } } else if self.token.is_keyword(keywords::Let) { // Catch this syntax error here, instead of in `parse_ident`, so // that we can explicitly mention that let is not to be used as an expression @@ -3696,6 +3710,11 @@ impl<'a> Parser<'a> { self.look_ahead(1, |t| t.is_ident() && !t.is_reserved_ident()) } + fn is_gen_arg(&self) -> bool { + self.token.is_keyword(keywords::Gen) && + self.look_ahead(1, |t| t.is_keyword(keywords::Arg)) + } + fn is_defaultness(&self) -> bool { // `pub` is included for better error messages self.token.is_keyword(keywords::Default) && @@ -3799,7 +3818,8 @@ impl<'a> Parser<'a> { // Starts like a simple path, but not a union item. } else if self.token.is_path_start() && !self.token.is_qpath_start() && - !self.is_union_item() { + !self.is_union_item() && + !self.is_gen_arg() { let pth = self.parse_path(PathStyle::Expr)?; if !self.eat(&token::Not) { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 834ac38af98..d39f11bc3ee 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -106,6 +106,7 @@ fn ident_can_begin_expr(ident: ast::Ident) -> bool { keywords::True.name(), keywords::Unsafe.name(), keywords::While.name(), + keywords::Yield.name(), ].contains(&ident.name) } |
