lang: require ':' before a for-loop range cursor

The cursor clause now matches the collection form's ': (capture)' — 'for 0..N: (i)' instead of 'for 0..N (i)'. The colon is required when a cursor is present; the no-cursor form 'for 0..N { }' is unchanged. Updated examples/200, the pack-index doc comment, and the spec.
This commit is contained in:
agra
2026-05-31 10:57:21 +03:00
parent c08433b345
commit 6b5edc77b4
4 changed files with 17 additions and 12 deletions

View File

@@ -2867,9 +2867,12 @@ pub const Parser = struct {
var capture_by_ref = false;
if (range_end != null) {
// Range capture is the optional cursor: `(i)` or nothing.
if (self.current.tag == .l_paren) {
// Optional cursor, introduced by `:` for symmetry with the
// collection form: `for 0..N: (i)` (or `for 0..N` with no cursor).
// The colon is required when a cursor is present.
if (self.current.tag == .colon) {
self.advance();
try self.expect(.l_paren);
if (self.current.tag != .identifier) return self.fail("expected cursor variable name");
capture_name = self.tokenSlice(self.current);
self.advance();