rune/ast/
expr_yield.rs

1use crate::ast::prelude::*;
2
3#[test]
4#[cfg(not(miri))]
5fn ast_parse() {
6    rt::<ast::ExprYield>("yield");
7    rt::<ast::ExprYield>("yield 42");
8    rt::<ast::ExprYield>("#[attr] yield 42");
9}
10
11/// A `yield` expression to return a value from a generator.
12///
13/// * `yield [expr]`.
14#[derive(Debug, TryClone, PartialEq, Eq, Parse, ToTokens, Spanned)]
15#[rune(parse = "meta_only")]
16#[non_exhaustive]
17pub struct ExprYield {
18    /// The attributes of the `yield`
19    #[rune(iter, meta)]
20    pub attributes: Vec<ast::Attribute>,
21    /// The return token.
22    pub yield_token: T![yield],
23    /// An optional expression to yield.
24    #[rune(iter)]
25    pub expr: Option<Box<ast::Expr>>,
26}
27
28expr_parse!(Yield, ExprYield, "yield expression");