zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 3fa0bed985b8de950859d4c482efe9cb30fdaf27 (tree)
parent 9543c0a7cc0bbdccc405370e224b546c56b76a0f
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Sun, 29 Apr 2018 18:22:24 -0400

zig fmt: array literal with 1 item on 1 line

Diffstat:
Mstd/zig/parser.zig | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/std/zig/parser.zig b/std/zig/parser.zig @@ -3730,6 +3730,16 @@ pub const Parser = struct { try stack.append(RenderState { .Expression = suffix_op.lhs }); continue; } + if (exprs.len == 1) { + const expr = exprs.at(0); + + try stack.append(RenderState { .Text = "}" }); + try stack.append(RenderState { .Expression = expr }); + try stack.append(RenderState { .Text = " {" }); + try stack.append(RenderState { .Expression = suffix_op.lhs }); + continue; + } + try stack.append(RenderState { .Text = "}"}); try stack.append(RenderState.PrintIndent); try stack.append(RenderState { .Indent = indent }); @@ -4513,6 +4523,13 @@ fn testCanonical(source: []const u8) !void { } } +test "zig fmt: array literal with 1 item on 1 line" { + try testCanonical( + \\var s = []const u64 {0} ** 25; + \\ + ); +} + test "zig fmt: preserve same-line comment after a statement" { try testCanonical( \\test "" {