diff --git a/examples/0051-basic-for-range-bounds.sx b/examples/0051-basic-for-range-bounds.sx index 1c23882..bbd5de5 100644 --- a/examples/0051-basic-for-range-bounds.sx +++ b/examples/0051-basic-for-range-bounds.sx @@ -1,7 +1,9 @@ // Range bound markers: each side of `..` takes `=` (inclusive) or `<` // (exclusive); defaults are start-inclusive, end-exclusive (`a..b` == `a=.. s32 { for lo<..=hi (i) { print("{} ", i); } print("| lo<..=hi\n"); + // Arbitrary expressions at either end of the range token. + x := 2; + n := 0; + sum := 0; + for x+2..=42 (e) { n += 1; sum += e; } // expression start: 4 .. 42 + print("x+2..=42: n={} sum={}\n", n, sum); + n2 := 0; + for x+2<.. n2 += 1; // both ends: 5 .. 41 + print("x+2<.. n3 += 1; // expression end: 0 .. 5 + print("0..x*3: n3={}\n", n3); + // Comparison operators still lex normally. a := 3; if a < 5 { print("cmp ok\n"); } diff --git a/examples/expected/0051-basic-for-range-bounds.stdout b/examples/expected/0051-basic-for-range-bounds.stdout index 6e74f14..c6fa043 100644 --- a/examples/expected/0051-basic-for-range-bounds.stdout +++ b/examples/expected/0051-basic-for-range-bounds.stdout @@ -8,5 +8,8 @@ 10@5 20@6 30@7 | xs, 5=.. inline 0<..=3 sum=6 2 3 4 | lo<..=hi +x+2..=42: n=39 sum=897 +x+2<..