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

Grammar: macros #458

Merged
merged 3 commits into from
Nov 3, 2018
Merged

Grammar: macros #458

merged 3 commits into from
Nov 3, 2018

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Oct 23, 2018

No description provided.

@ehuss
Copy link
Contributor Author

ehuss commented Oct 23, 2018

  • I included the unstable ? kleene operator, see ? kleene macro operator is unstable #456.
  • This doesn't add any details about how substitution works, since that is a big and complex topic, not directly related to the grammar rules.
  • The "novis" footnotes seem a little awkward. Not sure of the best way to express that.

@@ -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
Copy link
Contributor

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?

* `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`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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.)

Copy link
Contributor

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!") };
Copy link
Contributor

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.

Copy link
Contributor

@matthewjasper matthewjasper left a 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]\
Copy link
Contributor

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 )

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@matthewjasper matthewjasper merged commit 34c92dd into rust-lang:master Nov 3, 2018
@matthewjasper
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants