aboutsummaryrefslogtreecommitdiff
path: root/crates/mbe/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/mbe/src')
-rw-r--r--crates/mbe/src/lib.rs6
-rw-r--r--crates/mbe/src/tests/expand.rs15
-rw-r--r--crates/mbe/src/tt_iter.rs11
3 files changed, 30 insertions, 2 deletions
diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs
index e74f8cf3f..3af5bc18b 100644
--- a/crates/mbe/src/lib.rs
+++ b/crates/mbe/src/lib.rs
@@ -220,9 +220,11 @@ impl MacroDef {
220 while src.len() > 0 { 220 while src.len() > 0 {
221 let rule = Rule::parse(&mut src, true)?; 221 let rule = Rule::parse(&mut src, true)?;
222 rules.push(rule); 222 rules.push(rule);
223 if let Err(()) = src.expect_char(';') { 223 if let Err(()) = src.expect_any_char(&[';', ',']) {
224 if src.len() > 0 { 224 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 ));
226 } 228 }
227 break; 229 break;
228 } 230 }
diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs
index 8951f3813..e02d038b6 100644
--- a/crates/mbe/src/tests/expand.rs
+++ b/crates/mbe/src/tests/expand.rs
@@ -663,6 +663,21 @@ macro foo {
663} 663}
664 664
665#[test] 665#[test]
666fn test_macro_2_0_panic_2015() {
667 parse_macro2(
668 r#"
669macro panic_2015 {
670 () => (
671 ),
672 (bar) => (
673 ),
674}
675"#,
676 )
677 .assert_expand_items("panic_2015!(bar);", "");
678}
679
680#[test]
666fn test_path() { 681fn test_path() {
667 parse_macro( 682 parse_macro(
668 r#" 683 r#"
diff --git a/crates/mbe/src/tt_iter.rs b/crates/mbe/src/tt_iter.rs
index 319a40f2a..195b8cf30 100644
--- a/crates/mbe/src/tt_iter.rs
+++ b/crates/mbe/src/tt_iter.rs
@@ -34,6 +34,17 @@ impl<'a> TtIter<'a> {
34 } 34 }
35 } 35 }
36 36
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
37 pub(crate) fn expect_subtree(&mut self) -> Result<&'a tt::Subtree, ()> { 48 pub(crate) fn expect_subtree(&mut self) -> Result<&'a tt::Subtree, ()> {
38 match self.next() { 49 match self.next() {
39 Some(tt::TokenTree::Subtree(it)) => Ok(it), 50 Some(tt::TokenTree::Subtree(it)) => Ok(it),