authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-04-12 21:39:45-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-04-12 21:40:15-04:00
log9e701e951b637b5627a25d9530c074d2900d9362
tree9e2a57aea37da3905c7478d55a5ca675d2a9ed01
parentd4572d1140bb22aaeb587a66d3eee7bbdf162b1c

zig fmt includes trailing commas

See #911

1 files changed, 27 insertions(+), 37 deletions(-)

std/zig/parser.zig+27-37
......@@ -3758,6 +3758,14 @@ pub const Parser = struct {
37583758 while (i != 0) {
37593759 i -= 1;
37603760 const node = fields_and_decls[i];
3761 switch (node.id) {
3762 ast.Node.Id.StructField,
3763 ast.Node.Id.UnionTag,
3764 ast.Node.Id.EnumTag => {
3765 try stack.append(RenderState { .Text = "," });
3766 },
3767 else => { }
3768 }
37613769 try stack.append(RenderState { .TopLevelDecl = node});
37623770 try stack.append(RenderState.PrintIndent);
37633771 try stack.append(RenderState {
......@@ -3772,18 +3780,6 @@ pub const Parser = struct {
37723780 break :blk "\n";
37733781 },
37743782 });
3775
3776 if (i != 0) {
3777 const prev_node = fields_and_decls[i - 1];
3778 switch (prev_node.id) {
3779 ast.Node.Id.StructField,
3780 ast.Node.Id.UnionTag,
3781 ast.Node.Id.EnumTag => {
3782 try stack.append(RenderState { .Text = "," });
3783 },
3784 else => { }
3785 }
3786 }
37873783 }
37883784 try stack.append(RenderState { .Indent = indent + indent_delta});
37893785 try stack.append(RenderState { .Text = "{"});
......@@ -3812,6 +3808,7 @@ pub const Parser = struct {
38123808 while (i != 0) {
38133809 i -= 1;
38143810 const node = decls[i];
3811 try stack.append(RenderState { .Text = "," });
38153812 try stack.append(RenderState { .Expression = &node.base});
38163813 try stack.append(RenderState.PrintIndent);
38173814 try stack.append(RenderState {
......@@ -3826,10 +3823,6 @@ pub const Parser = struct {
38263823 break :blk "\n";
38273824 },
38283825 });
3829
3830 if (i != 0) {
3831 try stack.append(RenderState { .Text = "," });
3832 }
38333826 }
38343827 try stack.append(RenderState { .Indent = indent + indent_delta});
38353828 try stack.append(RenderState { .Text = "{"});
......@@ -3942,6 +3935,7 @@ pub const Parser = struct {
39423935 while (i != 0) {
39433936 i -= 1;
39443937 const node = cases[i];
3938 try stack.append(RenderState { .Text = ","});
39453939 try stack.append(RenderState { .Expression = &node.base});
39463940 try stack.append(RenderState.PrintIndent);
39473941 try stack.append(RenderState {
......@@ -3956,10 +3950,6 @@ pub const Parser = struct {
39563950 break :blk "\n";
39573951 },
39583952 });
3959
3960 if (i != 0) {
3961 try stack.append(RenderState { .Text = "," });
3962 }
39633953 }
39643954 try stack.append(RenderState { .Indent = indent + indent_delta});
39653955 try stack.append(RenderState { .Text = ") {"});
......@@ -4714,21 +4704,21 @@ test "zig fmt: struct declaration" {
47144704 \\ return *self;
47154705 \\ }
47164706 \\
4717 \\ f2: u8
4707 \\ f2: u8,
47184708 \\};
47194709 \\
47204710 \\const Ps = packed struct {
47214711 \\ a: u8,
47224712 \\ pub b: u8,
47234713 \\
4724 \\ c: u8
4714 \\ c: u8,
47254715 \\};
47264716 \\
47274717 \\const Es = extern struct {
47284718 \\ a: u8,
47294719 \\ pub b: u8,
47304720 \\
4731 \\ c: u8
4721 \\ c: u8,
47324722 \\};
47334723 \\
47344724 );
......@@ -4738,25 +4728,25 @@ test "zig fmt: enum declaration" {
47384728 try testCanonical(
47394729 \\const E = enum {
47404730 \\ Ok,
4741 \\ SomethingElse = 0
4731 \\ SomethingElse = 0,
47424732 \\};
47434733 \\
47444734 \\const E2 = enum(u8) {
47454735 \\ Ok,
47464736 \\ SomethingElse = 255,
4747 \\ SomethingThird
4737 \\ SomethingThird,
47484738 \\};
47494739 \\
47504740 \\const Ee = extern enum {
47514741 \\ Ok,
47524742 \\ SomethingElse,
4753 \\ SomethingThird
4743 \\ SomethingThird,
47544744 \\};
47554745 \\
47564746 \\const Ep = packed enum {
47574747 \\ Ok,
47584748 \\ SomethingElse,
4759 \\ SomethingThird
4749 \\ SomethingThird,
47604750 \\};
47614751 \\
47624752 );
......@@ -4768,35 +4758,35 @@ test "zig fmt: union declaration" {
47684758 \\ Int: u8,
47694759 \\ Float: f32,
47704760 \\ None,
4771 \\ Bool: bool
4761 \\ Bool: bool,
47724762 \\};
47734763 \\
47744764 \\const Ue = union(enum) {
47754765 \\ Int: u8,
47764766 \\ Float: f32,
47774767 \\ None,
4778 \\ Bool: bool
4768 \\ Bool: bool,
47794769 \\};
47804770 \\
47814771 \\const E = enum {
47824772 \\ Int,
47834773 \\ Float,
47844774 \\ None,
4785 \\ Bool
4775 \\ Bool,
47864776 \\};
47874777 \\
47884778 \\const Ue2 = union(E) {
47894779 \\ Int: u8,
47904780 \\ Float: f32,
47914781 \\ None,
4792 \\ Bool: bool
4782 \\ Bool: bool,
47934783 \\};
47944784 \\
47954785 \\const Eu = extern union {
47964786 \\ Int: u8,
47974787 \\ Float: f32,
47984788 \\ None,
4799 \\ Bool: bool
4789 \\ Bool: bool,
48004790 \\};
48014791 \\
48024792 );
......@@ -4808,7 +4798,7 @@ test "zig fmt: error set declaration" {
48084798 \\ A,
48094799 \\ B,
48104800 \\
4811 \\ C
4801 \\ C,
48124802 \\};
48134803 \\
48144804 );
......@@ -4894,19 +4884,19 @@ test "zig fmt: switch" {
48944884 \\ else => {
48954885 \\ const a = 1;
48964886 \\ const b = a;
4897 \\ }
4887 \\ },
48984888 \\ }
48994889 \\
49004890 \\ const res = switch (0) {
49014891 \\ 0 => 0,
49024892 \\ 1 => 2,
49034893 \\ 1 => a = 4,
4904 \\ else => 4
4894 \\ else => 4,
49054895 \\ };
49064896 \\
49074897 \\ const Union = union(enum) {
49084898 \\ Int: i64,
4909 \\ Float: f64
4899 \\ Float: f64,
49104900 \\ };
49114901 \\
49124902 \\ const u = Union {
......@@ -4914,7 +4904,7 @@ test "zig fmt: switch" {
49144904 \\ };
49154905 \\ switch (u) {
49164906 \\ Union.Int => |int| {},
4917 \\ Union.Float => |*float| unreachable
4907 \\ Union.Float => |*float| unreachable,
49184908 \\ }
49194909 \\}
49204910 \\