Skip to content

Commit 79d825d

Browse files
committed
Ast: allow grouped while then expressions
Beforehand, `while (x) ({ ... })` would fail, however this is not consistent with the PEG grammar specified in the langref which allows any expression and makes the continue expression optional.
1 parent d772c06 commit 79d825d

File tree

3 files changed

+4
-19
lines changed

3 files changed

+4
-19
lines changed

lib/std/zig/Ast.zig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,6 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void {
491491
.varargs_nonfinal => {
492492
return stream.writeAll("function prototype has parameter after varargs");
493493
},
494-
.expected_continue_expr => {
495-
return stream.writeAll("expected ':' before while continue expression");
496-
},
497494

498495
.expected_semi_after_decl => {
499496
return stream.writeAll("expected ';' after declaration");
@@ -2906,7 +2903,6 @@ pub const Error = struct {
29062903
test_doc_comment,
29072904
comptime_doc_comment,
29082905
varargs_nonfinal,
2909-
expected_continue_expr,
29102906
expected_semi_after_decl,
29112907
expected_semi_after_stmt,
29122908
expected_comma_after_field,

lib/std/zig/Parse.zig

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2954,12 +2954,7 @@ fn expectFieldInit(p: *Parse) !Node.Index {
29542954

29552955
/// WhileContinueExpr <- COLON LPAREN AssignExpr RPAREN
29562956
fn parseWhileContinueExpr(p: *Parse) !?Node.Index {
2957-
_ = p.eatToken(.colon) orelse {
2958-
if (p.tokenTag(p.tok_i) == .l_paren and
2959-
p.tokensOnSameLine(p.tok_i - 1, p.tok_i))
2960-
return p.fail(.expected_continue_expr);
2961-
return null;
2962-
};
2957+
_ = p.eatToken(.colon) orelse return null;
29632958
_ = try p.expectToken(.l_paren);
29642959
const node = try p.parseAssignExpr() orelse return p.fail(.expected_expr_or_assignment);
29652960
_ = try p.expectToken(.r_paren);

lib/std/zig/parser_test.zig

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5383,17 +5383,11 @@ test "zig fmt: while continue expr" {
53835383
\\ while (i > 0)
53845384
\\ (i * 2);
53855385
\\}
5386+
\\T: (while (true) ({
5387+
\\ break usize;
5388+
\\})),
53865389
\\
53875390
);
5388-
try testError(
5389-
\\test {
5390-
\\ while (i > 0) (i -= 1) {
5391-
\\ print("test123", .{});
5392-
\\ }
5393-
\\}
5394-
, &[_]Error{
5395-
.expected_continue_expr,
5396-
});
53975391
}
53985392

53995393
test "zig fmt: canonicalize symbols (simple)" {

0 commit comments

Comments
 (0)