diff options
Diffstat (limited to 'crates/ra_mbe/src/mbe_expander.rs')
-rw-r--r-- | crates/ra_mbe/src/mbe_expander.rs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 86867111f..66ea76698 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs | |||
@@ -121,6 +121,10 @@ impl Bindings { | |||
121 | } | 121 | } |
122 | Ok(()) | 122 | Ok(()) |
123 | } | 123 | } |
124 | |||
125 | fn merge(&mut self, nested: Bindings) { | ||
126 | self.inner.extend(nested.inner); | ||
127 | } | ||
124 | } | 128 | } |
125 | 129 | ||
126 | fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings, ExpandError> { | 130 | fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings, ExpandError> { |
@@ -236,7 +240,21 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings, | |||
236 | } | 240 | } |
237 | } | 241 | } |
238 | } | 242 | } |
239 | _ => {} | 243 | crate::TokenTree::Subtree(subtree) => { |
244 | let input_subtree = | ||
245 | input.eat_subtree().map_err(|_| ExpandError::UnexpectedToken)?; | ||
246 | if subtree.delimiter != input_subtree.delimiter { | ||
247 | return Err(ExpandError::UnexpectedToken); | ||
248 | } | ||
249 | |||
250 | let mut input = TtCursor::new(input_subtree); | ||
251 | let bindings = match_lhs(&subtree, &mut input)?; | ||
252 | if !input.is_eof() { | ||
253 | return Err(ExpandError::UnexpectedToken); | ||
254 | } | ||
255 | |||
256 | res.merge(bindings); | ||
257 | } | ||
240 | } | 258 | } |
241 | } | 259 | } |
242 | Ok(res) | 260 | Ok(res) |
@@ -287,7 +305,15 @@ fn expand_tt( | |||
287 | .into() | 305 | .into() |
288 | } | 306 | } |
289 | crate::Leaf::Punct(punct) => tt::Leaf::from(punct.clone()).into(), | 307 | crate::Leaf::Punct(punct) => tt::Leaf::from(punct.clone()).into(), |
290 | crate::Leaf::Var(v) => bindings.get(&v.text, nesting)?.clone(), | 308 | crate::Leaf::Var(v) => { |
309 | if v.text == "crate" { | ||
310 | // FIXME: Properly handle $crate token | ||
311 | tt::Leaf::from(tt::Ident { text: "$crate".into(), id: TokenId::unspecified() }) | ||
312 | .into() | ||
313 | } else { | ||
314 | bindings.get(&v.text, nesting)?.clone() | ||
315 | } | ||
316 | } | ||
291 | crate::Leaf::Literal(l) => tt::Leaf::from(tt::Literal { text: l.text.clone() }).into(), | 317 | crate::Leaf::Literal(l) => tt::Leaf::from(tt::Literal { text: l.text.clone() }).into(), |
292 | }, | 318 | }, |
293 | }; | 319 | }; |