about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-08-28 16:36:03 +0000
committerbors <bors@rust-lang.org>2017-08-28 16:36:03 +0000
commit9a59d693239915aa37bd08ca194a8ba2857db25a (patch)
treef0852037daee472f22814b2206285fee3733703d /src/libsyntax/parse
parent5caca6fa0213cadca1584db43dd71fb5f82b41b9 (diff)
parenta996d5eec70ba6733e23f2e56e762f58e60bb4ff (diff)
downloadrust-9a59d693239915aa37bd08ca194a8ba2857db25a.tar.gz
rust-9a59d693239915aa37bd08ca194a8ba2857db25a.zip
Auto merge of #43076 - Zoxc:gen, r=arielb1
Generator support

This adds experimental support for generators intended to land once https://github.com/rust-lang/rfcs/pull/2033 is approved.

This is not yet ready to be merged. Things to do:
- [x] Make closure arguments on generators an error
- [x] Spot FIXMEs
- [x] Pass make tidy
- [x] Write tests
- [x] Document the current syntax and semantics for generators somewhere
- [x] Use proper error message numbers
- [x] ~~Make the implicit argument type default to `()`~~
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs8
-rw-r--r--src/libsyntax/parse/token.rs1
2 files changed, 9 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 90a635fdf44..d2bf943ec17 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2222,6 +2222,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
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)
 }