lang: slice ranges take the same bound markers as for-header ranges

xs[1..=3] (end inclusive), xs[0<..<4] (both exclusive), xs[..=2]
(prefix form with markers, implicit 0 start), xs[2<..] (open end,
exclusive start), and xs[..] (whole collection) — lowered as lo+1 /
hi+1 on the existing subslice op. Strings slice through the same path.
An explicit end marker requires an end expression, matching the
for-header rule.

Regression: examples/0052-basic-slice-range-bounds.sx.
This commit is contained in:
agra
2026-06-10 22:12:45 +03:00
parent f513c11ea6
commit fea5617e4e
9 changed files with 93 additions and 11 deletions

View File

@@ -965,9 +965,22 @@ word := msg[6..11]; // string → "world"
- `expr[start..end]` — elements from `start` (inclusive) to `end` (exclusive)
- `expr[start..]` — elements from `start` to end
- `expr[..end]` — elements from beginning to `end`
- `expr[..]` — the whole collection as a slice
- Result type: `[]T` for arrays/slices, `string` for strings
- No memory allocation — the result points into the original backing storage
Slice ranges take the same bound markers as for-header ranges — `=`
inclusive / `<` exclusive on either side of `..`, defaulting to
start-inclusive, end-exclusive:
```sx
arr[1..=3] // elements 1, 2, 3
arr[0<..<4] // elements 1, 2, 3
arr[..=2] // elements 0, 1, 2 (prefix form takes markers too)
arr[2<..] // elements 3 .. len-1
```
An explicit end marker (`..=` / `..<`) requires an end expression. Bounds
are arbitrary expressions (`arr[x-1..=x+1]`).
### Pointer Types
| Syntax | Meaning | `.len` | `[i]` |