Skip to content

Ast: allow same-line grouped while then expressions #24487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/std/zig/Ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,6 @@ pub fn renderError(tree: Ast, parse_error: Error, w: *Writer) Writer.Error!void
.varargs_nonfinal => {
return w.writeAll("function prototype has parameter after varargs");
},
.expected_continue_expr => {
return w.writeAll("expected ':' before while continue expression");
},

.expected_semi_after_decl => {
return w.writeAll("expected ';' after declaration");
Expand Down Expand Up @@ -2974,7 +2971,6 @@ pub const Error = struct {
test_doc_comment,
comptime_doc_comment,
varargs_nonfinal,
expected_continue_expr,
expected_semi_after_decl,
expected_semi_after_stmt,
expected_comma_after_field,
Expand Down
7 changes: 1 addition & 6 deletions lib/std/zig/Parse.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2977,12 +2977,7 @@ fn expectFieldInit(p: *Parse) !Node.Index {

/// WhileContinueExpr <- COLON LPAREN AssignExpr RPAREN
fn parseWhileContinueExpr(p: *Parse) !?Node.Index {
_ = p.eatToken(.colon) orelse {
if (p.tokenTag(p.tok_i) == .l_paren and
p.tokensOnSameLine(p.tok_i - 1, p.tok_i))
return p.fail(.expected_continue_expr);
return null;
};
_ = p.eatToken(.colon) orelse return null;
_ = try p.expectToken(.l_paren);
const node = try p.parseAssignExpr() orelse return p.fail(.expected_expr_or_assignment);
_ = try p.expectToken(.r_paren);
Expand Down
12 changes: 3 additions & 9 deletions lib/std/zig/parser_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5426,17 +5426,11 @@ test "zig fmt: while continue expr" {
\\ while (i > 0)
\\ (i * 2);
\\}
\\T: (while (true) ({
\\ break usize;
\\})),
\\
);
try testError(
\\test {
\\ while (i > 0) (i -= 1) {
\\ print("test123", .{});
\\ }
\\}
, &[_]Error{
.expected_continue_expr,
});
}

test "zig fmt: canonicalize symbols (simple)" {
Expand Down