Skip to content

Commit

Permalink
zig fmt: fix rendering of align keyword of slice type
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed May 25, 2018
1 parent 56cb7f1 commit a630d3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 9 additions & 0 deletions std/zig/parser_test.zig
@@ -1,3 +1,12 @@
test "zig fmt: slice align" {
try testCanonical(
\\const A = struct {
\\ items: []align(A) T,
\\};
\\
);
}

test "zig fmt: first thing in file is line comment" {
try testTransform(
\\comptime {
Expand Down
12 changes: 6 additions & 6 deletions std/zig/render.zig
Expand Up @@ -268,10 +268,10 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
ast.Node.PrefixOp.Op.AddrOf => |addr_of_info| {
try renderToken(tree, stream, prefix_op_node.op_token, indent, Space.None); // &
if (addr_of_info.align_info) |align_info| {
const align_token = tree.nextToken(prefix_op_node.op_token);
try renderToken(tree, stream, align_token, indent, Space.None); // align

const lparen_token = tree.prevToken(align_info.node.firstToken());
const align_token = tree.prevToken(lparen_token);

try renderToken(tree, stream, align_token, indent, Space.None); // align
try renderToken(tree, stream, lparen_token, indent, Space.None); // (

try renderExpression(allocator, stream, tree, indent, align_info.node, Space.None);
Expand Down Expand Up @@ -305,10 +305,10 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
try renderToken(tree, stream, tree.nextToken(prefix_op_node.op_token), indent, Space.None); // ]

if (addr_of_info.align_info) |align_info| {
const align_token = tree.nextToken(prefix_op_node.op_token);
try renderToken(tree, stream, align_token, indent, Space.None); // align

const lparen_token = tree.prevToken(align_info.node.firstToken());
const align_token = tree.prevToken(lparen_token);

try renderToken(tree, stream, align_token, indent, Space.None); // align
try renderToken(tree, stream, lparen_token, indent, Space.None); // (

try renderExpression(allocator, stream, tree, indent, align_info.node, Space.None);
Expand Down

0 comments on commit a630d3e

Please sign in to comment.