Skip to content

Commit 0f55350

Browse files
authored
Merge pull request #2563 from rleungx/allow-underscore
allow underscore in macro_rules!
2 parents 752e2bd + bf3bf8c commit 0f55350

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ fn replace_names(input: &str) -> Option<(String, HashMap<String, String>)> {
460460
} else if c == '(' && cur_name.is_empty() {
461461
// FIXME: Support macro def with repeat.
462462
return None;
463-
} else if c.is_alphanumeric() {
463+
} else if c.is_alphanumeric() || c == '_' {
464464
cur_name.push(c);
465465
}
466466
}

tests/source/macro_rules.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,23 @@ macro_rules! add_message_to_notes {
168168
}
169169
}}
170170
}
171+
172+
// #2560
173+
macro_rules! binary {
174+
($_self:ident,$expr:expr, $lhs:expr,$func:ident) => {
175+
while $_self.matched($expr) {
176+
let op = $_self.get_binary_op()?;
177+
178+
let rhs = Box::new($_self.$func()?);
179+
180+
$lhs = Spanned {
181+
span: $lhs.get_span().to(rhs.get_span()),
182+
value: Expression::Binary {
183+
lhs: Box::new($lhs),
184+
op,
185+
rhs,
186+
},
187+
}
188+
}
189+
};
190+
}

tests/target/macro_rules.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,23 @@ macro_rules! add_message_to_notes {
200200
}
201201
}};
202202
}
203+
204+
// #2560
205+
macro_rules! binary {
206+
($_self:ident, $expr:expr, $lhs:expr, $func:ident) => {
207+
while $_self.matched($expr) {
208+
let op = $_self.get_binary_op()?;
209+
210+
let rhs = Box::new($_self.$func()?);
211+
212+
$lhs = Spanned {
213+
span: $lhs.get_span().to(rhs.get_span()),
214+
value: Expression::Binary {
215+
lhs: Box::new($lhs),
216+
op,
217+
rhs,
218+
},
219+
}
220+
}
221+
};
222+
}

0 commit comments

Comments
 (0)