use crate::ast::prelude::*;
#[derive(Debug, Clone, PartialEq, Eq, Parse, ToTokens, Spanned)]
#[rune(parse = "meta_only")]
#[non_exhaustive]
pub struct ExprBreak {
#[rune(iter, meta)]
pub attributes: Vec<ast::Attribute>,
pub break_token: T![break],
#[rune(iter)]
pub expr: Option<Box<ExprBreakValue>>,
}
expr_parse!(Break, ExprBreak, "break expression");
#[derive(Debug, Clone, PartialEq, Eq, ToTokens, Spanned)]
#[non_exhaustive]
#[allow(clippy::large_enum_variant)]
pub enum ExprBreakValue {
Expr(ast::Expr),
Label(ast::Label),
}
impl Parse for ExprBreakValue {
fn parse(p: &mut Parser<'_>) -> Result<Self, ParseError> {
Ok(match p.nth(0)? {
K!['label] => Self::Label(p.parse()?),
_ => Self::Expr(p.parse()?),
})
}
}
impl Peek for ExprBreakValue {
fn peek(p: &mut Peeker<'_>) -> bool {
match p.nth(0) {
K!['label] => true,
_ => ast::Expr::peek(p),
}
}
}