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);
diff --git a/src/fold.rs b/src/fold.rs
index 99b66cb..5794f52 100644
--- a/src/fold.rs
+++ b/src/fold.rs
@@ -892,6 +892,13 @@
})
}
#[cfg(feature = "full")]
+ Yield(e) => {
+ Yield(ExprYield {
+ expr: e.expr.map(|e| e.lift(|e| folder.fold_expr(e))),
+ ..e
+ })
+ }
+ #[cfg(feature = "full")]
Closure(e) => {
Closure(ExprClosure {
decl: e.decl.lift(|v| folder.fold_fn_decl(v)),
diff --git a/src/visit.rs b/src/visit.rs
index 550afb7..f14fbdc 100644
--- a/src/visit.rs
+++ b/src/visit.rs
@@ -591,6 +591,12 @@
visitor.visit_expr(amt);
}
#[cfg(feature = "full")]
+ Yield(ExprYield { ref expr, .. }) => {
+ if let Some(ref expr) = *expr {
+ visitor.visit_expr(expr);
+ }
+ }
+ #[cfg(feature = "full")]
TupField(ExprTupField { ref expr, .. }) |
Unary(ExprUnary { ref expr, .. }) |
Box(ExprBox { ref expr, .. }) |