Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/proc-macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ use proc_macro::*;
/// ```
#[proc_macro]
pub fn pattern(input: TokenStream) -> TokenStream {
let input = input.into_iter().collect::<Vec<_>>();
let mut input = input.into_iter().collect::<Vec<_>>();

// When calling the macro with a macro_rules capture, say $pat, the TokenTree
// will instead be a no-delimiter Group containing the expanded value of $pat.
// Unpack no-delimiter groups to handle this
match &input[..] {
[TokenTree::Group(g)] if g.delimiter() == Delimiter::None => input = g.stream().into_iter().collect::<Vec<_>>(),
_ => (),
};

let string = match &input[..] {
[TokenTree::Literal(lit)] => parse_str_literal(&lit),
Expand Down
Loading