-
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 future proofing #550
Changes from 1 commit
f2ee210
cc7f0e1
2ebedee
34a3bd6
645f679
849c0ae
8b475b5
bca17b4
b522379
5ef6de5
68ecb34
5db222a
b61c42a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
- RFC PR: (leave this empty) | ||
- Rust Issue: (leave this empty) | ||
|
||
**NOTE**: Draft, not finalized. | ||
|
||
# Key Terminology | ||
|
||
- `macro`: anything invokable as `foo!(...)` in source code. | ||
|
@@ -87,9 +85,9 @@ allowed tokens for the given NT's fragment specifier, and is defined below. | |
2. For each token `T` in `M`: | ||
1. If `T` is not an NT, continue. | ||
2. If `T` is a simple NT, look ahead to the next token `T'` in `M`. If | ||
`T'` is `EOF`, replace `T'` with `F`. If `T'` is in the set | ||
`FOLLOW(NT)`, `T'` is EOF, `T'` is any NT, or `T'` is any identifier, | ||
continue. Else, reject. | ||
`T'` is `EOF` or a close delimiter of a token tree, replace `T'` with | ||
`F`. If `T'` is in the set `FOLLOW(NT)`, `T'` is EOF, `T'` is any NT, | ||
or `T'` is any identifier, continue. Else, reject. | ||
3. Else, `T` is a complex NT. | ||
1. If `T` has the form `$(...)+` or `$(...)*`, run the algorithm on | ||
the contents with `F` set to `EOF`. If it accepts, continue, else, | ||
|
@@ -105,21 +103,16 @@ emitted and compilation should not complete. | |
The current legal fragment specifiers are: `item`, `block`, `stmt`, `pat`, | ||
`expr`, `ty`, `ident`, `path`, `meta`, and `tt`. | ||
|
||
- `FOLLOW(item)` = `{}` | ||
- `FOLLOW(block)` = `FOLLOW(expr)` | ||
- `FOLLOW(stmt)` = `FOLLOW(expr)` | ||
- `FOLLOW(pat)` = `{FatArrow, Comma, Pipe}` | ||
- `FOLLOW(expr)` = `{Comma, FatArrow, CloseBrace, CloseParen, Lit}` (where | ||
`Lit` is any literal, string or numeric) | ||
- `FOLLOW(ty)` = `{Comma, Eq, Gt, Lt, RArrow, FatArrow, OpenBrace, OpenParen, | ||
CloseBrace, CloseParen}` | ||
- `FOLLOW(expr)` = `{Comma, FatArrow, CloseBrace, CloseParen, CloseBracket}` | ||
- `FOLLOW(ty)` = `{Comma, CloseBrace, CloseParen, CloseBracket}` | ||
- `FOLLOW(block)` = any token | ||
- `FOLLOW(ident)` = any token | ||
- `FOLLOW(path)` = any token | ||
- `FOLLOW(meta)` = any token | ||
- `FOLLOW(tt)` = any token | ||
|
||
**Note**: the `FOLLOW` sets as given are based on every MBE in the Rust | ||
distribution, but should probably be tuned before the RFC is accepted. | ||
- `FOLLOW(item)` = up for discussion | ||
- `FOLLOW(path)` = up for discussion | ||
- `FOLLOW(meta)` = up for discussion | ||
|
||
# Drawbacks | ||
|
||
|
@@ -146,4 +139,9 @@ reasonable freedom. | |
|
||
# Unresolved questions | ||
|
||
Are the given `FOLLOW` sets adequate? | ||
1. What should the FOLLOW sets for `item`, `path`, and `meta` be? | ||
2. Should the `FOLLOW` set for `ty` be extended? In practice, `RArrow`, | ||
`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". | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider Looks like it's implied that each FOLLOW set contains all identifiers:
Further, alternation ( [1] RFC: Extend pattern syntax #99, postponed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how we ought to handle identifiers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For |
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.
Forgot one, of course:
=