for arr: (it) {}

This commit is contained in:
agra
2026-02-16 00:55:03 +02:00
parent 3e1e764753
commit fb60818424
7 changed files with 88 additions and 56 deletions

View File

@@ -1428,11 +1428,33 @@ pub const Parser = struct {
self.advance(); // skip 'for'
const iterable = try self.parseExpr();
// Expect ': (' capture clause
try self.expect(.colon);
try self.expect(.l_paren);
// Capture variable name
if (self.current.tag != .identifier) return self.fail("expected capture variable name");
const capture_name = self.tokenSlice(self.current);
self.advance();
// Optional ', index_name'
var index_name: ?[]const u8 = null;
if (self.current.tag == .comma) {
self.advance();
if (self.current.tag != .identifier) return self.fail("expected index variable name");
index_name = self.tokenSlice(self.current);
self.advance();
}
try self.expect(.r_paren);
const body = try self.parseBlock();
return try self.createNode(start, .{ .for_expr = .{
.iterable = iterable,
.body = body,
.capture_name = capture_name,
.index_name = index_name,
} });
}