authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-02 21:53:25-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-02 21:53:25-05:00
logf83411b0b1b857c7f8679e3b90d2093ba60621d4
treef34729cf06bea2534f62fe9dc10f63fab4d8ec6c
parente9536ca10fe53d829551624b9d5753b163577eb2
signaturelock-open Commit is signed but in an unrecognized format.

Revert "Trailing comma is respected for builtin calls"

This reverts commit afd029091854358e6e88cfc4cbb524022f4ec136. This caused test failures.

2 files changed, 7 insertions(+), 51 deletions(-)

lib/std/zig/parser_test.zig-21
...@@ -26,27 +26,6 @@ test "zig fmt: c pointer type" {...@@ -26,27 +26,6 @@ test "zig fmt: c pointer type" {
26 );26 );
27}27}
2828
29test "zig fmt: builtin call with trailing comma" {
30 try testCanonical(
31 \\pub fn main() void {
32 \\ _ = @intToPtr(
33 \\ a,
34 \\ b,
35 \\ );
36 \\ _ = @ptrCast(
37 \\ a,
38 \\ b,
39 \\ );
40 \\ _ = @call(
41 \\ a,
42 \\ b,
43 \\ c,
44 \\ );
45 \\}
46 \\
47 );
48}
49
50test "zig fmt: asm expression with comptime content" {29test "zig fmt: asm expression with comptime content" {
51 try testCanonical(30 try testCanonical(
52 \\comptime {31 \\comptime {
lib/std/zig/render.zig+7-30
...@@ -1263,40 +1263,17 @@ fn renderExpression(...@@ -1263,40 +1263,17 @@ fn renderExpression(
1263 try renderToken(tree, stream, builtin_call.builtin_token, indent, start_col, Space.None); // @name1263 try renderToken(tree, stream, builtin_call.builtin_token, indent, start_col, Space.None); // @name
1264 }1264 }
12651265
1266 const src_params_trailing_comma = blk: {1266 try renderToken(tree, stream, tree.nextToken(builtin_call.builtin_token), indent, start_col, Space.None); // (
1267 const maybe_comma = tree.prevToken(builtin_call.rparen_token);
1268 break :blk tree.tokens.at(maybe_comma).id == .Comma;
1269 };
1270
1271 const lparen = tree.nextToken(builtin_call.builtin_token);
1272
1273 if (!src_params_trailing_comma) {
1274 try renderToken(tree, stream, lparen, indent, start_col, Space.None); // (
12751267
1276 // render all on one line, no trailing comma1268 var it = builtin_call.params.iterator(0);
1277 var it = builtin_call.params.iterator(0);1269 while (it.next()) |param_node| {
1278 while (it.next()) |param_node| {1270 try renderExpression(allocator, stream, tree, indent, start_col, param_node.*, Space.None);
1279 try renderExpression(allocator, stream, tree, indent, start_col, param_node.*, Space.None);
1280 // try renderParamDecl(allocator, stream, tree, indent, start_col, param_node.*, Space.None);
1281
1282 if (it.peek() != null) {
1283 const comma_token = tree.nextToken(param_node.*.lastToken());
1284 try renderToken(tree, stream, comma_token, indent, start_col, Space.Space); // ,
1285 }
1286 }
1287 } else {
1288 // one param per line
1289 const new_indent = indent + indent_delta;
1290 try renderToken(tree, stream, lparen, new_indent, start_col, Space.Newline); // (
12911271
1292 var it = builtin_call.params.iterator(0);1272 if (it.peek() != null) {
1293 while (it.next()) |param_node| {1273 const comma_token = tree.nextToken(param_node.*.lastToken());
1294 try stream.writeByteNTimes(' ', new_indent);1274 try renderToken(tree, stream, comma_token, indent, start_col, Space.Space); // ,
1295 try renderExpression(allocator, stream, tree, indent, start_col, param_node.*, Space.Comma);
1296 }1275 }
1297 try stream.writeByteNTimes(' ', indent);
1298 }1276 }
1299
1300 return renderToken(tree, stream, builtin_call.rparen_token, indent, start_col, space); // )1277 return renderToken(tree, stream, builtin_call.rparen_token, indent, start_col, space); // )
1301 },1278 },
13021279