lang: range bound markers — '=' inclusive / '<' exclusive on either side of '..'
Each side of '..' takes an optional bound marker, defaulting to
start-inclusive, end-exclusive (a..b == a=..<b; a..=b stays the short
end-inclusive spelling):
for 0<..<N (i) { } // 1 .. N-1 (both exclusive)
for 0=..=N (i) { } // 0 .. N (both inclusive)
for 0<..=N (i) { } // 1 .. N
for 0..<N (i) { } // 0 .. N-1 (explicit default)
for xs, 2<.. (x, i) // open range, exclusive start: i = 3, 4, ...
The nine lexemes are single tokens (maximal munch on '<'/'='/'..'), so
expression parsing never sees the leading marker as a comparison; '<',
'<<', '<=', '==', '=>' lex unchanged. An explicit end marker makes the
end expression mandatory; open forms are a.. / a<.. / a=... Works in
runtime, multi-iterable, and inline-for headers.
Regression: examples/0051-basic-for-range-bounds.sx (full matrix, open
start-marked ranges, comptime unroll, runtime bounds, lexer
non-regression); 1152's pinned message generalized.
This commit is contained in:
1
examples/expected/0051-basic-for-range-bounds.exit
Normal file
1
examples/expected/0051-basic-for-range-bounds.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
1
examples/expected/0051-basic-for-range-bounds.stderr
Normal file
1
examples/expected/0051-basic-for-range-bounds.stderr
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
12
examples/expected/0051-basic-for-range-bounds.stdout
Normal file
12
examples/expected/0051-basic-for-range-bounds.stdout
Normal file
@@ -0,0 +1,12 @@
|
||||
1 2 3 4 | 0<..<5
|
||||
0 1 2 3 4 5 | 0=..=5
|
||||
1 2 3 4 5 | 0<..=5
|
||||
0 1 2 3 4 | 0=..<5
|
||||
0 1 2 3 4 | 0..<5
|
||||
0 1 2 3 4 5 | 0..=5
|
||||
10@3 20@4 30@5 | xs, 2<..
|
||||
10@5 20@6 30@7 | xs, 5=..
|
||||
inline 0<..=3 sum=6
|
||||
2 3 4 | lo<..=hi
|
||||
cmp ok
|
||||
shl=6
|
||||
@@ -1,5 +1,5 @@
|
||||
error: '..=' requires an end expression — the open form is 'a..'
|
||||
--> examples/1152-diagnostics-for-inclusive-open.sx:6:14
|
||||
error: a range with an explicit end marker ('..=' / '..<') requires an end expression — the open form is 'a..'
|
||||
--> examples/1152-diagnostics-for-inclusive-open.sx:7:14
|
||||
|
|
||||
6 | for 0..= (i) { }
|
||||
7 | for 0..= (i) { }
|
||||
| ^
|
||||
|
||||
Reference in New Issue
Block a user