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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
use smol_str::SmolStr;
use crate::tt::{self, Delimiter};
pub use crate::{
mbe_parser::parse,
mbe_expander::exapnd,
};
#[derive(Debug)]
pub struct MacroRules {
pub(crate) rules: Vec<Rule>,
}
#[derive(Debug)]
pub(crate) struct Rule {
pub(crate) lhs: Subtree,
pub(crate) rhs: Subtree,
}
#[derive(Debug)]
pub(crate) enum TokenTree {
Leaf(Leaf),
Subtree(Subtree),
Repeat(Repeat),
}
impl_froms!(TokenTree: Leaf, Subtree, Repeat);
#[derive(Debug)]
pub(crate) enum Leaf {
Literal(Literal),
Punct(Punct),
Ident(Ident),
Var(Var),
}
impl_froms!(Leaf: Literal, Punct, Ident, Var);
#[derive(Debug)]
pub(crate) struct Subtree {
pub(crate) delimiter: Delimiter,
pub(crate) token_trees: Vec<TokenTree>,
}
#[derive(Debug)]
pub(crate) struct Repeat {
pub(crate) subtree: Subtree,
pub(crate) kind: RepeatKind,
pub(crate) separator: Option<Punct>,
}
#[derive(Debug)]
pub(crate) enum RepeatKind {
ZeroOrMore,
OneOrMore,
ZeroOrOne,
}
#[derive(Debug)]
pub(crate) struct Literal {
pub(crate) text: SmolStr,
}
#[derive(Debug)]
pub(crate) struct Punct {
pub(crate) char: char,
}
#[derive(Debug)]
pub(crate) struct Ident {
pub(crate) text: SmolStr,
}
#[derive(Debug)]
pub(crate) struct Var {
pub(crate) text: SmolStr,
pub(crate) kind: Option<SmolStr>,
}
|