mbe: Ensure repetition separator matches

This commit is contained in:
Jeff Muizelaar 2019-02-04 20:18:53 -05:00
parent 0000f00787
commit a4b473226b
2 changed files with 30 additions and 2 deletions

View file

@ -256,4 +256,28 @@ impl_froms!(TokenTree: Leaf, Subtree);
assert_expansion(&rules, "foo! { eggs Baz }", "struct Baz ;"); assert_expansion(&rules, "foo! { eggs Baz }", "struct Baz ;");
} }
#[test]
fn test_match_group_pattern_by_separator_token() {
let rules = create_rules(
r#"
macro_rules! foo {
($ ($ i:ident),*) => ($ (
mod $ i {}
)*);
($ ($ i:ident)#*) => ($ (
fn $ i() {}
)*);
($ i:ident ,# $ j:ident) => (
struct $ i;
struct $ j;
)
}
"#,
);
assert_expansion(&rules, "foo! { foo, bar }", "mod foo {} mod bar {}");
assert_expansion(&rules, "foo! { foo# bar }", "fn foo () {} fn bar () {}");
assert_expansion(&rules, "foo! { Foo,# Bar }", "struct Foo ; struct Bar ;");
}
} }

View file

@ -140,8 +140,12 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Option<Bindings>
}) => { }) => {
while let Some(nested) = match_lhs(subtree, input) { while let Some(nested) = match_lhs(subtree, input) {
res.push_nested(nested)?; res.push_nested(nested)?;
if separator.is_some() && !input.is_eof() { if let Some(separator) = *separator {
input.eat_punct()?; if !input.is_eof() {
if input.eat_punct()?.char != separator {
return None;
}
}
} }
} }
} }