parser: implement while loops, port while test

Implement in parser.c:
- parseWhileExpr: while (cond) body, with optional payload,
  continue expression, and else clause
- while_simple, while_cont, while AST nodes

Port test "while else err prong with no block".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-02-10 18:32:24 +00:00
parent 26c73c4f87
commit a8bca43940
2 changed files with 73 additions and 6 deletions

View File

@@ -1517,6 +1517,18 @@ test "zig fmt: whitespace fixes" {
);
}
test "zig fmt: while else err prong with no block" {
try testCanonical(
\\test "" {
\\ const result = while (returnError()) |value| {
\\ break value;
\\ } else |err| @as(i32, 2);
\\ try expect(result == 2);
\\}
\\
);
}
test "zig fmt: tagged union with enum values" {
try testCanonical(
\\const MultipleChoice2 = union(enum(u32)) {