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

Macro future proofing #550

Merged
merged 13 commits into from Jan 19, 2015

Conversation

Projects
None yet
5 participants
@cmr
Copy link
Member

cmr commented Jan 3, 2015

@cmr

This comment has been minimized.

Copy link
Member Author

cmr commented Jan 3, 2015

# Unresolved questions

1. What should the FOLLOW sets for `item`, `path`, and `meta` be?
2. Should the `FOLLOW` set for `ty` be extended? In practice, `RArrow`,

This comment has been minimized.

@cmr

cmr Jan 3, 2015

Author Member

Forgot one, of course: =

`Colon`, `as`, and `in` are also used. (See next item)
2. What, if any, identifiers should be allowed in the FOLLOW sets? The author
is concerned that allowing arbitrary identifiers would limit the future use
of "contextual keywords".

This comment has been minimized.

@nrc

nrc Jan 4, 2015

Member

Could you give some intuition of what the effects are of including or excluding tokens in the FOLLOW sets? I.e., doe sit mean the new token can be used a delimiter token? What does it mean for future proofing? Does it restrict or extend what we can do in the future? How?

I have a feeling we should think about semi-colons, but I'm not sure how. Should they be in the follow sets for either expr or stmt? Is it true that an item must always end with a } or a ;? If so, does that mean we should take anything for FOLLOW for item? (I feel I only have about a 50% grasp of the concepts here, so forgive my possibly stupid questions)

This comment has been minimized.

@cmr

cmr Jan 4, 2015

Author Member

If a token is in the FOLLOW set of a nt, we can never change the language in such a way that parsing that nt would consume that token. This gives us a rigid boundary around which we can change the language and not break macros.

I think the FOLLOW for item could be everything. I think the FOLLOW for meta could be anything, but I'm not sure how that interacts with future plans for letting attributes contain arbitrary token trees. I really don't know about the futures of path/ty. path really ought to be removed, since there isn't really a single "path" that makes sense anymore.

This comment has been minimized.

@pczarn

pczarn Jan 4, 2015

Consider foo @ pat, an example of $_:pat. We might want to extend the pattern syntax so that pattern guards are allowed in patterns: foo @ pat if condition[1]. Now, let's assume this syntax is going to be added in 1.1. The input foo @ pat if something will continue to be accepted by the matcher ( $bar:pat if something ) for some time, but it will be rejected as soon as 1.1 comes. The culprit is the if in ( $bar:pat if something ) and hence if should be excluded from FOLLOW(pat).

Looks like it's implied that each FOLLOW set contains all identifiers:

If (...) T' is any identifier, continue. Else, reject.

Further, alternation (|) in patterns has been proposed in [1]. I think FOLLOW(pat) shouldn't include Pipe, too.
Edit: in both cases, the syntax that pat parses could be fixed.

[1] RFC: Extend pattern syntax #99, postponed

This comment has been minimized.

@cmr

cmr Jan 5, 2015

Author Member

I'm not sure how we ought to handle identifiers.

This comment has been minimized.

@cmr

cmr Jan 5, 2015

Author Member

For ty I have in the implementation as, ,, ->, :, =, and >. Any token for meta and item. Still not sure about path.

@nrc

This comment has been minimized.

Copy link
Member

nrc commented Jan 4, 2015

Oh, and a massive +1 to the overall idea here.

@pczarn

This comment has been minimized.

Copy link

pczarn commented Jan 4, 2015

+1, I'm convinced this is necessary. Detailed futures of some NTs are a bit unclear, though.

@cmr cmr referenced this pull request Jan 5, 2015

Merged

Macro input future proofing #20563

@cmr

This comment has been minimized.

Copy link
Member Author

cmr commented Jan 5, 2015

@alexcrichton alexcrichton referenced this pull request Jan 5, 2015

Closed

Macro reform #20482

@nrc nrc self-assigned this Jan 15, 2015

@nrc

This comment has been minimized.

Copy link
Member

nrc commented Jan 15, 2015

@cmr are there any changes you'd like to make to this RFC before we merge it?

@cmr

This comment has been minimized.

Copy link
Member Author

cmr commented Jan 15, 2015

@nick29581 maybe. The algorithm here no longer reflects the implementation, and the follow sets are subtly incorrect.

@nrc

This comment has been minimized.

Copy link
Member

nrc commented Jan 15, 2015

@cmr Ok, ping me when you are happy and I'll merge it

@cmr

This comment has been minimized.

Copy link
Member Author

cmr commented Jan 18, 2015

@nick29581 this is ready.

@nrc nrc merged commit b61c42a into rust-lang:master Jan 19, 2015


- `FOLLOW(pat)` = `{FatArrow, Comma, Eq}`
- `FOLLOW(expr)` = `{FatArrow, Comma, Semicolon}`
- `FOLLOW(ty)` = `{Comma, FatArrow, Colon, Eq, Gt, Ident(as)}`

This comment has been minimized.

@vadimcn

vadimcn Jan 23, 2015

Contributor

@cmr, was there a reason for not including Semicolon on this list as well?
It's handy when defining matchers like $( fn $n:ident( $(p:ident : $t:ty),* ) -> $r:ty ; )* (note the trailing 'ty')

This comment has been minimized.

@cmr

cmr Jan 23, 2015

Author Member

No, that was indeed an oversight

sent from my phone
On Jan 23, 2015 12:24 AM, "Vadim Chugunov" notifications@github.com wrote:

In text/0000-macro-future-proofing.md
#550 (comment):

  •   continue, else, reject.
    
    1. If T has the form $(...)U+ or $(...)U* for some token U, run
  •   the algorithm on the contents with `F` set to `U`. If it accepts,
    
  •   check that the last token in the sequence can be followed by `F`. If
    
  •   so, accept. Otherwise, reject.
    
    +This algorithm should be run on every matcher in every macro_rules
    +invocation, with F as EOF. If it rejects a matcher, an error should be
    +emitted and compilation should not complete.
    +
    +The current legal fragment specifiers are: item, block, stmt, pat,
    +expr, ty, ident, path, meta, and tt.
    +
    +- FOLLOW(pat) = {FatArrow, Comma, Eq}
    +- FOLLOW(expr) = {FatArrow, Comma, Semicolon}
    +- FOLLOW(ty) = {Comma, FatArrow, Colon, Eq, Gt, Ident(as)}

@cmr https://github.com/cmr, was there a reason for not including
Semicolon on this list as well?
It's handy when defining matchers like $( fn $n:ident( $(p:ident :
$t:ty),* ) -> $r:ty ; )* (note the trailing 'ty')


Reply to this email directly or view it on GitHub
https://github.com/rust-lang/rfcs/pull/550/files#r23432570.

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Jun 12, 2015

Remove 'html literals' macro test
This test was originally created back in 2012 as a test of the macro
system:
rust-lang@d704fc9

When the 'macro input future proofing' rust-lang/rfcs#550 was
implemented in rust-lang#20563, this test no longer worked properly.

Over the history of Rust, there have been a number of 'generate HTML
with a macro' libraries, the latest of which is Horrorshow:
https://users.rust-lang.org/t/horrorshow-a-no-longer-poc-html-template-library/1603

As such, I think this test doesn't really need to exist anymore, as it
would just be a test of horrorshow anyway.

Fixes rust-lang#20673
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.