-
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
Add macro_rules fragment class for "expressions that can be followed by {
"
#1463
Comments
FYI, this covers more than predicates: // Does it cover `let x = y` (a predicate?) or just `y`?
while let x = y {
}
// no predicate in sight
for a in b {
} |
@Stebalien I am not quite sure how to interpret your comment. For example, |
Sorry, I meant to write "covers more than predicates" instead of "covers more than pred". My point was that neither |
@Stebalien ah yes; the name Really the most attractive thing about the token |
I might be having a brain fart, but what situations in the current grammar have expressions followed by In terms of bikeshedding the name:
Another crazy idea is "silent adaptation" -- if you put |
Yeah, it probably is bad; consider e.g. the macro pattern |
@pnkfelix IMO, that's unambiguous. |
@Stebalien in that case I think we would be better served by a separately named fragment class. Having the potentially matched forms of a NT depend on patterns potentially arbitrarily far ahead in the macro LHS seems bad |
Unless I'm mistaken, it only depends on the next pattern. However, I'm certainly not opposed to making it explicit (I just can't think of a name). |
Sorry I think my example failed to express what I'm concerned about; look e.g. at:
(Where I have now added a comma before $b so that we don't worry the two exprs right next to each other) In this case, a In this case, a ` |
Ah. I see. Yes, that's a problem.Steven Allen |
As part of this RFC (or maybe a separate one), can we expand a couple of follow sets with things they should logically already include, for macro writing convenience?
Did I miss any? |
@durka those sounds like good things, but I would put them in a separate RFC. Actually I'd put them into an amendment of the macro-future proofing RFC -- that is likely to ensure that it gets approved faster. |
See #1494. |
(spawned off of #1384 (comment) )
I've been leaving links to the above comment in all sorts of places, so I finally decided it was time to open an RFC issue for this idea.
Namely, to add some fragment class, which I'll call
pred
for now, that represents "the subset of expressions that do not have{
in their follow set, and thus the presence of a{
as the next token tells the parser that it is definitely done parsing the expression."In particular, this is the subset of expressions that we use for the test in an
if test { then } else { other }
Such an fragment class would be useful for writing
macro_rules!
that naturally want a{
to come after them in the input pattern.We used to superficially "allow" such macros, but they didn't actually work in general; see rust-lang/rust#26739
The text was updated successfully, but these errors were encountered: