-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add support for repetition to proc_macro::quote
#140238
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
Comments
Cc @dtolnay in case you have any notes here |
Also fyi @SpriteOvO if you might be interested in this, since you have done a lot of other work with |
I recommend copying from the quote crate. It is tricky to get something that has all the behaviors that people expect are "obvious". If you see
|
Hi there! Excuse me for interrupting, but I’d like to try working on this PR when I have time — as long as it’s not an urgent task. (I’m not very familiar with Rust macros, but I have solid experience with meta-programming in OCaml and Scala, so I believe I can handle it given enough time.) The main task seems to be porting the logic from declarative macros to procedural macros: The most challenging part for me is likely the parsing. |
@moatom I don't see why you have to replicate the parsing logic of the crate. I'm sure it won't interfere with the quoting behavior. The code for the quote crate I feel is unnecessarily complex by virtue of it being a declarative macro, with one of the comments also saying that it is written that way to avoid using a muncher. I think recursive descent (or a simpler method) would suffice. As for the grammar, I think I have got it here, though I'm not 100% sure I got everything correct. It is quite simple: <content> ::= <tokentree> | <tokentree> <quote> <content> | ε
<quote> ::= "$" <ident> | "$" <repetition>
<repetition> ::= "(" <content> ")" <quantifier>
<quantifier> ::= "*" | <punct> "*" |
I'm opening a standalone issue to have something with "help wanted" labels in case anyone is interested in picking this up.
Our
proc_macro::quote
does not support repetition, unlikequote
from thequote
crate. As mentioned many times on the tracking issue, this is something we should support or at least account for beforeproc_macro::quote
can be stabilized.This should use the syntax:
Where
CONTENTS
is the thing to be repeated andSEP
is an optional single-character separator. Expansion should work for anything that implementsIntoIterator
. This matches the quote crate's logic (except quote::quote uses#
rather than$
).It's probably easiest to just copy
quote
's logic here, which uses an extension trait to facilitate this.quote
crate source repo: https://github.com/dtolnay/quote.quote
that needs to be updated: https://github.com/rust-lang/rust/blob/fa58ce343ad498196d799a7381869e79938e952a/library/proc_macro/src/quote.rstests/ui/proc-macro/quote
for things we should reject)quote!
macro inproc_macro
#54722The text was updated successfully, but these errors were encountered: