Allow ,
to delimit macro 2.0 rules
This commit is contained in:
parent
eb264fb819
commit
eaffdae300
@ -220,9 +220,11 @@ impl MacroDef {
|
||||
while src.len() > 0 {
|
||||
let rule = Rule::parse(&mut src, true)?;
|
||||
rules.push(rule);
|
||||
if let Err(()) = src.expect_char(';') {
|
||||
if let Err(()) = src.expect_any_char(&[';', ',']) {
|
||||
if src.len() > 0 {
|
||||
return Err(ParseError::Expected("expected `;`".to_string()));
|
||||
return Err(ParseError::Expected(
|
||||
"expected `;` or `,` to delimit rules".to_string(),
|
||||
));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -662,6 +662,21 @@ macro foo {
|
||||
.assert_expand_items("foo!(bar);", "fn bar () {}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_macro_2_0_panic_2015() {
|
||||
parse_macro2(
|
||||
r#"
|
||||
macro panic_2015 {
|
||||
() => (
|
||||
),
|
||||
(bar) => (
|
||||
),
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.assert_expand_items("panic_2015!(bar);", "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_path() {
|
||||
parse_macro(
|
||||
|
@ -34,6 +34,17 @@ impl<'a> TtIter<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn expect_any_char(&mut self, chars: &[char]) -> Result<(), ()> {
|
||||
match self.next() {
|
||||
Some(tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: c, .. })))
|
||||
if chars.contains(c) =>
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn expect_subtree(&mut self) -> Result<&'a tt::Subtree, ()> {
|
||||
match self.next() {
|
||||
Some(tt::TokenTree::Subtree(it)) => Ok(it),
|
||||
|
Loading…
x
Reference in New Issue
Block a user