authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-30 15:33:58-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-30 15:33:58-04:00
log93b51b0e4023c05f1ef40371b8e72004cb55f046
tree99d08b1618adb14daa3f5a1d0ff4c42da862ea2d
parent2c96f19fd3ed312e5cb0ac8006b73e73abf4a98d

spaces around slice operator if operands are infix

See #1003

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

std/zig/parser_test.zig+9
......@@ -1,3 +1,12 @@
1test "zig fmt: spaces around slice operator" {
2 try testCanonical(
3 \\var a = b[c..d];
4 \\var a = b[c + 1 .. d];
5 \\var a = b[c .. d + 1];
6 \\
7 );
8}
9
110test "zig fmt: async call in if condition" {
211 try testCanonical(
312 \\comptime {
std/zig/render.zig+6-2
......@@ -530,9 +530,13 @@ fn renderExpression(
530530 const lbracket = tree.prevToken(range.start.firstToken());
531531 const dotdot = tree.nextToken(range.start.lastToken());
532532
533 const spaces_around_op = range.start.id == ast.Node.Id.InfixOp or
534 (if (range.end) |end| end.id == ast.Node.Id.InfixOp else false);
535 const op_space = if (spaces_around_op) Space.Space else Space.None;
536
533537 try renderToken(tree, stream, lbracket, indent, start_col, Space.None); // [
534 try renderExpression(allocator, stream, tree, indent, start_col, range.start, Space.None);
535 try renderToken(tree, stream, dotdot, indent, start_col, Space.None); // ..
538 try renderExpression(allocator, stream, tree, indent, start_col, range.start, op_space);
539 try renderToken(tree, stream, dotdot, indent, start_col, op_space); // ..
536540 if (range.end) |end| {
537541 try renderExpression(allocator, stream, tree, indent, start_col, end, Space.None);
538542 }