authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-23 18:23:49-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-23 18:23:49-07:00
log988f1c6a6f075e63d0ab2dc8f6e802a67b4a0902
tree556d86698b53d5be7708ded08c817ba4f28d318c
parent08107a555eb1bc8d6e9aa8d80507896d08b2b18d

zig fmt: fn proto end with anytype and comma

also zig fmt: space after top level doc comment

3 files changed, 34 insertions(+), 1 deletions(-)

lib/std/zig/parse.zig+6-1
......@@ -3706,7 +3706,12 @@ const Parser = struct {
37063706 const param = try p.expectParamDecl();
37073707 if (param != 0) break param;
37083708 switch (p.token_tags[p.nextToken()]) {
3709 .comma => continue,
3709 .comma => {
3710 if (p.eatToken(.r_paren)) |_| {
3711 return SmallSpan{ .zero_or_one = 0 };
3712 }
3713 continue;
3714 },
37103715 .r_paren => return SmallSpan{ .zero_or_one = 0 },
37113716 else => {
37123717 // This is likely just a missing comma;
lib/std/zig/parser_test.zig+18
......@@ -4134,6 +4134,24 @@ test "zig fmt: function params should align nicely" {
41344134 );
41354135}
41364136
4137test "zig fmt: fn proto end with anytype and comma" {
4138 try testCanonical(
4139 \\pub fn format(
4140 \\ out_stream: anytype,
4141 \\) !void {}
4142 \\
4143 );
4144}
4145
4146test "zig fmt: space after top level doc comment" {
4147 try testCanonical(
4148 \\//! top level doc comment
4149 \\
4150 \\field: i32,
4151 \\
4152 );
4153}
4154
41374155test "zig fmt: error for invalid bit range" {
41384156 try testError(
41394157 \\var x: []align(0:0:0)u8 = bar;
lib/std/zig/render.zig+10
......@@ -1449,6 +1449,8 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full.
14491449 .identifier => {},
14501450 .keyword_anytype => {
14511451 try renderToken(ais, tree, last_param_token, .comma); // anytype
1452 if (token_tags[last_param_token + 1] == .comma)
1453 last_param_token += 1;
14521454 continue;
14531455 },
14541456 .r_paren => break,
......@@ -1462,6 +1464,8 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full.
14621464 }
14631465 if (token_tags[last_param_token] == .keyword_anytype) {
14641466 try renderToken(ais, tree, last_param_token, .comma); // anytype
1467 if (token_tags[last_param_token + 1] == .comma)
1468 last_param_token += 1;
14651469 continue;
14661470 }
14671471 const param = fn_proto.ast.params[param_i];
......@@ -2363,6 +2367,12 @@ fn renderContainerDocComments(ais: *Ais, tree: ast.Tree, start_token: ast.TokenI
23632367 while (token_tags[tok] == .container_doc_comment) : (tok += 1) {
23642368 try renderToken(ais, tree, tok, .newline);
23652369 }
2370 // Render extra newline if there is one between final container doc comment and
2371 // the next token. If the next token is a doc comment, that code path
2372 // will have its own logic to insert a newline.
2373 if (token_tags[tok] != .doc_comment) {
2374 try renderExtraNewlineToken(ais, tree, tok);
2375 }
23662376}
23672377
23682378fn tokenSliceForRender(tree: ast.Tree, token_index: ast.TokenIndex) []const u8 {