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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user