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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/doc/grammar.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

expr_path '(' expr
[ ',' expr ] * ')' |
expr_path ;
Expand Down