-
Notifications
You must be signed in to change notification settings - Fork 537
Grammar: Statements. #427
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: Statements. #427
Conversation
There's an issue with this PR. Some statements allow outer attributes, but that is not indicated in the grammar. I see two ways to fix that:
Statements that I know of that don't support attributes:
I lean towards 1, but please let me know which you think would be better. |
I think that's probably the right choice. |
20c0b33
to
f30c45d
Compare
I decided to document attributes in a slightly different way. It was more complex than I first thought, as it was accidentally stabilized for expressions in some contexts. I am a little uneasy about the way statements are defined. Technically the |
What I see LGTM. What I don't see, doesn't. |
I added to the list, though in a brief form. Hopefully that's ok, it seemed more natural that way instead of stuffing all the rules in one place. |
src/expressions/block-expr.md
Outdated
@@ -4,19 +4,11 @@ | |||
> _BlockExpression_ :\ | |||
> `{`\ | |||
> [_InnerAttribute_]<sup>\*</sup>\ | |||
> _Statements_<sup>\*</sup>\ | |||
> [_Statement_]<sup>\*</sup>\ |
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 a note that *
is lazy here.
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.
Just to be clear, are you saying that because block-expressions can be confused as to whether it is a statement or a tail expression?
This kinda gets back to my uneasiness with how statements are defined. Technically they do not include the trailing semicolon, they are separated by semicolons. I'm thinking about rewriting the grammar to express it that way. What do you think?
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.
yes { { 2 } }
has a tail expression, not a tail-statement.
If you can get statements without ;
to work well then I would prefer that but I couldn't work out how to do it myself.
Cleans up "Statement" definition. Adds "let" statement.
94a8929
to
f428fa2
Compare
f428fa2
to
49f5c9a
Compare
Ok, I have pushed an update to rewrite statements in such a way that I think is more correct (less wrong?). I also came across some related attributes that were missing. Please let me know if there's anything I can do to make it easier to review these things. Sample code, links to rustc source, whatever. |
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 this is good now. One thing that is maybe worth changing.
src/statements.md
Outdated
> `;`\ | ||
> | [_Item_]\ | ||
> | [_LetStatement_]\ | ||
> | [_ExpressionWithoutBlock_][expression] `;`\ |
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.
You could move these down to Expression statements
, also this arguably should be Expression since { { 1 } let x = 0; }
does not type check while { { 1 }; let x = 0; }
does.
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.
Ok, moved it down.
It can't be just Expression because { { () } let x = 0; }
is valid. That's why I put the sentence about blocks must have the unit type. Generally I don't think the grammar should include type checking rules.
Thanks for this! |
Cleans up "Statement" definition.
Adds "let" statement.