diff options
author | Aleksey Kladov <[email protected]> | 2019-01-31 18:43:54 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-31 20:23:30 +0000 |
commit | a16f6bb27df1a9a9fcb506081bb30ccbf966e5c2 (patch) | |
tree | 7ec1a33ec57806979951fa5cefc3cc9a05b28987 /crates/ra_mbe/src/mbe_expander.rs | |
parent | 2d1f0b105d7995088fdf7a90e5e594b5555699c6 (diff) |
cleanup
Diffstat (limited to 'crates/ra_mbe/src/mbe_expander.rs')
-rw-r--r-- | crates/ra_mbe/src/mbe_expander.rs | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 21c1552ce..19c75404d 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs | |||
@@ -1,13 +1,13 @@ | |||
1 | use rustc_hash::FxHashMap; | 1 | use rustc_hash::FxHashMap; |
2 | use ra_syntax::SmolStr; | 2 | use ra_syntax::SmolStr; |
3 | 3 | ||
4 | use crate::{self as mbe, tt_cursor::TtCursor}; | 4 | use crate::tt_cursor::TtCursor; |
5 | 5 | ||
6 | pub fn exapnd(rules: &mbe::MacroRules, input: &tt::Subtree) -> Option<tt::Subtree> { | 6 | pub fn exapnd(rules: &crate::MacroRules, input: &tt::Subtree) -> Option<tt::Subtree> { |
7 | rules.rules.iter().find_map(|it| expand_rule(it, input)) | 7 | rules.rules.iter().find_map(|it| expand_rule(it, input)) |
8 | } | 8 | } |
9 | 9 | ||
10 | fn expand_rule(rule: &mbe::Rule, input: &tt::Subtree) -> Option<tt::Subtree> { | 10 | fn expand_rule(rule: &crate::Rule, input: &tt::Subtree) -> Option<tt::Subtree> { |
11 | let mut input = TtCursor::new(input); | 11 | let mut input = TtCursor::new(input); |
12 | let bindings = match_lhs(&rule.lhs, &mut input)?; | 12 | let bindings = match_lhs(&rule.lhs, &mut input)?; |
13 | expand_subtree(&rule.rhs, &bindings, &mut Vec::new()) | 13 | expand_subtree(&rule.rhs, &bindings, &mut Vec::new()) |
@@ -52,12 +52,12 @@ impl Bindings { | |||
52 | } | 52 | } |
53 | } | 53 | } |
54 | 54 | ||
55 | fn match_lhs(pattern: &mbe::Subtree, input: &mut TtCursor) -> Option<Bindings> { | 55 | fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Option<Bindings> { |
56 | let mut res = Bindings::default(); | 56 | let mut res = Bindings::default(); |
57 | for pat in pattern.token_trees.iter() { | 57 | for pat in pattern.token_trees.iter() { |
58 | match pat { | 58 | match pat { |
59 | mbe::TokenTree::Leaf(leaf) => match leaf { | 59 | crate::TokenTree::Leaf(leaf) => match leaf { |
60 | mbe::Leaf::Var(mbe::Var { text, kind }) => { | 60 | crate::Leaf::Var(crate::Var { text, kind }) => { |
61 | let kind = kind.clone()?; | 61 | let kind = kind.clone()?; |
62 | match kind.as_str() { | 62 | match kind.as_str() { |
63 | "ident" => { | 63 | "ident" => { |
@@ -70,14 +70,14 @@ fn match_lhs(pattern: &mbe::Subtree, input: &mut TtCursor) -> Option<Bindings> { | |||
70 | _ => return None, | 70 | _ => return None, |
71 | } | 71 | } |
72 | } | 72 | } |
73 | mbe::Leaf::Punct(punct) => { | 73 | crate::Leaf::Punct(punct) => { |
74 | if input.eat_punct()? != punct { | 74 | if input.eat_punct()? != punct { |
75 | return None; | 75 | return None; |
76 | } | 76 | } |
77 | } | 77 | } |
78 | _ => return None, | 78 | _ => return None, |
79 | }, | 79 | }, |
80 | mbe::TokenTree::Repeat(mbe::Repeat { | 80 | crate::TokenTree::Repeat(crate::Repeat { |
81 | subtree, | 81 | subtree, |
82 | kind: _, | 82 | kind: _, |
83 | separator, | 83 | separator, |
@@ -114,7 +114,7 @@ impl_froms! (Foo: Bar, Baz) | |||
114 | */ | 114 | */ |
115 | 115 | ||
116 | fn expand_subtree( | 116 | fn expand_subtree( |
117 | template: &mbe::Subtree, | 117 | template: &crate::Subtree, |
118 | bindings: &Bindings, | 118 | bindings: &Bindings, |
119 | nesting: &mut Vec<usize>, | 119 | nesting: &mut Vec<usize>, |
120 | ) -> Option<tt::Subtree> { | 120 | ) -> Option<tt::Subtree> { |
@@ -131,13 +131,13 @@ fn expand_subtree( | |||
131 | } | 131 | } |
132 | 132 | ||
133 | fn expand_tt( | 133 | fn expand_tt( |
134 | template: &mbe::TokenTree, | 134 | template: &crate::TokenTree, |
135 | bindings: &Bindings, | 135 | bindings: &Bindings, |
136 | nesting: &mut Vec<usize>, | 136 | nesting: &mut Vec<usize>, |
137 | ) -> Option<tt::TokenTree> { | 137 | ) -> Option<tt::TokenTree> { |
138 | let res: tt::TokenTree = match template { | 138 | let res: tt::TokenTree = match template { |
139 | mbe::TokenTree::Subtree(subtree) => expand_subtree(subtree, bindings, nesting)?.into(), | 139 | crate::TokenTree::Subtree(subtree) => expand_subtree(subtree, bindings, nesting)?.into(), |
140 | mbe::TokenTree::Repeat(repeat) => { | 140 | crate::TokenTree::Repeat(repeat) => { |
141 | let mut token_trees = Vec::new(); | 141 | let mut token_trees = Vec::new(); |
142 | nesting.push(0); | 142 | nesting.push(0); |
143 | while let Some(t) = expand_subtree(&repeat.subtree, bindings, nesting) { | 143 | while let Some(t) = expand_subtree(&repeat.subtree, bindings, nesting) { |
@@ -152,14 +152,14 @@ fn expand_tt( | |||
152 | } | 152 | } |
153 | .into() | 153 | .into() |
154 | } | 154 | } |
155 | mbe::TokenTree::Leaf(leaf) => match leaf { | 155 | crate::TokenTree::Leaf(leaf) => match leaf { |
156 | mbe::Leaf::Ident(ident) => tt::Leaf::from(tt::Ident { | 156 | crate::Leaf::Ident(ident) => tt::Leaf::from(tt::Ident { |
157 | text: ident.text.clone(), | 157 | text: ident.text.clone(), |
158 | }) | 158 | }) |
159 | .into(), | 159 | .into(), |
160 | mbe::Leaf::Punct(punct) => tt::Leaf::from(punct.clone()).into(), | 160 | crate::Leaf::Punct(punct) => tt::Leaf::from(punct.clone()).into(), |
161 | mbe::Leaf::Var(v) => bindings.get(&v.text, nesting)?.clone(), | 161 | crate::Leaf::Var(v) => bindings.get(&v.text, nesting)?.clone(), |
162 | mbe::Leaf::Literal(l) => tt::Leaf::from(tt::Literal { | 162 | crate::Leaf::Literal(l) => tt::Leaf::from(tt::Literal { |
163 | text: l.text.clone(), | 163 | text: l.text.clone(), |
164 | }) | 164 | }) |
165 | .into(), | 165 | .into(), |