Skip to content

Fix struct_expr grammar: make base update part optional. #38957

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

Conversation

theduke
Copy link
Contributor

@theduke theduke commented Jan 10, 2017

The current grammar rule 'struct_expr' does not set the base update part
as optional. ( S { x: 55, ..base } ).

Fixed by a single ?.

I noticed this in #38956, but I'm not sure about the policy for PR. This seems like a disjoint change to me, therefore the separate PR. If things like this should be just mashed together to keep the queue cleaner, let me know.

The grammar also needs a lot of work (fix me everywhere). I might have time to make it more complete in the next weeks.

r? @steveklabnik

The current grammar rule 'struct_expr' does not set the base update part
as optional.

Fixed by a single ?.
@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @steveklabnik (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@theduke theduke closed this Jan 10, 2017
@theduke theduke reopened this Jan 10, 2017
@@ -512,7 +512,7 @@ unit_expr : "()" ;
```antlr
struct_expr : expr_path '{' ident ':' expr
[ ',' ident ':' expr ] *
[ ".." expr ] '}' |
[ ".." expr ] ? '}' |
Copy link
Member

@nagisa nagisa Jan 10, 2017

Choose a reason for hiding this comment

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

IIRC [ <rules> ] already means <rules> are optional.

Side note: this rule says A { a: 0 .. A { ..Default::default() } (note the missing comma after the 0) would do base update twice, but the comma between fields and base update cannot be omitted here. It also disallows A { ..Default::default() } which is valid, because it requires at least one field. Want to fix this rule?

Copy link
Contributor Author

@theduke theduke Jan 10, 2017

Choose a reason for hiding this comment

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

Often in BNF () is used for grouping and [] for optional but in grammar.md it's used just for grouping. ( quote: Square brackets are used to group rules. )

Copy link
Contributor Author

@theduke theduke Jan 10, 2017

Choose a reason for hiding this comment

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

But yeah I'll fix the rule to be valid, but this will be affected by my other PR.

I think I'll just close this down and do some more thought out work on the grammar.

@theduke theduke closed this Jan 10, 2017
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