mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Allow ,
to delimit macro 2.0 rules
This commit is contained in:
parent
eb264fb819
commit
eaffdae300
3 changed files with 30 additions and 2 deletions
|
@ -220,9 +220,11 @@ impl MacroDef {
|
||||||
while src.len() > 0 {
|
while src.len() > 0 {
|
||||||
let rule = Rule::parse(&mut src, true)?;
|
let rule = Rule::parse(&mut src, true)?;
|
||||||
rules.push(rule);
|
rules.push(rule);
|
||||||
if let Err(()) = src.expect_char(';') {
|
if let Err(()) = src.expect_any_char(&[';', ',']) {
|
||||||
if src.len() > 0 {
|
if src.len() > 0 {
|
||||||
return Err(ParseError::Expected("expected `;`".to_string()));
|
return Err(ParseError::Expected(
|
||||||
|
"expected `;` or `,` to delimit rules".to_string(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -662,6 +662,21 @@ macro foo {
|
||||||
.assert_expand_items("foo!(bar);", "fn bar () {}");
|
.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]
|
#[test]
|
||||||
fn test_path() {
|
fn test_path() {
|
||||||
parse_macro(
|
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, ()> {
|
pub(crate) fn expect_subtree(&mut self) -> Result<&'a tt::Subtree, ()> {
|
||||||
match self.next() {
|
match self.next() {
|
||||||
Some(tt::TokenTree::Subtree(it)) => Ok(it),
|
Some(tt::TokenTree::Subtree(it)) => Ok(it),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue