use crate::ast::prelude::*;
#[test]
#[cfg(not(miri))]
fn ast_parse() {
rt::<ast::ExprRange>("0..42");
rt::<ast::ExprRange>("0..=42");
rt::<ast::ExprRange>("0..=a + 2");
}
#[derive(Debug, TryClone, PartialEq, Eq, ToTokens, Spanned)]
#[non_exhaustive]
pub struct ExprRange {
#[rune(iter)]
pub attributes: Vec<ast::Attribute>,
#[rune(iter)]
pub start: Option<Box<ast::Expr>>,
pub limits: ExprRangeLimits,
#[rune(iter)]
pub end: Option<Box<ast::Expr>>,
}
#[derive(Debug, TryClone, PartialEq, Eq, ToTokens, Spanned)]
#[non_exhaustive]
pub enum ExprRangeLimits {
HalfOpen(T![..]),
Closed(T![..=]),
}
impl Parse for ExprRangeLimits {
fn parse(p: &mut Parser<'_>) -> Result<Self> {
Ok(match p.nth(0)? {
K![..] => Self::HalfOpen(p.parse()?),
K![..=] => Self::Closed(p.parse()?),
_ => return Err(compile::Error::expected(p.tok_at(0)?, "range limits")),
})
}
}
expr_parse!(Range, ExprRange, "range expression");