for arr: (it) {}
This commit is contained in:
@@ -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,
|
||||
} });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user