Skip to content

Commit 604250f

Browse files
committed
update precedence rules for range expression.
1 parent 4c133f9 commit 604250f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

proposals/csharp-8.0/ranges.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,24 @@ C# has no syntactic way to access "ranges" or "slices" of collections. Usually u
9999

100100
The language will introduce a new range operator `x..y`. It is a binary infix operator that accepts two expressions. Either operand can be omitted (examples below), and they have to be convertible to `System.Index`. It will be lowered to the appropriate `System.Range` factory method call.
101101

102-
We replace the C# grammar rules for *shift_expression* with the following (in order to introduce a new precedence level):
102+
-We replace the C# grammar rules for *multiplicative_expression* with the following (in order to introduce a new precedence level):
103103

104104
```antlr
105-
shift_expression
106-
: range_expression
107-
| shift_expression '<<' range_expression
108-
| shift_expression right_shift range_expression
105+
range_expression
106+
: unary_expression
107+
| range_expression? '..' range_expression?
109108
;
110109

111-
range_expression
112-
: additive_expression
113-
| range_expression? '..' additive_expression?
110+
multiplicative_expression
111+
: range_expression
112+
| multiplicative_expression '*' range_expression
113+
| multiplicative_expression '/' range_expression
114+
| multiplicative_expression '%' range_expression
114115
;
115116
```
116117

118+
All forms of the *range operator* have the same precedence. This new precedence group is lower than the *unary operators* and higher than the *mulitiplicative arithmetic operators*.
119+
117120
We call the `..` operator the *range operator*. The built-in range operator can roughly be understood to correspond to the invocation of a built-in operator of this form:
118121

119122
```csharp

0 commit comments

Comments
 (0)