Skip to content

Commit

Permalink
rust: macros: get paste! { [A $pos] } to work for integers
Browse files Browse the repository at this point in the history
Signed-off-by: Fabien Parent <[email protected]>
  • Loading branch information
Fabo committed Mar 1, 2024
1 parent 7b4547c commit 6f150e2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion rust/macros/paste.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ fn concat(tokens: &[TokenTree], group_span: Span) -> TokenTree {
let mut segments = Vec::new();
let mut span = None;
loop {
match tokens.next() {
let t = tokens.next();
match t {
None => break,
Some(TokenTree::Literal(lit)) => {
// Allow us to concat string literals by stripping quotes
Expand Down Expand Up @@ -46,6 +47,19 @@ fn concat(tokens: &[TokenTree], group_span: Span) -> TokenTree {
};
segments.push((value, sp));
}
Some(TokenTree::Group(group)) => {
let stream: Vec<_> = group.stream().into_iter().collect();
if let TokenTree::Literal(lit) = &stream[0] {
let mut value = lit.to_string();
if value.starts_with('"') && value.ends_with('"') {
value.remove(0);
value.pop();
}
segments.push((value, lit.span()));
} else {
panic!("unexpected token in paste segments");
}
}
_ => panic!("unexpected token in paste segments"),
};
}
Expand Down

0 comments on commit 6f150e2

Please sign in to comment.