-
Notifications
You must be signed in to change notification settings - Fork 492
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
Grammar: macros #458
Grammar: macros #458
Conversation
|
@@ -27,11 +66,11 @@ syntax named by _designator_. Valid designators are: | |||
* `expr`: an [expression] | |||
* `ty`: a [type] | |||
* `ident`: an [identifier] or [keyword] | |||
* `path`: a [path] | |||
* `tt`: a token tree (a single [token] by matching `()`, `[]`, or `{}`) | |||
* `path`: a [_TypePath_] style path |
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.
Could you name the relevant production in the grammar for all of these that have one?
src/macros-by-example.md
Outdated
* `expr` and `stmt` may only be followed by one of `=>`, `,`, or `;`. | ||
* `pat` may only be followed by one of `=>`, `,`, `=`, `|`, `if`, or `in`. | ||
* `path` and `ty` may only be followed by one of `=>`, `,`, `=`, `|`, `;`, | ||
`:`, `>`, `[`, `{`, `as`, `where`, or a macro variable of `block` |
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.
And >>
(rust-lang/rust#54977)
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.
Might want to add a note that >>
will not work in compilers prior to 1.31. (Didn't think about backporting it to 1.30, which we could have.)
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.
The reference documents as it is today, not what it was yesterday. We don't care about older releases.
|
||
// Macro calls within macros. | ||
macro_rules! example { | ||
() => { println!("Macro call in a macro!") }; |
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.
There should be some mention that the outer macro expands to the inner macro, which is then expanded.
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.
One more thing, I don't mind merging as is if you don't want to make more changes.
src/items.md
Outdated
> | _Macro_\ | ||
> | _MacroDefinition_\ | ||
> | [_MacroInvocationSemi_] [^novis]\ | ||
> | [_MacroRulesDefinition_] [^novis]\ |
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.
Was this deliberately not written like this?
OuterAttribute ( Visibility ? ( Module | ... | ExternBlock ) | MacroInvocationSemi | MacroRulesDefinition )
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.
I was trying to avoid making it too nested. In that example, there would need to be another set of parenthesis, like: OuterAttribute* ( ( Visibility? ( Module | ... | ExternBlock ) ) | MacroInvocationSemi | MacroRulesDefinition ) which seems a little unwieldy. I pushed a variation that removes the footnote, let me know if it looks any better.
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.
I think I prefer this version because the macro can expand to an item with a visibility.
Thanks! |
No description provided.