Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support $interpolation? #3

Open
Goncalerta opened this issue Jan 29, 2019 · 5 comments
Open

Support $interpolation? #3

Goncalerta opened this issue Jan 29, 2019 · 5 comments
Labels
question Further information is requested

Comments

@Goncalerta
Copy link
Owner

Currently, this crate follows the syntax of dtolnay/quote, where the symbol # is used for interpolations. I wonder if this symbol was chosen because $ would clash with macro_rules!.

The (unstable) libproc_macro::quote uses $ rather than #. Would allowing this symbol as an alias to # be beneficial? Using $ would allow a smoother transition to libproc once quote is stable.

@Goncalerta Goncalerta added the question Further information is requested label Jan 29, 2019
@dtolnay
Copy link

dtolnay commented Jan 29, 2019

The choice of # is handy when writing a proc macro that emits macro_rules macros. If you go with $, you will want to come up with some syntax for escaping them, which is not needed for #.

@Goncalerta
Copy link
Owner Author

Interesting point. It didn't occur to me that someone could want to write a proc macro that emits macro_rules.

@eddyb
Copy link

eddyb commented Jan 30, 2019

I mentioned the implementation of proc_macro::quote! in the original thread (dtolnay/request-for-implementation#8 (comment)).

What it does is allow using $$ to escape $, which is probably fine, although I'd prefer \$ myself.

@dtolnay How do you deal with #[...] attribute syntax? Does it work out by simply not overlapping with #(...) or any other interpolation?

@dtolnay
Copy link

dtolnay commented Jan 30, 2019

The quote crate does not have any syntax for escaping anything, and I don't recall anyone asking for escaping in the past 2 years. It allows #[...] without needing an escape.

For \$ presumably you would also want an escape sequence for \ so that a macro can emit literally \$ as two tokens. Er, is the problem that \ is not allowed in macro input?

error: unknown start of token: \
 --> src/main.rs:2:25
  |
2 |     println!(stringify!(\));
  |                         ^

@eddyb
Copy link

eddyb commented Jan 30, 2019

Yeah, \ would have to be officially introduced, and you probably can't even allow it at all without giving it some semantics in macro_rules (because you can't add those later, and change the behavior of code using \).

This is a bit sad, as we could've introduced \ a while back, and properly supported higher-order macros even in cases where repetitions are used, but we didn't.

It overall makes me have no preference between using # and having to deal with $$.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants