Skip to content

Commit 60748f6

Browse files
committed
Ast: allow same-line grouped while then expressions
Beforehand, `while (x) ({ ... })` would fail, however this is not consistent with the PEG grammar specified in the langref which does not require a newline when the then expression starts with parenthesis.
1 parent 4e6a049 commit 60748f6

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
@@ -493,9 +493,6 @@ pub fn renderError(tree: Ast, parse_error: Error, w: *Writer) Writer.Error!void
493493
.varargs_nonfinal => {
494494
return w.writeAll("function prototype has parameter after varargs");
495495
},
496-
.expected_continue_expr => {
497-
return w.writeAll("expected ':' before while continue expression");
498-
},
499496

500497
.expected_semi_after_decl => {
501498
return w.writeAll("expected ';' after declaration");
@@ -2974,7 +2971,6 @@ pub const Error = struct {
29742971
test_doc_comment,
29752972
comptime_doc_comment,
29762973
varargs_nonfinal,
2977-
expected_continue_expr,
29782974
expected_semi_after_decl,
29792975
expected_semi_after_stmt,
29802976
expected_comma_after_field,

lib/std/zig/Parse.zig

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

29782978
/// WhileContinueExpr <- COLON LPAREN AssignExpr RPAREN
29792979
fn parseWhileContinueExpr(p: *Parse) !?Node.Index {
2980-
_ = p.eatToken(.colon) orelse {
2981-
if (p.tokenTag(p.tok_i) == .l_paren and
2982-
p.tokensOnSameLine(p.tok_i - 1, p.tok_i))
2983-
return p.fail(.expected_continue_expr);
2984-
return null;
2985-
};
2980+
_ = p.eatToken(.colon) orelse return null;
29862981
_ = try p.expectToken(.l_paren);
29872982
const node = try p.parseAssignExpr() orelse return p.fail(.expected_expr_or_assignment);
29882983
_ = 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
@@ -5426,17 +5426,11 @@ test "zig fmt: while continue expr" {
54265426
\\ while (i > 0)
54275427
\\ (i * 2);
54285428
\\}
5429+
\\T: (while (true) ({
5430+
\\ break usize;
5431+
\\})),
54295432
\\
54305433
);
5431-
try testError(
5432-
\\test {
5433-
\\ while (i > 0) (i -= 1) {
5434-
\\ print("test123", .{});
5435-
\\ }
5436-
\\}
5437-
, &[_]Error{
5438-
.expected_continue_expr,
5439-
});
54405434
}
54415435

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

0 commit comments

Comments
 (0)