Skip to content

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

Merged
matthewjasper merged 1 commit into
rust-lang:masterfrom
goodmanjonathan:match_beginning_vert
Feb 6, 2018
Merged

Add match expression syntax and document feature(match_beginning_vert)#231
matthewjasper merged 1 commit into
rust-lang:masterfrom
goodmanjonathan:match_beginning_vert

Conversation

@goodmanjonathan

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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.

@alercahalercah added the RFC Stabilization Docs Documentation required for stabilizing a feature label Feb 1, 2018

@HavvyHavvy left a comment

Copy link
Copy Markdown
Contributor

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

@HavvyHavvy 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
Copy Markdown
ContributorAuthor

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#231Closesrust-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#231Closesrust-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#231Closesrust-lang#44101
@matthewjasper
matthewjasper merged commit 55893bf into rust-lang:masterFeb 6, 2018
@matthewjasper

Copy link
Copy Markdown
Contributor

Thanks!

@goodmanjonathan
goodmanjonathan deleted the match_beginning_vert branch February 6, 2018 16:52
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFC Stabilization DocsDocumentation required for stabilizing a featureS-waiting-on-stabilizationWaiting 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

@goodmanjonathan@matthewjasper@Havvy@alercah