authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-18 18:11:12-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-18 18:11:12-05:00
logb0ceea1831047f374278734f1d86ac94f5438fb4
treeae475ba52b7df4f767695787163d194b70d0de4b
parent74bdc1d1f89870588e7ac86d9384187fd1f6c10d
signature Commit is signed but in an unrecognized format.

zig fmt: fix infix operator before multiline string literal


2 files changed, 12 insertions(+), 2 deletions(-)

std/zig/parser_test.zig+9
...@@ -1,3 +1,12 @@...@@ -1,3 +1,12 @@
1test "zig fmt: infix operator and then multiline string literal" {
2 try testCanonical(
3 \\const x = "" ++
4 \\ \\ hi
5 \\;
6 \\
7 );
8}
9
1test "zig fmt: C pointers" {10test "zig fmt: C pointers" {
2 try testCanonical(11 try testCanonical(
3 \\const Ptr = [*c]i32;12 \\const Ptr = [*c]i32;
std/zig/render.zig+3-2
...@@ -340,7 +340,6 @@ fn renderExpression(...@@ -340,7 +340,6 @@ fn renderExpression(
340 ast.Node.Id.InfixOp => {340 ast.Node.Id.InfixOp => {
341 const infix_op_node = @fieldParentPtr(ast.Node.InfixOp, "base", base);341 const infix_op_node = @fieldParentPtr(ast.Node.InfixOp, "base", base);
342342
343 const op_token = tree.tokens.at(infix_op_node.op_token);
344 const op_space = switch (infix_op_node.op) {343 const op_space = switch (infix_op_node.op) {
345 ast.Node.InfixOp.Op.Period, ast.Node.InfixOp.Op.ErrorUnion, ast.Node.InfixOp.Op.Range => Space.None,344 ast.Node.InfixOp.Op.Period, ast.Node.InfixOp.Op.ErrorUnion, ast.Node.InfixOp.Op.Range => Space.None,
346 else => Space.Space,345 else => Space.Space,
...@@ -353,7 +352,9 @@ fn renderExpression(...@@ -353,7 +352,9 @@ fn renderExpression(
353 };352 };
354353
355 try renderToken(tree, stream, infix_op_node.op_token, indent, start_col, after_op_space);354 try renderToken(tree, stream, infix_op_node.op_token, indent, start_col, after_op_space);
356 if (after_op_space == Space.Newline) {355 if (after_op_space == Space.Newline and
356 tree.tokens.at(tree.nextToken(infix_op_node.op_token)).id != Token.Id.MultilineStringLiteralLine)
357 {
357 try stream.writeByteNTimes(' ', indent + indent_delta);358 try stream.writeByteNTimes(' ', indent + indent_delta);
358 start_col.* = indent + indent_delta;359 start_col.* = indent + indent_delta;
359 }360 }