| author | |
| committer | |
| log | 7295d4b8079b5cf3fcdbb81dd9e129f3f0f139aa |
| tree | ccf98069a75ba3b2b751ac745c6d759fddd5187e |
| parent | ebf04c56e12c8dd7cf503f042e698984704b14b2 |
3 files changed, 41 insertions(+), 25 deletions(-)
lib/std/zig/ast.zig+19-2| ... | ... | @@ -459,7 +459,6 @@ pub const Tree = struct { |
| 459 | 459 | .Try, |
| 460 | 460 | .Await, |
| 461 | 461 | .OptionalType, |
| 462 | .Suspend, | |
| 463 | 462 | .Resume, |
| 464 | 463 | .Nosuspend, |
| 465 | 464 | .Comptime, |
| ... | ... | @@ -625,7 +624,6 @@ pub const Tree = struct { |
| 625 | 624 | }, |
| 626 | 625 | |
| 627 | 626 | .ArrayInitDotTwo, |
| 628 | .BuiltinCallTwo, | |
| 629 | 627 | .BlockTwo, |
| 630 | 628 | .StructInitDotTwo, |
| 631 | 629 | .ContainerDeclTwo, |
| ... | ... | @@ -640,6 +638,18 @@ pub const Tree = struct { |
| 640 | 638 | return main_tokens[n] + end_offset; |
| 641 | 639 | } |
| 642 | 640 | }, |
| 641 | .BuiltinCallTwo => { | |
| 642 | if (datas[n].rhs != 0) { | |
| 643 | end_offset += 1; // for the rparen/rbrace | |
| 644 | n = datas[n].rhs; | |
| 645 | } else if (datas[n].lhs != 0) { | |
| 646 | end_offset += 1; // for the rparen/rbrace | |
| 647 | n = datas[n].lhs; | |
| 648 | } else { | |
| 649 | end_offset += 2; // for the lparen and rparen | |
| 650 | return main_tokens[n] + end_offset; | |
| 651 | } | |
| 652 | }, | |
| 643 | 653 | .ArrayInitDotTwoComma, |
| 644 | 654 | .BuiltinCallTwoComma, |
| 645 | 655 | .BlockTwoSemicolon, |
| ... | ... | @@ -861,6 +871,13 @@ pub const Tree = struct { |
| 861 | 871 | assert(extra.else_expr != 0); |
| 862 | 872 | n = extra.else_expr; |
| 863 | 873 | }, |
| 874 | .Suspend => { | |
| 875 | if (datas[n].lhs != 0) { | |
| 876 | n = datas[n].lhs; | |
| 877 | } else { | |
| 878 | return main_tokens[n] + end_offset; | |
| 879 | } | |
| 880 | }, | |
| 864 | 881 | |
| 865 | 882 | // These are not supported by lastToken() because implementation would |
| 866 | 883 | // require recursion due to the optional comma followed by rbrace. |
lib/std/zig/parser_test.zig+12-12| ... | ... | @@ -2124,18 +2124,18 @@ test "zig fmt: error set declaration" { |
| 2124 | 2124 | // \\ |
| 2125 | 2125 | // ); |
| 2126 | 2126 | //} |
| 2127 | // | |
| 2128 | //test "zig fmt: resume from suspend block" { | |
| 2129 | // try testCanonical( | |
| 2130 | // \\fn foo() void { | |
| 2131 | // \\ suspend { | |
| 2132 | // \\ resume @frame(); | |
| 2133 | // \\ } | |
| 2134 | // \\} | |
| 2135 | // \\ | |
| 2136 | // ); | |
| 2137 | //} | |
| 2138 | // | |
| 2127 | ||
| 2128 | test "zig fmt: resume from suspend block" { | |
| 2129 | try testCanonical( | |
| 2130 | \\fn foo() void { | |
| 2131 | \\ suspend { | |
| 2132 | \\ resume @frame(); | |
| 2133 | \\ } | |
| 2134 | \\} | |
| 2135 | \\ | |
| 2136 | ); | |
| 2137 | } | |
| 2138 | ||
| 2139 | 2139 | //test "zig fmt: comments before error set decl" { |
| 2140 | 2140 | // try testCanonical( |
| 2141 | 2141 | // \\const UnexpectedError = error{ |
lib/std/zig/render.zig+10-11| ... | ... | @@ -238,17 +238,16 @@ fn renderExpression(ais: *Ais, tree: ast.Tree, node: ast.Node.Index, space: Spac |
| 238 | 238 | return renderExpression(ais, tree, block, space); |
| 239 | 239 | }, |
| 240 | 240 | |
| 241 | .Suspend => unreachable, // TODO | |
| 242 | //.Suspend => { | |
| 243 | // const suspend_node = @fieldParentPtr(ast.Node.Suspend, "base", base); | |
| 244 | ||
| 245 | // if (suspend_node.body) |body| { | |
| 246 | // try renderToken(ais, tree, suspend_node.suspend_token, Space.Space); | |
| 247 | // return renderExpression(ais, tree, body, space); | |
| 248 | // } else { | |
| 249 | // return renderToken(ais, tree, suspend_node.suspend_token, space); | |
| 250 | // } | |
| 251 | //}, | |
| 241 | .Suspend => { | |
| 242 | const suspend_token = main_tokens[node]; | |
| 243 | const body = datas[node].lhs; | |
| 244 | if (body != 0) { | |
| 245 | try renderToken(ais, tree, suspend_token, .Space); | |
| 246 | return renderExpression(ais, tree, body, space); | |
| 247 | } else { | |
| 248 | return renderToken(ais, tree, suspend_token, space); | |
| 249 | } | |
| 250 | }, | |
| 252 | 251 | |
| 253 | 252 | .Catch => { |
| 254 | 253 | const main_token = main_tokens[node]; |