diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-04-12 21:39:45 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-04-12 21:40:15 -0400 |
| commit | 9e701e951b637b5627a25d9530c074d2900d9362 (patch) | |
| tree | 9e2a57aea37da3905c7478d55a5ca675d2a9ed01 /std | |
| parent | d4572d1140bb22aaeb587a66d3eee7bbdf162b1c (diff) | |
| download | zig-9e701e951b637b5627a25d9530c074d2900d9362.tar.gz zig-9e701e951b637b5627a25d9530c074d2900d9362.zip | |
zig fmt includes trailing commas
See #911
Diffstat (limited to 'std')
| -rw-r--r-- | std/zig/parser.zig | 64 |
1 files changed, 27 insertions, 37 deletions
diff --git a/std/zig/parser.zig b/std/zig/parser.zig index 3ad408afc7..91623ba596 100644 --- a/std/zig/parser.zig +++ b/std/zig/parser.zig @@ -3758,6 +3758,14 @@ pub const Parser = struct { while (i != 0) { i -= 1; const node = fields_and_decls[i]; + switch (node.id) { + ast.Node.Id.StructField, + ast.Node.Id.UnionTag, + ast.Node.Id.EnumTag => { + try stack.append(RenderState { .Text = "," }); + }, + else => { } + } try stack.append(RenderState { .TopLevelDecl = node}); try stack.append(RenderState.PrintIndent); try stack.append(RenderState { @@ -3772,18 +3780,6 @@ pub const Parser = struct { break :blk "\n"; }, }); - - if (i != 0) { - const prev_node = fields_and_decls[i - 1]; - switch (prev_node.id) { - ast.Node.Id.StructField, - ast.Node.Id.UnionTag, - ast.Node.Id.EnumTag => { - try stack.append(RenderState { .Text = "," }); - }, - else => { } - } - } } try stack.append(RenderState { .Indent = indent + indent_delta}); try stack.append(RenderState { .Text = "{"}); @@ -3812,6 +3808,7 @@ pub const Parser = struct { while (i != 0) { i -= 1; const node = decls[i]; + try stack.append(RenderState { .Text = "," }); try stack.append(RenderState { .Expression = &node.base}); try stack.append(RenderState.PrintIndent); try stack.append(RenderState { @@ -3826,10 +3823,6 @@ pub const Parser = struct { break :blk "\n"; }, }); - - if (i != 0) { - try stack.append(RenderState { .Text = "," }); - } } try stack.append(RenderState { .Indent = indent + indent_delta}); try stack.append(RenderState { .Text = "{"}); @@ -3942,6 +3935,7 @@ pub const Parser = struct { while (i != 0) { i -= 1; const node = cases[i]; + try stack.append(RenderState { .Text = ","}); try stack.append(RenderState { .Expression = &node.base}); try stack.append(RenderState.PrintIndent); try stack.append(RenderState { @@ -3956,10 +3950,6 @@ pub const Parser = struct { break :blk "\n"; }, }); - - if (i != 0) { - try stack.append(RenderState { .Text = "," }); - } } try stack.append(RenderState { .Indent = indent + indent_delta}); try stack.append(RenderState { .Text = ") {"}); @@ -4714,21 +4704,21 @@ test "zig fmt: struct declaration" { \\ return *self; \\ } \\ - \\ f2: u8 + \\ f2: u8, \\}; \\ \\const Ps = packed struct { \\ a: u8, \\ pub b: u8, \\ - \\ c: u8 + \\ c: u8, \\}; \\ \\const Es = extern struct { \\ a: u8, \\ pub b: u8, \\ - \\ c: u8 + \\ c: u8, \\}; \\ ); @@ -4738,25 +4728,25 @@ test "zig fmt: enum declaration" { try testCanonical( \\const E = enum { \\ Ok, - \\ SomethingElse = 0 + \\ SomethingElse = 0, \\}; \\ \\const E2 = enum(u8) { \\ Ok, \\ SomethingElse = 255, - \\ SomethingThird + \\ SomethingThird, \\}; \\ \\const Ee = extern enum { \\ Ok, \\ SomethingElse, - \\ SomethingThird + \\ SomethingThird, \\}; \\ \\const Ep = packed enum { \\ Ok, \\ SomethingElse, - \\ SomethingThird + \\ SomethingThird, \\}; \\ ); @@ -4768,35 +4758,35 @@ test "zig fmt: union declaration" { \\ Int: u8, \\ Float: f32, \\ None, - \\ Bool: bool + \\ Bool: bool, \\}; \\ \\const Ue = union(enum) { \\ Int: u8, \\ Float: f32, \\ None, - \\ Bool: bool + \\ Bool: bool, \\}; \\ \\const E = enum { \\ Int, \\ Float, \\ None, - \\ Bool + \\ Bool, \\}; \\ \\const Ue2 = union(E) { \\ Int: u8, \\ Float: f32, \\ None, - \\ Bool: bool + \\ Bool: bool, \\}; \\ \\const Eu = extern union { \\ Int: u8, \\ Float: f32, \\ None, - \\ Bool: bool + \\ Bool: bool, \\}; \\ ); @@ -4808,7 +4798,7 @@ test "zig fmt: error set declaration" { \\ A, \\ B, \\ - \\ C + \\ C, \\}; \\ ); @@ -4894,19 +4884,19 @@ test "zig fmt: switch" { \\ else => { \\ const a = 1; \\ const b = a; - \\ } + \\ }, \\ } \\ \\ const res = switch (0) { \\ 0 => 0, \\ 1 => 2, \\ 1 => a = 4, - \\ else => 4 + \\ else => 4, \\ }; \\ \\ const Union = union(enum) { \\ Int: i64, - \\ Float: f64 + \\ Float: f64, \\ }; \\ \\ const u = Union { @@ -4914,7 +4904,7 @@ test "zig fmt: switch" { \\ }; \\ switch (u) { \\ Union.Int => |int| {}, - \\ Union.Float => |*float| unreachable + \\ Union.Float => |*float| unreachable, \\ } \\} \\ |
