Skip to content

Commit c85fec1

Browse files
Make logical patterns left-associative. (#2492)
This makes them consistent with expressions, which should make parsing easier. There should be no user-observable semantic difference.
1 parent b9f4356 commit c85fec1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

working/0546-patterns/patterns-feature-specification.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Author: Bob Nystrom
44

55
Status: In progress
66

7-
Version 2.5 (see [CHANGELOG](#CHANGELOG) at end)
7+
Version 2.6 (see [CHANGELOG](#CHANGELOG) at end)
88

99
Note: This proposal is broken into a couple of separate documents. See also
1010
[records][] and [exhaustiveness][].
@@ -214,8 +214,8 @@ Here is the overall grammar for the different kinds of patterns:
214214
pattern ::= logicalOrPattern
215215
patterns ::= pattern ( ',' pattern )* ','?
216216
217-
logicalOrPattern ::= logicalAndPattern ( '|' logicalOrPattern )?
218-
logicalAndPattern ::= relationalPattern ( '&' logicalAndPattern )?
217+
logicalOrPattern ::= ( logicalOrPattern '|' )? logicalAndPattern
218+
logicalAndPattern ::= ( logicalAndPattern '&' )? relationalPattern
219219
relationalPattern ::= ( equalityOperator | relationalOperator) relationalExpression
220220
| unaryPattern
221221
@@ -243,7 +243,7 @@ The individual patterns are:
243243
### Logical-or pattern
244244

245245
```
246-
logicalOrPattern ::= logicalAndPattern ( '|' logicalOrPattern )?
246+
logicalOrPattern ::= ( logicalOrPattern '|' )? logicalAndPattern
247247
```
248248

249249
A pair of patterns separated by `|` matches if either of the branches match.
@@ -300,7 +300,7 @@ problems stemming from that, the following restrictions apply:
300300
### Logical-and pattern
301301

302302
```
303-
logicalAndPattern ::= relationalPattern ( '&' logicalAndPattern )?
303+
logicalAndPattern ::= ( logicalAndPattern '&' )? relationalPattern
304304
```
305305

306306
A pair of patterns separated by `&` matches only if *both* subpatterns match.
@@ -2251,6 +2251,10 @@ Here is one way it could be broken down into separate pieces:
22512251
22522252
## Changelog
22532253
2254+
### 2.6
2255+
2256+
- Change logical-or and logical-and patterns to be left-associative.
2257+
22542258
### 2.5
22552259
22562260
- Move back to a syntax where variable declarations are explicit in cases but

0 commit comments

Comments
 (0)