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
47
48
49
50
51
52
53
use crate::ast;
use crate::{Parse, ParseError, Parser, Peek, Peeker, Spanned, ToTokens};
#[derive(Debug, Clone, PartialEq, Eq, Parse, ToTokens, Spanned)]
#[rune(parse = "meta_only")]
pub struct ExprBreak {
#[rune(iter, meta)]
pub attributes: Vec<ast::Attribute>,
pub break_token: T![break],
#[rune(iter)]
pub expr: Option<ExprBreakValue>,
}
expr_parse!(Break, ExprBreak, "break expression");
#[derive(Debug, Clone, PartialEq, Eq, ToTokens, Spanned)]
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),
}
}
}