aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_macros/src/mbe_expander.rs44
1 files changed, 42 insertions, 2 deletions
diff --git a/crates/ra_macros/src/mbe_expander.rs b/crates/ra_macros/src/mbe_expander.rs
index 545bd2002..f55c337da 100644
--- a/crates/ra_macros/src/mbe_expander.rs
+++ b/crates/ra_macros/src/mbe_expander.rs
@@ -14,11 +14,51 @@ fn expand_rule(rule: &mbe::Rule, input: &tt::Subtree) -> Option<tt::Subtree> {
14 14
15#[derive(Debug, Default)] 15#[derive(Debug, Default)]
16struct Bindings { 16struct Bindings {
17 inner: FxHashMap<SmolStr, tt::TokenTree>, 17 inner: FxHashMap<SmolStr, Binding>,
18} 18}
19 19
20#[derive(Debug)]
21enum Binding {
22 Simple(tt::TokenTree),
23 Nested(Vec<Binding>),
24}
25
26/*
27
28macro_rules! impl_froms {
29 ($e:ident: $($v:ident),*) => {
30 $(
31 impl From<$v> for $e {
32 fn from(it: $v) -> $e {
33 $e::$v(it)
34 }
35 }
36 )*
37 }
38}
39
40impl_froms! (Foo: Bar, Baz)
41
42*/
43
20fn match_lhs(pattern: &mbe::Subtree, input: &tt::Subtree) -> Option<Bindings> { 44fn match_lhs(pattern: &mbe::Subtree, input: &tt::Subtree) -> Option<Bindings> {
21 Some(Bindings::default()) 45 let mut res = Bindings::default();
46 for pat in pattern.token_trees.iter() {
47 match pat {
48 mbe::TokenTree::Leaf(leaf) => match leaf {
49 mbe::Leaf::Var(mbe::Var { text, kind }) => {
50 let kind = kind.clone()?;
51 match kind.as_str() {
52 "ident" => (),
53 _ => return None,
54 }
55 }
56 _ => return None,
57 },
58 _ => {}
59 }
60 }
61 Some(res)
22} 62}
23 63
24fn expand_rhs(template: &mbe::Subtree, bindings: &Bindings) -> Option<tt::Subtree> { 64fn expand_rhs(template: &mbe::Subtree, bindings: &Bindings) -> Option<tt::Subtree> {