Generator literal support

This commit is contained in:
John Kåre Alsaker
2016-12-26 14:34:03 +01:00
parent 6f815ca771
commit d861982ca6
127 changed files with 3238 additions and 259 deletions

View File

@@ -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) {