rune/ast/
expr_while.rs

1use crate::ast::prelude::*;
2
3#[test]
4#[cfg(not(miri))]
5fn ast_parse() {
6    rt::<ast::ExprWhile>("while x {}");
7    rt::<ast::ExprWhile>("'label: while x {}");
8    rt::<ast::ExprWhile>("#[attr] 'label: while x {}");
9}
10
11/// A `while` loop.
12///
13/// * `while [expr] { ... }`.
14#[derive(Debug, TryClone, PartialEq, Eq, Parse, ToTokens, Spanned)]
15#[rune(parse = "meta_only")]
16#[non_exhaustive]
17pub struct ExprWhile {
18    /// The attributes for the `while` loop
19    #[rune(iter, meta)]
20    pub attributes: Vec<ast::Attribute>,
21    /// A label for the while loop.
22    #[rune(iter, meta)]
23    pub label: Option<(ast::Label, T![:])>,
24    /// The `while` keyword.
25    pub while_token: T![while],
26    /// The name of the binding.
27    pub condition: Box<ast::Condition>,
28    /// The body of the while loop.
29    pub body: Box<ast::Block>,
30}
31
32expr_parse!(While, ExprWhile, "while expression");