diff options
author | Jeff Muizelaar <[email protected]> | 2019-02-05 01:18:53 +0000 |
---|---|---|
committer | Jeff Muizelaar <[email protected]> | 2019-02-05 01:19:23 +0000 |
commit | a4b473226bd185e6a016b175bdee22901fafd7ce (patch) | |
tree | 112ef8e29756597c46615c509e342b159679d971 /crates/ra_mbe | |
parent | 0000f007873a3de2b454bd808083c0c0e8c6c6fa (diff) |
mbe: Ensure repetition separator matches
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r-- | crates/ra_mbe/src/lib.rs | 24 | ||||
-rw-r--r-- | crates/ra_mbe/src/mbe_expander.rs | 8 |
2 files changed, 30 insertions, 2 deletions
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 6f719acbf..2c8ad4429 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs | |||
@@ -256,4 +256,28 @@ impl_froms!(TokenTree: Leaf, Subtree); | |||
256 | assert_expansion(&rules, "foo! { eggs Baz }", "struct Baz ;"); | 256 | assert_expansion(&rules, "foo! { eggs Baz }", "struct Baz ;"); |
257 | } | 257 | } |
258 | 258 | ||
259 | #[test] | ||
260 | fn test_match_group_pattern_by_separator_token() { | ||
261 | let rules = create_rules( | ||
262 | r#" | ||
263 | macro_rules! foo { | ||
264 | ($ ($ i:ident),*) => ($ ( | ||
265 | mod $ i {} | ||
266 | )*); | ||
267 | ($ ($ i:ident)#*) => ($ ( | ||
268 | fn $ i() {} | ||
269 | )*); | ||
270 | ($ i:ident ,# $ j:ident) => ( | ||
271 | struct $ i; | ||
272 | struct $ j; | ||
273 | ) | ||
274 | } | ||
275 | "#, | ||
276 | ); | ||
277 | |||
278 | assert_expansion(&rules, "foo! { foo, bar }", "mod foo {} mod bar {}"); | ||
279 | assert_expansion(&rules, "foo! { foo# bar }", "fn foo () {} fn bar () {}"); | ||
280 | assert_expansion(&rules, "foo! { Foo,# Bar }", "struct Foo ; struct Bar ;"); | ||
281 | } | ||
282 | |||
259 | } | 283 | } |
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 212e2ea92..04b5a4035 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs | |||
@@ -140,8 +140,12 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Option<Bindings> | |||
140 | }) => { | 140 | }) => { |
141 | while let Some(nested) = match_lhs(subtree, input) { | 141 | while let Some(nested) = match_lhs(subtree, input) { |
142 | res.push_nested(nested)?; | 142 | res.push_nested(nested)?; |
143 | if separator.is_some() && !input.is_eof() { | 143 | if let Some(separator) = *separator { |
144 | input.eat_punct()?; | 144 | if !input.is_eof() { |
145 | if input.eat_punct()?.char != separator { | ||
146 | return None; | ||
147 | } | ||
148 | } | ||
145 | } | 149 | } |
146 | } | 150 | } |
147 | } | 151 | } |