| author | |
| committer | |
| log | 4cc1008c2d2b438b9847944898ad2d7cfbbdab8b |
| tree | 28ae3a1c5ad85493392f9999f8bf642056641e50 |
| parent | 3e61c45f8936f6211ae9b61b2b0358c560344f7b |
2 files changed, 50 insertions(+), 17 deletions(-)
std/zig/parser.zig+18-3| ... | ... | @@ -4110,14 +4110,30 @@ pub const Parser = struct { |
| 4110 | 4110 | }, |
| 4111 | 4111 | ast.Node.Id.ErrorSetDecl => { |
| 4112 | 4112 | const err_set_decl = @fieldParentPtr(ast.Node.ErrorSetDecl, "base", base); |
| 4113 | try stream.print("error "); | |
| 4113 | ||
| 4114 | const decls = err_set_decl.decls.toSliceConst(); | |
| 4115 | if (decls.len == 0) { | |
| 4116 | try stream.write("error{}"); | |
| 4117 | continue; | |
| 4118 | } | |
| 4119 | ||
| 4120 | if (decls.len == 1) blk: { | |
| 4121 | const node = decls[0]; | |
| 4122 | if (node.same_line_comment != null or node.doc_comments != null) break :blk; | |
| 4123 | ||
| 4124 | try stream.write("error{"); | |
| 4125 | try stack.append(RenderState { .Text = "}" }); | |
| 4126 | try stack.append(RenderState { .Expression = node }); | |
| 4127 | continue; | |
| 4128 | } | |
| 4129 | ||
| 4130 | try stream.write("error{"); | |
| 4114 | 4131 | |
| 4115 | 4132 | try stack.append(RenderState { .Text = "}"}); |
| 4116 | 4133 | try stack.append(RenderState.PrintIndent); |
| 4117 | 4134 | try stack.append(RenderState { .Indent = indent }); |
| 4118 | 4135 | try stack.append(RenderState { .Text = "\n"}); |
| 4119 | 4136 | |
| 4120 | const decls = err_set_decl.decls.toSliceConst(); | |
| 4121 | 4137 | var i = decls.len; |
| 4122 | 4138 | while (i != 0) { |
| 4123 | 4139 | i -= 1; |
| ... | ... | @@ -4142,7 +4158,6 @@ pub const Parser = struct { |
| 4142 | 4158 | }); |
| 4143 | 4159 | } |
| 4144 | 4160 | try stack.append(RenderState { .Indent = indent + indent_delta}); |
| 4145 | try stack.append(RenderState { .Text = "{"}); | |
| 4146 | 4161 | }, |
| 4147 | 4162 | ast.Node.Id.MultilineStringLiteral => { |
| 4148 | 4163 | const multiline_str_literal = @fieldParentPtr(ast.Node.MultilineStringLiteral, "base", base); |
std/zig/parser_test.zig+32-14| ... | ... | @@ -1,5 +1,35 @@ |
| 1 | test "zig fmt: union(enum(u32)) with assigned enum values" { | |
| 1 | test "zig fmt: error set declaration" { | |
| 2 | 2 | try testCanonical( |
| 3 | \\const E = error{ | |
| 4 | \\ A, | |
| 5 | \\ B, | |
| 6 | \\ | |
| 7 | \\ C, | |
| 8 | \\}; | |
| 9 | \\ | |
| 10 | \\const Error = error{ | |
| 11 | \\ /// no more memory | |
| 12 | \\ OutOfMemory, | |
| 13 | \\}; | |
| 14 | \\ | |
| 15 | \\const Error = error{ | |
| 16 | \\ /// no more memory | |
| 17 | \\ OutOfMemory, | |
| 18 | \\ | |
| 19 | \\ /// another | |
| 20 | \\ Another, | |
| 21 | \\ | |
| 22 | \\ // end | |
| 23 | \\}; | |
| 24 | \\ | |
| 25 | \\const Error = error{OutOfMemory}; | |
| 26 | \\const Error = error{}; | |
| 27 | \\ | |
| 28 | ); | |
| 29 | } | |
| 30 | ||
| 31 | test "zig fmt: union(enum(u32)) with assigned enum values" { | |
| 32 | try testCanonical( | |
| 3 | 33 | \\const MultipleChoice = union(enum(u32)) { |
| 4 | 34 | \\ A = 20, |
| 5 | 35 | \\ B = 40, |
| ... | ... | @@ -23,7 +53,7 @@ test "zig fmt: labeled suspend" { |
| 23 | 53 | |
| 24 | 54 | test "zig fmt: comments before error set decl" { |
| 25 | 55 | try testCanonical( |
| 26 | \\const UnexpectedError = error { | |
| 56 | \\const UnexpectedError = error{ | |
| 27 | 57 | \\ /// The Operating System returned an undocumented error code. |
| 28 | 58 | \\ Unexpected, |
| 29 | 59 | \\ // another |
| ... | ... | @@ -601,18 +631,6 @@ test "zig fmt: union declaration" { |
| 601 | 631 | ); |
| 602 | 632 | } |
| 603 | 633 | |
| 604 | test "zig fmt: error set declaration" { | |
| 605 | try testCanonical( | |
| 606 | \\const E = error { | |
| 607 | \\ A, | |
| 608 | \\ B, | |
| 609 | \\ | |
| 610 | \\ C, | |
| 611 | \\}; | |
| 612 | \\ | |
| 613 | ); | |
| 614 | } | |
| 615 | ||
| 616 | 634 | test "zig fmt: arrays" { |
| 617 | 635 | try testCanonical( |
| 618 | 636 | \\test "test array" { |