From bf3bf8c235af8a9f0267782cddfa0ac99f4895bf Mon Sep 17 00:00:00 2001 From: rleungx Date: Mon, 26 Mar 2018 20:45:39 +0800 Subject: [PATCH] allow underscore --- src/macros.rs | 2 +- tests/source/macro_rules.rs | 20 ++++++++++++++++++++ tests/target/macro_rules.rs | 20 ++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/macros.rs b/src/macros.rs index b3f443a628e..bd8b86a49d4 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -460,7 +460,7 @@ fn replace_names(input: &str) -> Option<(String, HashMap)> { } else if c == '(' && cur_name.is_empty() { // FIXME: Support macro def with repeat. return None; - } else if c.is_alphanumeric() { + } else if c.is_alphanumeric() || c == '_' { cur_name.push(c); } } diff --git a/tests/source/macro_rules.rs b/tests/source/macro_rules.rs index f390b426317..3f7f5d621c3 100644 --- a/tests/source/macro_rules.rs +++ b/tests/source/macro_rules.rs @@ -168,3 +168,23 @@ macro_rules! add_message_to_notes { } }} } + +// #2560 +macro_rules! binary { + ($_self:ident,$expr:expr, $lhs:expr,$func:ident) => { + while $_self.matched($expr) { + let op = $_self.get_binary_op()?; + + let rhs = Box::new($_self.$func()?); + + $lhs = Spanned { + span: $lhs.get_span().to(rhs.get_span()), + value: Expression::Binary { + lhs: Box::new($lhs), + op, + rhs, + }, + } + } + }; +} diff --git a/tests/target/macro_rules.rs b/tests/target/macro_rules.rs index 12fdb7b026e..7d527b0c3fd 100644 --- a/tests/target/macro_rules.rs +++ b/tests/target/macro_rules.rs @@ -200,3 +200,23 @@ macro_rules! add_message_to_notes { } }}; } + +// #2560 +macro_rules! binary { + ($_self:ident, $expr:expr, $lhs:expr, $func:ident) => { + while $_self.matched($expr) { + let op = $_self.get_binary_op()?; + + let rhs = Box::new($_self.$func()?); + + $lhs = Spanned { + span: $lhs.get_span().to(rhs.get_span()), + value: Expression::Binary { + lhs: Box::new($lhs), + op, + rhs, + }, + } + } + }; +} -- 2.44.0