@@ -346,6 +346,14 @@ ast_enum_of_structs! {
346346 pub catch_token: tokens:: Catch ,
347347 pub block: Block ,
348348 } ) ,
349+
350+ /// A yield expression.
351+ ///
352+ /// E.g. `yield expr`
353+ pub Yield ( ExprYield #full {
354+ pub yield_token: tokens:: Yield ,
355+ pub expr: Option <Box <Expr >>,
356+ } ) ,
349357 }
350358}
351359
@@ -1164,6 +1172,8 @@ pub mod parsing {
11641172 |
11651173 syn!( ExprCatch ) => { ExprKind :: Catch }
11661174 |
1175+ syn!( ExprYield ) => { ExprKind :: Yield }
1176+ |
11671177 call!( expr_closure, allow_struct)
11681178 |
11691179 cond_reduce!( allow_block, map!( syn!( ExprBlock ) , ExprKind :: Block ) )
@@ -1208,6 +1218,8 @@ pub mod parsing {
12081218 |
12091219 syn!( ExprCatch ) => { ExprKind :: Catch }
12101220 |
1221+ syn!( ExprYield ) => { ExprKind :: Yield }
1222+ |
12111223 syn!( ExprBlock ) => { ExprKind :: Block }
12121224 ) , Expr :: from) ) ;
12131225
@@ -1472,6 +1484,18 @@ pub mod parsing {
14721484 ) ) ;
14731485 }
14741486
1487+ #[ cfg( feature = "full" ) ]
1488+ impl Synom for ExprYield {
1489+ named ! ( parse -> Self , do_parse!(
1490+ yield_: syn!( Yield ) >>
1491+ expr: option!( syn!( Expr ) ) >>
1492+ ( ExprYield {
1493+ yield_token: yield_,
1494+ expr: expr. map( Box :: new) ,
1495+ } )
1496+ ) ) ;
1497+ }
1498+
14751499 #[ cfg( feature = "full" ) ]
14761500 fn arm_requires_comma ( arm : & Arm ) -> bool {
14771501 if let ExprKind :: Block ( ExprBlock { unsafety : Unsafety :: Normal , .. } ) = arm. body . node {
@@ -2448,6 +2472,14 @@ mod printing {
24482472 }
24492473 }
24502474
2475+ #[ cfg( feature = "full" ) ]
2476+ impl ToTokens for ExprYield {
2477+ fn to_tokens ( & self , tokens : & mut Tokens ) {
2478+ self . yield_token . to_tokens ( tokens) ;
2479+ self . expr . to_tokens ( tokens) ;
2480+ }
2481+ }
2482+
24512483 #[ cfg( feature = "full" ) ]
24522484 impl ToTokens for ExprClosure {
24532485 fn to_tokens ( & self , tokens : & mut Tokens ) {
0 commit comments