1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::ast;
use crate::{Parse, Spanned, ToTokens};
#[derive(Debug, Clone, PartialEq, Eq, ToTokens, Spanned)]
pub struct ExprRange {
#[rune(iter)]
pub attributes: Vec<ast::Attribute>,
#[rune(iter)]
pub from: Option<ast::Expr>,
pub limits: ExprRangeLimits,
#[rune(iter)]
pub to: Option<ast::Expr>,
}
#[derive(Debug, Clone, PartialEq, Eq, ToTokens, Spanned)]
pub enum ExprRangeLimits {
HalfOpen(T![..]),
Closed(T![..=]),
}
impl Parse for ExprRangeLimits {
fn parse(p: &mut crate::Parser) -> Result<Self, crate::ParseError> {
Ok(match p.nth(0)? {
K![..] => Self::HalfOpen(p.parse()?),
K![..=] => Self::Closed(p.parse()?),
_ => return Err(crate::ParseError::expected(&p.tok_at(0)?, "range limits")),
})
}
}
expr_parse!(Range, ExprRange, "range expression");