@@ -12,7 +12,7 @@ use syn::{
1212 spanned:: Spanned ,
1313 token:: {
1414 At , Brace , Bracket , Colon , Comma , Dot , Else , Eq , FatArrow , For , If , In , Let , Match , Minus ,
15- Paren , Pound , Question , Semi , Slash , While ,
15+ Paren , Pound , Question , Semi , Slash , While , Yield ,
1616 } ,
1717} ;
1818
@@ -810,6 +810,15 @@ impl<E: MaybeElement> DiagnosticParse for ControlFlow<E> {
810810 } ;
811811
812812 ControlFlowKind :: Let ( local)
813+ } else if lookahead. peek ( Yield ) {
814+ #[ cfg( feature = "streaming" ) ]
815+ {
816+ ControlFlowKind :: Yield ( input. diagnostic_parse ( diagnostics) ?)
817+ }
818+ #[ cfg( not( feature = "streaming" ) ) ]
819+ {
820+ return Err ( lookahead. error ( ) ) ;
821+ }
813822 } else {
814823 return Err ( lookahead. error ( ) ) ;
815824 }
@@ -827,6 +836,8 @@ impl<E: ToTokens> ToTokens for ControlFlow<E> {
827836 ControlFlowKind :: For ( for_) => for_. to_tokens ( tokens) ,
828837 ControlFlowKind :: While ( while_) => while_. to_tokens ( tokens) ,
829838 ControlFlowKind :: Match ( match_) => match_. to_tokens ( tokens) ,
839+ #[ cfg( feature = "streaming" ) ]
840+ ControlFlowKind :: Yield ( yield_) => yield_. to_tokens ( tokens) ,
830841 }
831842 }
832843}
@@ -838,6 +849,8 @@ pub enum ControlFlowKind<E> {
838849 For ( ForExpr < E > ) ,
839850 While ( WhileExpr < E > ) ,
840851 Match ( MatchExpr < E > ) ,
852+ #[ cfg( feature = "streaming" ) ]
853+ Yield ( YieldExpr ) ,
841854}
842855
843856#[ derive( Debug , Clone ) ]
@@ -1073,6 +1086,31 @@ impl<E: ToTokens> ToTokens for MatchArm<E> {
10731086 }
10741087}
10751088
1089+ #[ cfg( feature = "streaming" ) ]
1090+ #[ derive( Debug , Clone ) ]
1091+ pub struct YieldExpr {
1092+ pub yield_token : Yield ,
1093+ }
1094+
1095+ #[ cfg( feature = "streaming" ) ]
1096+ impl DiagnosticParse for YieldExpr {
1097+ fn diagnostic_parse (
1098+ input : ParseStream ,
1099+ _diagnostics : & mut Vec < Diagnostic > ,
1100+ ) -> syn:: Result < Self > {
1101+ Ok ( Self {
1102+ yield_token : input. parse ( ) ?,
1103+ } )
1104+ }
1105+ }
1106+
1107+ #[ cfg( feature = "streaming" ) ]
1108+ impl ToTokens for YieldExpr {
1109+ fn to_tokens ( & self , tokens : & mut TokenStream ) {
1110+ self . yield_token . to_tokens ( tokens) ;
1111+ }
1112+ }
1113+
10761114pub trait DiagnosticParse : Sized {
10771115 fn diagnostic_parse ( input : ParseStream , diagnostics : & mut Vec < Diagnostic > )
10781116 -> syn:: Result < Self > ;
0 commit comments