rune/ast/
condition.rs

1use crate::ast::prelude::*;
2
3#[test]
4#[cfg(not(miri))]
5fn ast_parse() {
6    rt::<ast::Condition>("true");
7    rt::<ast::Condition>("let [a, ..] = v");
8}
9
10/// The condition in an if statement.
11///
12/// * `true`.
13/// * `let Some(<pat>) = <expr>`.
14#[derive(Debug, TryClone, PartialEq, Eq, ToTokens, Spanned)]
15#[non_exhaustive]
16pub enum Condition {
17    /// A regular expression.
18    Expr(ast::Expr),
19    /// A pattern match.
20    ExprLet(ast::ExprLet),
21}
22
23impl Parse for Condition {
24    fn parse(p: &mut Parser<'_>) -> Result<Self> {
25        Ok(match p.nth(0)? {
26            K![let] => Self::ExprLet(ast::ExprLet::parse_without_eager_brace(p)?),
27            _ => Self::Expr(ast::Expr::parse_without_eager_brace(p)?),
28        })
29    }
30}