1use crate::ast::prelude::*;
2
3#[test]
4#[cfg(not(miri))]
5fn ast_parse() {
6 rt::<ast::ExprFor>("for i in x {}");
7 rt::<ast::ExprFor>("for (a, _) in x {}");
8 rt::<ast::ExprFor>("'label: for i in x {}");
9 rt::<ast::ExprFor>("#[attr] 'label: for i in x {}");
10}
11
12#[derive(Debug, TryClone, PartialEq, Eq, ToTokens, Spanned)]
16#[non_exhaustive]
17pub struct ExprFor {
18 #[rune(iter)]
20 pub attributes: Vec<ast::Attribute>,
21 #[rune(iter)]
23 pub label: Option<(ast::Label, T![:])>,
24 pub for_token: T![for],
26 pub binding: ast::Pat,
29 pub in_: T![in],
31 pub iter: Box<ast::Expr>,
33 pub body: Box<ast::Block>,
35}
36
37impl ExprFor {
38 pub(crate) fn parse_with_meta(
40 parser: &mut Parser<'_>,
41 attributes: Vec<ast::Attribute>,
42 label: Option<(ast::Label, T![:])>,
43 ) -> Result<Self> {
44 Ok(Self {
45 attributes,
46 label,
47 for_token: parser.parse()?,
48 binding: parser.parse()?,
49 in_: parser.parse()?,
50 iter: Box::try_new(ast::Expr::parse_without_eager_brace(parser)?)?,
51 body: Box::try_new(parser.parse()?)?,
52 })
53 }
54}
55
56expr_parse!(For, ExprFor, "for loop expression");