mirror of
https://gitee.com/openharmony/third_party_rust_quote
synced 2024-11-23 07:10:01 +00:00
Merge pull request #199 from dtolnay/respan
Recursively respan tokens interpolated from a macro_rules metavariable
This commit is contained in:
commit
d74545e82b
@ -184,10 +184,24 @@ pub fn parse(tokens: &mut TokenStream, s: &str) {
|
||||
|
||||
pub fn parse_spanned(tokens: &mut TokenStream, span: Span, s: &str) {
|
||||
let s: TokenStream = s.parse().expect("invalid token stream");
|
||||
tokens.extend(s.into_iter().map(|mut t| {
|
||||
t.set_span(span);
|
||||
t
|
||||
}));
|
||||
tokens.extend(s.into_iter().map(|t| respan_token_tree(t, span)));
|
||||
}
|
||||
|
||||
// Token tree with every span replaced by the given one.
|
||||
fn respan_token_tree(mut token: TokenTree, span: Span) -> TokenTree {
|
||||
match &mut token {
|
||||
TokenTree::Group(g) => {
|
||||
let stream = g
|
||||
.stream()
|
||||
.into_iter()
|
||||
.map(|token| respan_token_tree(token, span))
|
||||
.collect();
|
||||
*g = Group::new(g.delimiter(), stream);
|
||||
g.set_span(span);
|
||||
}
|
||||
other => other.set_span(span),
|
||||
}
|
||||
token
|
||||
}
|
||||
|
||||
pub fn push_ident(tokens: &mut TokenStream, s: &str) {
|
||||
|
Loading…
Reference in New Issue
Block a user