Skip to content

Commit cad98d1

Browse files
add match expression syntax
1 parent e6a5d5d commit cad98d1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/expressions/match-expr.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# `match` expressions
22

3+
> **<sup>Syntax</sup>**
4+
> _MatchExpression_ :
5+
> &nbsp;&nbsp; `match` [_Expression_]<sub>_except struct expression_</sub> _MatchBlock_
6+
>
7+
> _MatchBlock_ :
8+
> &nbsp;&nbsp; &nbsp;&nbsp; `{` `}`
9+
> &nbsp;&nbsp; | `{` (`|`<sup>?</sup> _Pattern_ (`|` _Pattern_)<sup>\*</sup> (`if` [_Expression_])<sup>?</sup> `=>` ([_BlockExpression_] `,`<sup>?</sup> | [_Expression_] `,`))<sup>\*</sup>
10+
> &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; (`|`<sup>?</sup> _Pattern_ (`|` _Pattern_)<sup>\*</sup> (`if` [_Expression_])<sup>?</sup> `=>` ([_BlockExpression_] `,`<sup>?</sup> | [_Expression_] `,`<sup>?</sup>))
11+
> &nbsp;&nbsp; &nbsp;&nbsp; `}`
12+
313
A `match` expression branches on a *pattern*. The exact form of matching that
414
occurs depends on the pattern. Patterns consist of some combination of
515
literals, destructured arrays or enum constructors, structs and tuples,
@@ -127,5 +137,7 @@ let message = match maybe_digit {
127137
};
128138
```
129139

140+
[_Expression_]: expressions.html
141+
[_BlockExpression_]: expressions/block-expr.html#block-expressions
130142
[place expression]: expressions.html#place-expressions-and-value-expressions
131-
[value expression]: expressions.html#place-expressions-and-value-expressions
143+
[value expression]: expressions.html#place-expressions-and-value-expressions

0 commit comments

Comments
 (0)