dtolnay / quote

Rust quasi-quoting
Apache License 2.0
1.32k stars 90 forks source link

How to escape `#` character to allow quoting a quote! { } block #249

Closed sam0x17 closed 1 year ago

sam0x17 commented 1 year ago

I am dynamically generating some proc macros and am in a situation where I need to write a quote! block that contains another quote! block including interpolations on the inner quote! block. I would like to escape the # somehow within the inner quote! block so that the outer/real quote! block does not interpret them as interpolations. Is this possible?

quote! {
    // ...
    quote! {
        // I need to escape these interpolations so they are copied verbatim
        // and ignored by the outer `quote!` block
        let #some_ident = #some_value;
    }
    // ...
}
dtolnay commented 1 year ago

See #142.