Skip to content

Commit

Permalink
In macro definitions new name can start from $ without spaces before it.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Glusker committed Jan 17, 2024
1 parent 6356fca commit 293f34c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,13 @@ fn replace_names(input: &str) -> Option<(String, HashMap<String, String>)> {
if kind != FullCodeCharKind::Normal {
result.push(c);
} else if c == '$' {
// the name can end by starting new name with $
if !cur_name.is_empty() {
dbg!(&cur_name);
register_metavariable(&mut substs, &mut result, &cur_name, dollar_count);
dollar_count = 0;
cur_name.clear();
}
dollar_count += 1;
} else if dollar_count == 0 {
result.push(c);
Expand Down
8 changes: 8 additions & 0 deletions tests/source/issue-5905/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
macro_rules! test_macro {
($member:ident $($rest:tt)*) => {
paste::paste! {fn test(&self) {
(self.$member$($rest)* )
}}
};
}

7 changes: 7 additions & 0 deletions tests/target/issue-5905/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
macro_rules! test_macro {
($member:ident $($rest:tt)*) => {
paste::paste! {fn test(&self) {
(self.$member$($rest)* )
}}
};
}

0 comments on commit 293f34c

Please sign in to comment.