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

Add match expression syntax and document feature(match_beginning_vert) #231

Merged

Conversation

goodmanjonathan
Copy link
Contributor

> _MatchBlock_ :
>       `{` `}`
> &nbsp;&nbsp; | `{` (`|`<sup>?</sup> _Pattern_ (`|` _Pattern_)<sup>\*</sup> (`if` [_Expression_])<sup>?</sup> `=>` ([_BlockExpression_] `,`<sup>?</sup> | [_Expression_] `,`))<sup>\*</sup>
> &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; (`|`<sup>?</sup> _Pattern_ (`|` _Pattern_)<sup>\*</sup> (`if` [_Expression_])<sup>?</sup> `=>` ([_BlockExpression_] `,`<sup>?</sup> | [_Expression_] `,`<sup>?</sup>))
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 line up the opening parenthesis with the one above it, but I couldn't quite line them up.

@alercah alercah added the RFC Stabilization Docs Documentation required for stabilizing a feature label Feb 1, 2018
Copy link
Contributor

@Havvy Havvy left a comment

Choose a reason for hiding this comment

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

This is correct, and it exists, and is better than anything, so I'm approving. 👍

But, with that said, there's a few things I don't like about this. The biggest is the duplication of the entire match clause for when there are multiple clauses. I'd rather a match clause be its own line (without the comma) and then MatchBlock would just be { _MatchClause_ (`,` _MatchClause_)<sup>*</sup> `,`<sup>?</sup> }.

@Havvy Havvy added the S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository label Feb 2, 2018
@goodmanjonathan
Copy link
Contributor Author

If I understand your suggestion correctly, you mean this:

MatchBlock :
      { }
   | { MatchClause (, MatchClause)* ,? }

MatchClause :
      |? Pattern (| Pattern)* (if [Expression])? => [Expression]

But if a MatchBlock has a non-final MatchClause with a BlockExpression on the right side of the =>, this fails to account for the comma being optional. I'm not seeing a way to solve that easily.

kennytm added a commit to kennytm/rust that referenced this pull request Feb 3, 2018
…inning_vert, r=petrochenkov

Stabilize feature(match_beginning_vert)

With this feature stabilized, match expressions can optionally have a `|` at the beginning of each arm.

Reference PR: rust-lang/reference#231

Closes rust-lang#44101
kennytm added a commit to kennytm/rust that referenced this pull request Feb 4, 2018
…inning_vert, r=petrochenkov

Stabilize feature(match_beginning_vert)

With this feature stabilized, match expressions can optionally have a `|` at the beginning of each arm.

Reference PR: rust-lang/reference#231

Closes rust-lang#44101
kennytm added a commit to kennytm/rust that referenced this pull request Feb 4, 2018
…inning_vert, r=petrochenkov

Stabilize feature(match_beginning_vert)

With this feature stabilized, match expressions can optionally have a `|` at the beginning of each arm.

Reference PR: rust-lang/reference#231

Closes rust-lang#44101
@matthewjasper matthewjasper merged commit 55893bf into rust-lang:master Feb 6, 2018
@matthewjasper
Copy link
Contributor

Thanks!

@goodmanjonathan goodmanjonathan deleted the match_beginning_vert branch February 6, 2018 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Stabilization Docs Documentation required for stabilizing a feature S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants