Support for `yield`
diff --git a/src/expr.rs b/src/expr.rs
index 6783b7d..db3fb55 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -346,6 +346,14 @@
pub catch_token: tokens::Catch,
pub block: Block,
}),
+
+ /// A yield expression.
+ ///
+ /// E.g. `yield expr`
+ pub Yield(ExprYield #full {
+ pub yield_token: tokens::Yield,
+ pub expr: Option<Box<Expr>>,
+ }),
}
}
@@ -1164,6 +1172,8 @@
|
syn!(ExprCatch) => { ExprKind::Catch }
|
+ syn!(ExprYield) => { ExprKind::Yield }
+ |
call!(expr_closure, allow_struct)
|
cond_reduce!(allow_block, map!(syn!(ExprBlock), ExprKind::Block))
@@ -1208,6 +1218,8 @@
|
syn!(ExprCatch) => { ExprKind::Catch }
|
+ syn!(ExprYield) => { ExprKind::Yield }
+ |
syn!(ExprBlock) => { ExprKind::Block }
), Expr::from));
@@ -1473,6 +1485,18 @@
}
#[cfg(feature = "full")]
+ impl Synom for ExprYield {
+ named!(parse -> Self, do_parse!(
+ yield_: syn!(Yield) >>
+ expr: option!(syn!(Expr)) >>
+ (ExprYield {
+ yield_token: yield_,
+ expr: expr.map(Box::new),
+ })
+ ));
+ }
+
+ #[cfg(feature = "full")]
fn arm_requires_comma(arm: &Arm) -> bool {
if let ExprKind::Block(ExprBlock { unsafety: Unsafety::Normal, .. }) = arm.body.node {
false
@@ -2449,6 +2473,14 @@
}
#[cfg(feature = "full")]
+ impl ToTokens for ExprYield {
+ fn to_tokens(&self, tokens: &mut Tokens) {
+ self.yield_token.to_tokens(tokens);
+ self.expr.to_tokens(tokens);
+ }
+ }
+
+ #[cfg(feature = "full")]
impl ToTokens for ExprClosure {
fn to_tokens(&self, tokens: &mut Tokens) {
self.capture.to_tokens(tokens);