diff options
author | Aleksey Kladov <[email protected]> | 2019-01-31 18:09:43 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-31 20:23:30 +0000 |
commit | 40feacdeb90786b49ea9e0510ba22ff7af79e020 (patch) | |
tree | 294162ffb99480a5f150b9718675a954a4ac0f0a /crates/ra_mbe/src/lib.rs | |
parent | ad80a0c551458de7d27a98d182d7f559de04f291 (diff) |
split macros across crates
Diffstat (limited to 'crates/ra_mbe/src/lib.rs')
-rw-r--r-- | crates/ra_mbe/src/lib.rs | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs new file mode 100644 index 000000000..38bf3431a --- /dev/null +++ b/crates/ra_mbe/src/lib.rs | |||
@@ -0,0 +1,88 @@ | |||
1 | macro_rules! impl_froms { | ||
2 | ($e:ident: $($v:ident), *) => { | ||
3 | $( | ||
4 | impl From<$v> for $e { | ||
5 | fn from(it: $v) -> $e { | ||
6 | $e::$v(it) | ||
7 | } | ||
8 | } | ||
9 | )* | ||
10 | } | ||
11 | } | ||
12 | |||
13 | mod tt_cursor; | ||
14 | mod mbe_parser; | ||
15 | mod mbe_expander; | ||
16 | |||
17 | use smol_str::SmolStr; | ||
18 | |||
19 | pub use tt::{Delimiter, Punct}; | ||
20 | |||
21 | pub use crate::{ | ||
22 | mbe_parser::parse, | ||
23 | mbe_expander::exapnd, | ||
24 | }; | ||
25 | |||
26 | #[derive(Debug)] | ||
27 | pub struct MacroRules { | ||
28 | pub(crate) rules: Vec<Rule>, | ||
29 | } | ||
30 | |||
31 | #[derive(Debug)] | ||
32 | pub(crate) struct Rule { | ||
33 | pub(crate) lhs: Subtree, | ||
34 | pub(crate) rhs: Subtree, | ||
35 | } | ||
36 | |||
37 | #[derive(Debug)] | ||
38 | pub(crate) enum TokenTree { | ||
39 | Leaf(Leaf), | ||
40 | Subtree(Subtree), | ||
41 | Repeat(Repeat), | ||
42 | } | ||
43 | impl_froms!(TokenTree: Leaf, Subtree, Repeat); | ||
44 | |||
45 | #[derive(Debug)] | ||
46 | pub(crate) enum Leaf { | ||
47 | Literal(Literal), | ||
48 | Punct(Punct), | ||
49 | Ident(Ident), | ||
50 | Var(Var), | ||
51 | } | ||
52 | impl_froms!(Leaf: Literal, Punct, Ident, Var); | ||
53 | |||
54 | #[derive(Debug)] | ||
55 | pub(crate) struct Subtree { | ||
56 | pub(crate) delimiter: Delimiter, | ||
57 | pub(crate) token_trees: Vec<TokenTree>, | ||
58 | } | ||
59 | |||
60 | #[derive(Debug)] | ||
61 | pub(crate) struct Repeat { | ||
62 | pub(crate) subtree: Subtree, | ||
63 | pub(crate) kind: RepeatKind, | ||
64 | pub(crate) separator: Option<char>, | ||
65 | } | ||
66 | |||
67 | #[derive(Debug)] | ||
68 | pub(crate) enum RepeatKind { | ||
69 | ZeroOrMore, | ||
70 | OneOrMore, | ||
71 | ZeroOrOne, | ||
72 | } | ||
73 | |||
74 | #[derive(Debug)] | ||
75 | pub(crate) struct Literal { | ||
76 | pub(crate) text: SmolStr, | ||
77 | } | ||
78 | |||
79 | #[derive(Debug)] | ||
80 | pub(crate) struct Ident { | ||
81 | pub(crate) text: SmolStr, | ||
82 | } | ||
83 | |||
84 | #[derive(Debug)] | ||
85 | pub(crate) struct Var { | ||
86 | pub(crate) text: SmolStr, | ||
87 | pub(crate) kind: Option<SmolStr>, | ||
88 | } | ||