You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/csharp-8.0/ranges.md
+11-8Lines changed: 11 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,21 +99,24 @@ C# has no syntactic way to access "ranges" or "slices" of collections. Usually u
99
99
100
100
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.
101
101
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):
103
103
104
104
```antlr
105
-
shift_expression
106
-
: range_expression
107
-
| shift_expression '<<' range_expression
108
-
| shift_expressionright_shiftrange_expression
105
+
range_expression
106
+
: unary_expression
107
+
| range_expression? '..' range_expression?
109
108
;
110
109
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
114
115
;
115
116
```
116
117
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
+
117
120
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:
0 commit comments