| 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,7 +459,6 @@ pub const Tree = struct { |
| 459 | .Try, | 459 | .Try, |
| 460 | .Await, | 460 | .Await, |
| 461 | .OptionalType, | 461 | .OptionalType, |
| 462 | .Suspend, | ||
| 463 | .Resume, | 462 | .Resume, |
| 464 | .Nosuspend, | 463 | .Nosuspend, |
| 465 | .Comptime, | 464 | .Comptime, |
| ... | @@ -625,7 +624,6 @@ pub const Tree = struct { | ... | @@ -625,7 +624,6 @@ pub const Tree = struct { |
| 625 | }, | 624 | }, |
| 626 | 625 | ||
| 627 | .ArrayInitDotTwo, | 626 | .ArrayInitDotTwo, |
| 628 | .BuiltinCallTwo, | ||
| 629 | .BlockTwo, | 627 | .BlockTwo, |
| 630 | .StructInitDotTwo, | 628 | .StructInitDotTwo, |
| 631 | .ContainerDeclTwo, | 629 | .ContainerDeclTwo, |
| ... | @@ -640,6 +638,18 @@ pub const Tree = struct { | ... | @@ -640,6 +638,18 @@ pub const Tree = struct { |
| 640 | return main_tokens[n] + end_offset; | 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 | .ArrayInitDotTwoComma, | 653 | .ArrayInitDotTwoComma, |
| 644 | .BuiltinCallTwoComma, | 654 | .BuiltinCallTwoComma, |
| 645 | .BlockTwoSemicolon, | 655 | .BlockTwoSemicolon, |
| ... | @@ -861,6 +871,13 @@ pub const Tree = struct { | ... | @@ -861,6 +871,13 @@ pub const Tree = struct { |
| 861 | assert(extra.else_expr != 0); | 871 | assert(extra.else_expr != 0); |
| 862 | n = extra.else_expr; | 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 | // These are not supported by lastToken() because implementation would | 882 | // These are not supported by lastToken() because implementation would |
| 866 | // require recursion due to the optional comma followed by rbrace. | 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,18 +2124,18 @@ test "zig fmt: error set declaration" { |
| 2124 | // \\ | 2124 | // \\ |
| 2125 | // ); | 2125 | // ); |
| 2126 | //} | 2126 | //} |
| 2127 | // | 2127 | |
| 2128 | //test "zig fmt: resume from suspend block" { | 2128 | test "zig fmt: resume from suspend block" { |
| 2129 | // try testCanonical( | 2129 | try testCanonical( |
| 2130 | // \\fn foo() void { | 2130 | \\fn foo() void { |
| 2131 | // \\ suspend { | 2131 | \\ suspend { |
| 2132 | // \\ resume @frame(); | 2132 | \\ resume @frame(); |
| 2133 | // \\ } | 2133 | \\ } |
| 2134 | // \\} | 2134 | \\} |
| 2135 | // \\ | 2135 | \\ |
| 2136 | // ); | 2136 | ); |
| 2137 | //} | 2137 | } |
| 2138 | // | 2138 | |
| 2139 | //test "zig fmt: comments before error set decl" { | 2139 | //test "zig fmt: comments before error set decl" { |
| 2140 | // try testCanonical( | 2140 | // try testCanonical( |
| 2141 | // \\const UnexpectedError = error{ | 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,17 +238,16 @@ fn renderExpression(ais: *Ais, tree: ast.Tree, node: ast.Node.Index, space: Spac |
| 238 | return renderExpression(ais, tree, block, space); | 238 | return renderExpression(ais, tree, block, space); |
| 239 | }, | 239 | }, |
| 240 | 240 | ||
| 241 | .Suspend => unreachable, // TODO | 241 | .Suspend => { |
| 242 | //.Suspend => { | 242 | const suspend_token = main_tokens[node]; |
| 243 | // const suspend_node = @fieldParentPtr(ast.Node.Suspend, "base", base); | 243 | const body = datas[node].lhs; |
| 244 | 244 | if (body != 0) { | |
| 245 | // if (suspend_node.body) |body| { | 245 | try renderToken(ais, tree, suspend_token, .Space); |
| 246 | // try renderToken(ais, tree, suspend_node.suspend_token, Space.Space); | 246 | return renderExpression(ais, tree, body, space); |
| 247 | // return renderExpression(ais, tree, body, space); | 247 | } else { |
| 248 | // } else { | 248 | return renderToken(ais, tree, suspend_token, space); |
| 249 | // return renderToken(ais, tree, suspend_node.suspend_token, space); | 249 | } |
| 250 | // } | 250 | }, |
| 251 | //}, | ||
| 252 | 251 | ||
| 253 | .Catch => { | 252 | .Catch => { |
| 254 | const main_token = main_tokens[node]; | 253 | const main_token = main_tokens[node]; |