feature. See also
. The project being documented here (as the example) is the Zig library itself.
Parse.expectWhileTypeExpr
fn expectWhileTypeExpr(p: *Parse) !Node.Index
File
Code
fn expectWhileTypeExpr(p: *Parse) !Node.Index {
const while_token = p.assertToken(.keyword_while);
_ = try p.expectToken(.l_paren);
const condition = try p.expectExpr();
_ = try p.expectToken(.r_paren);
_ = try p.parsePtrPayload();
const cont_expr = try p.parseWhileContinueExpr();
const then_expr = try p.expectTypeExpr();
_ = p.eatToken(.keyword_else) orelse {
if (cont_expr == null) {
return try p.addNode(.{
.tag = .while_simple,
.main_token = while_token,
.data = .{ .node_and_node = .{
condition,
then_expr,
} },
});
} else {
return try p.addNode(.{
.tag = .while_cont,
.main_token = while_token,
.data = .{ .node_and_extra = .{
condition,
try p.addExtra(Node.WhileCont{
.cont_expr = cont_expr.?,
.then_expr = then_expr,
}),
} },
});
}
};
_ = try p.parsePayload();
const else_expr = try p.expectTypeExpr();
return try p.addNode(.{
.tag = .@"while",
.main_token = while_token,
.data = .{ .node_and_extra = .{
condition,
try p.addExtra(Node.While{
.cont_expr = .fromOptional(cont_expr),
.then_expr = then_expr,
.else_expr = else_expr,
}),
} },
});
}