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