dtolnay / quote

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

"*" cannot be used as a seperator #186

Closed Volker-Weissmann closed 2 years ago

Volker-Weissmann commented 3 years ago

#(#var),* produces a,b,c, but #(#var)** does work. How can I produce a*b*c?

Currently, I use #((#var) *)* 1.0, but this is not a perfect solution

dtolnay commented 2 years ago

The expansion to a b c * matches the behavior of macro_rules, so I think this is fine.

macro_rules! repro {
    ($($var:tt),*) => {
        stringify!($($var)**)
    };
}

fn main() {
    println!(repro!(a, b, c));
}

An alternative in both cases would be something like:

let mut rest = var.iter();
let first = rest.next();
quote! { #first #(* #rest)* }
Volker-Weissmann commented 2 years ago
let mut rest = var.iter();
let first = rest.next();
quote! { #first #(* #rest)* }

Thank you, this is what I needed.