Skip to content

Commit eaffdae

Browse files
Allow , to delimit macro 2.0 rules
1 parent eb264fb commit eaffdae

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

crates/mbe/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,11 @@ impl MacroDef {
220220
while src.len() > 0 {
221221
let rule = Rule::parse(&mut src, true)?;
222222
rules.push(rule);
223-
if let Err(()) = src.expect_char(';') {
223+
if let Err(()) = src.expect_any_char(&[';', ',']) {
224224
if src.len() > 0 {
225-
return Err(ParseError::Expected("expected `;`".to_string()));
225+
return Err(ParseError::Expected(
226+
"expected `;` or `,` to delimit rules".to_string(),
227+
));
226228
}
227229
break;
228230
}

crates/mbe/src/tests/expand.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,21 @@ macro foo {
662662
.assert_expand_items("foo!(bar);", "fn bar () {}");
663663
}
664664

665+
#[test]
666+
fn test_macro_2_0_panic_2015() {
667+
parse_macro2(
668+
r#"
669+
macro panic_2015 {
670+
() => (
671+
),
672+
(bar) => (
673+
),
674+
}
675+
"#,
676+
)
677+
.assert_expand_items("panic_2015!(bar);", "");
678+
}
679+
665680
#[test]
666681
fn test_path() {
667682
parse_macro(

crates/mbe/src/tt_iter.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ impl<'a> TtIter<'a> {
3434
}
3535
}
3636

37+
pub(crate) fn expect_any_char(&mut self, chars: &[char]) -> Result<(), ()> {
38+
match self.next() {
39+
Some(tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: c, .. })))
40+
if chars.contains(c) =>
41+
{
42+
Ok(())
43+
}
44+
_ => Err(()),
45+
}
46+
}
47+
3748
pub(crate) fn expect_subtree(&mut self) -> Result<&'a tt::Subtree, ()> {
3849
match self.next() {
3950
Some(tt::TokenTree::Subtree(it)) => Ok(it),

0 commit comments

Comments
 (0)