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 {...@@ -3758,6 +3758,14 @@ pub const Parser = struct {
3758 while (i != 0) {3758 while (i != 0) {
3759 i -= 1;3759 i -= 1;
3760 const node = fields_and_decls[i];3760 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 }
3761 try stack.append(RenderState { .TopLevelDecl = node});3769 try stack.append(RenderState { .TopLevelDecl = node});
3762 try stack.append(RenderState.PrintIndent);3770 try stack.append(RenderState.PrintIndent);
3763 try stack.append(RenderState {3771 try stack.append(RenderState {
...@@ -3772,18 +3780,6 @@ pub const Parser = struct {...@@ -3772,18 +3780,6 @@ pub const Parser = struct {
3772 break :blk "\n";3780 break :blk "\n";
3773 },3781 },
3774 });3782 });
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 }
3787 }3783 }
3788 try stack.append(RenderState { .Indent = indent + indent_delta});3784 try stack.append(RenderState { .Indent = indent + indent_delta});
3789 try stack.append(RenderState { .Text = "{"});3785 try stack.append(RenderState { .Text = "{"});
...@@ -3812,6 +3808,7 @@ pub const Parser = struct {...@@ -3812,6 +3808,7 @@ pub const Parser = struct {
3812 while (i != 0) {3808 while (i != 0) {
3813 i -= 1;3809 i -= 1;
3814 const node = decls[i];3810 const node = decls[i];
3811 try stack.append(RenderState { .Text = "," });
3815 try stack.append(RenderState { .Expression = &node.base});3812 try stack.append(RenderState { .Expression = &node.base});
3816 try stack.append(RenderState.PrintIndent);3813 try stack.append(RenderState.PrintIndent);
3817 try stack.append(RenderState {3814 try stack.append(RenderState {
...@@ -3826,10 +3823,6 @@ pub const Parser = struct {...@@ -3826,10 +3823,6 @@ pub const Parser = struct {
3826 break :blk "\n";3823 break :blk "\n";
3827 },3824 },
3828 });3825 });
3829
3830 if (i != 0) {
3831 try stack.append(RenderState { .Text = "," });
3832 }
3833 }3826 }
3834 try stack.append(RenderState { .Indent = indent + indent_delta});3827 try stack.append(RenderState { .Indent = indent + indent_delta});
3835 try stack.append(RenderState { .Text = "{"});3828 try stack.append(RenderState { .Text = "{"});
...@@ -3942,6 +3935,7 @@ pub const Parser = struct {...@@ -3942,6 +3935,7 @@ pub const Parser = struct {
3942 while (i != 0) {3935 while (i != 0) {
3943 i -= 1;3936 i -= 1;
3944 const node = cases[i];3937 const node = cases[i];
3938 try stack.append(RenderState { .Text = ","});
3945 try stack.append(RenderState { .Expression = &node.base});3939 try stack.append(RenderState { .Expression = &node.base});
3946 try stack.append(RenderState.PrintIndent);3940 try stack.append(RenderState.PrintIndent);
3947 try stack.append(RenderState {3941 try stack.append(RenderState {
...@@ -3956,10 +3950,6 @@ pub const Parser = struct {...@@ -3956,10 +3950,6 @@ pub const Parser = struct {
3956 break :blk "\n";3950 break :blk "\n";
3957 },3951 },
3958 });3952 });
3959
3960 if (i != 0) {
3961 try stack.append(RenderState { .Text = "," });
3962 }
3963 }3953 }
3964 try stack.append(RenderState { .Indent = indent + indent_delta});3954 try stack.append(RenderState { .Indent = indent + indent_delta});
3965 try stack.append(RenderState { .Text = ") {"});3955 try stack.append(RenderState { .Text = ") {"});
...@@ -4714,21 +4704,21 @@ test "zig fmt: struct declaration" {...@@ -4714,21 +4704,21 @@ test "zig fmt: struct declaration" {
4714 \\ return *self;4704 \\ return *self;
4715 \\ }4705 \\ }
4716 \\4706 \\
4717 \\ f2: u84707 \\ f2: u8,
4718 \\};4708 \\};
4719 \\4709 \\
4720 \\const Ps = packed struct {4710 \\const Ps = packed struct {
4721 \\ a: u8,4711 \\ a: u8,
4722 \\ pub b: u8,4712 \\ pub b: u8,
4723 \\4713 \\
4724 \\ c: u84714 \\ c: u8,
4725 \\};4715 \\};
4726 \\4716 \\
4727 \\const Es = extern struct {4717 \\const Es = extern struct {
4728 \\ a: u8,4718 \\ a: u8,
4729 \\ pub b: u8,4719 \\ pub b: u8,
4730 \\4720 \\
4731 \\ c: u84721 \\ c: u8,
4732 \\};4722 \\};
4733 \\4723 \\
4734 );4724 );
...@@ -4738,25 +4728,25 @@ test "zig fmt: enum declaration" {...@@ -4738,25 +4728,25 @@ test "zig fmt: enum declaration" {
4738 try testCanonical(4728 try testCanonical(
4739 \\const E = enum {4729 \\const E = enum {
4740 \\ Ok,4730 \\ Ok,
4741 \\ SomethingElse = 04731 \\ SomethingElse = 0,
4742 \\};4732 \\};
4743 \\4733 \\
4744 \\const E2 = enum(u8) {4734 \\const E2 = enum(u8) {
4745 \\ Ok,4735 \\ Ok,
4746 \\ SomethingElse = 255,4736 \\ SomethingElse = 255,
4747 \\ SomethingThird4737 \\ SomethingThird,
4748 \\};4738 \\};
4749 \\4739 \\
4750 \\const Ee = extern enum {4740 \\const Ee = extern enum {
4751 \\ Ok,4741 \\ Ok,
4752 \\ SomethingElse,4742 \\ SomethingElse,
4753 \\ SomethingThird4743 \\ SomethingThird,
4754 \\};4744 \\};
4755 \\4745 \\
4756 \\const Ep = packed enum {4746 \\const Ep = packed enum {
4757 \\ Ok,4747 \\ Ok,
4758 \\ SomethingElse,4748 \\ SomethingElse,
4759 \\ SomethingThird4749 \\ SomethingThird,
4760 \\};4750 \\};
4761 \\4751 \\
4762 );4752 );
...@@ -4768,35 +4758,35 @@ test "zig fmt: union declaration" {...@@ -4768,35 +4758,35 @@ test "zig fmt: union declaration" {
4768 \\ Int: u8,4758 \\ Int: u8,
4769 \\ Float: f32,4759 \\ Float: f32,
4770 \\ None,4760 \\ None,
4771 \\ Bool: bool4761 \\ Bool: bool,
4772 \\};4762 \\};
4773 \\4763 \\
4774 \\const Ue = union(enum) {4764 \\const Ue = union(enum) {
4775 \\ Int: u8,4765 \\ Int: u8,
4776 \\ Float: f32,4766 \\ Float: f32,
4777 \\ None,4767 \\ None,
4778 \\ Bool: bool4768 \\ Bool: bool,
4779 \\};4769 \\};
4780 \\4770 \\
4781 \\const E = enum {4771 \\const E = enum {
4782 \\ Int,4772 \\ Int,
4783 \\ Float,4773 \\ Float,
4784 \\ None,4774 \\ None,
4785 \\ Bool4775 \\ Bool,
4786 \\};4776 \\};
4787 \\4777 \\
4788 \\const Ue2 = union(E) {4778 \\const Ue2 = union(E) {
4789 \\ Int: u8,4779 \\ Int: u8,
4790 \\ Float: f32,4780 \\ Float: f32,
4791 \\ None,4781 \\ None,
4792 \\ Bool: bool4782 \\ Bool: bool,
4793 \\};4783 \\};
4794 \\4784 \\
4795 \\const Eu = extern union {4785 \\const Eu = extern union {
4796 \\ Int: u8,4786 \\ Int: u8,
4797 \\ Float: f32,4787 \\ Float: f32,
4798 \\ None,4788 \\ None,
4799 \\ Bool: bool4789 \\ Bool: bool,
4800 \\};4790 \\};
4801 \\4791 \\
4802 );4792 );
...@@ -4808,7 +4798,7 @@ test "zig fmt: error set declaration" {...@@ -4808,7 +4798,7 @@ test "zig fmt: error set declaration" {
4808 \\ A,4798 \\ A,
4809 \\ B,4799 \\ B,
4810 \\4800 \\
4811 \\ C4801 \\ C,
4812 \\};4802 \\};
4813 \\4803 \\
4814 );4804 );
...@@ -4894,19 +4884,19 @@ test "zig fmt: switch" {...@@ -4894,19 +4884,19 @@ test "zig fmt: switch" {
4894 \\ else => {4884 \\ else => {
4895 \\ const a = 1;4885 \\ const a = 1;
4896 \\ const b = a;4886 \\ const b = a;
4897 \\ }4887 \\ },
4898 \\ }4888 \\ }
4899 \\4889 \\
4900 \\ const res = switch (0) {4890 \\ const res = switch (0) {
4901 \\ 0 => 0,4891 \\ 0 => 0,
4902 \\ 1 => 2,4892 \\ 1 => 2,
4903 \\ 1 => a = 4,4893 \\ 1 => a = 4,
4904 \\ else => 44894 \\ else => 4,
4905 \\ };4895 \\ };
4906 \\4896 \\
4907 \\ const Union = union(enum) {4897 \\ const Union = union(enum) {
4908 \\ Int: i64,4898 \\ Int: i64,
4909 \\ Float: f644899 \\ Float: f64,
4910 \\ };4900 \\ };
4911 \\4901 \\
4912 \\ const u = Union {4902 \\ const u = Union {
...@@ -4914,7 +4904,7 @@ test "zig fmt: switch" {...@@ -4914,7 +4904,7 @@ test "zig fmt: switch" {
4914 \\ };4904 \\ };
4915 \\ switch (u) {4905 \\ switch (u) {
4916 \\ Union.Int => |int| {},4906 \\ Union.Int => |int| {},
4917 \\ Union.Float => |*float| unreachable4907 \\ Union.Float => |*float| unreachable,
4918 \\ }4908 \\ }
4919 \\}4909 \\}
4920 \\4910 \\