-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Macro fragment fields #3714
base: master
Are you sure you want to change the base?
Macro fragment fields #3714
Conversation
Oh, I like this. Cute idea. |
Nominating this (and related RFCs) for discussion, to decide whether we can process it asynchronously or whether we need a design meeting. |
I think an important discussion to be had will be whether it's okay for fields to "generate" tokens. The RFC itself already proposes that Unless the plan is to drop
Another discussion which may be necessary is pinning down exactly which types the fields should have. Unless macro-rules are significantly complicated by allowing subtyping in the future, for now, types are final. For example, using the The problem, though, is that suddenly:
Keen readers may notice that C-variadics The conservative choice, it seems to me, would be to err on the side of introduce fragment types more often than not, even if in the meantime they end up being functionally equivalent to another fragment type (or a set thereof). Note: editions may help here, but any change risks introducing breakage so... it may be best to think of editions as a last resort rather than as the default way. |
Co-authored-by: René Kijewski <Kijewski@users.noreply.github.com>
@matthieu-m So, I do in general think that we should allow fields to synthesize tokens. There are too many cases where it would be useful to present unified cases to macros to simplify writing macros. And in particular, for But that said, your comment and the mention of things like Imagine, for instance, matching Please note that this remains firmly within the future possibilities section, and I'm very intentionally leaving it out of this RFC to avoid blocking on figuring out the right design for conditionally available fields. But it is a rather appealing design. |
@matthieu-m wrote:
I don't think this is the case. Today, you can write a macro that matches the same tokens several different ways. And I think we could, for instance, present We can also add fields to existing fragment specifiers, without breaking compatibility. There are compatibility considerations we have to take care with, and we may need to introduce new fragment specifiers in the future to handle those; for instance, if we make a field require and it later becomes optional, we might have to introduce a new fragment specifier with it optional. But I don't think switching the type of a field (e.g. to a newly created fragment specifier) would break compatibility as long as it contains the same tokens. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT otherwise
This gives an example of needing to synthesize tokens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad to see someone materializing the idea I've had floating around for a while.
For the purpose of avoiding RFCs for future fields, I believe it would be best to explicitly grant T-lang the ability to decide this on their own volition.
|
||
- `:fn`: A function definition (including body). | ||
- `name`: The name of the function, as an `ident`. | ||
- `param`: The parameters of the function, presented as though captured by a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the "type" of this field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we add the macro fragment param
, then each repetition will have type param
; until then, each repetition looks like pat_param: ty
. (Handwaving the ...
case here.)
I added an unresolved question about whether we should develop a lighter-weight process/policy for approving these, and whether we should delegate them to another team (e.g. wg-macros). |
Add a syntax and mechanism for macros to access "fields" of high-level fragment
specifiers that they've matched, to let macros use the Rust parser for
robustness and future compatibility, while still extracting pieces of the
matched syntax.
This RFC introduces the syntax
${fragname.field}
, and a couple of fragment specifiers and their fields. The goal is to add more such fragment specifiers and fields, to allow more macros to leverage the Rust parser, but the purpose of this RFC is to introduce the concept and syntax.Rendered