Commit 7295d4b807
Changed files (3)
lib
lib/std/zig/ast.zig
@@ -459,7 +459,6 @@ pub const Tree = struct {
.Try,
.Await,
.OptionalType,
- .Suspend,
.Resume,
.Nosuspend,
.Comptime,
@@ -625,7 +624,6 @@ pub const Tree = struct {
},
.ArrayInitDotTwo,
- .BuiltinCallTwo,
.BlockTwo,
.StructInitDotTwo,
.ContainerDeclTwo,
@@ -640,6 +638,18 @@ pub const Tree = struct {
return main_tokens[n] + end_offset;
}
},
+ .BuiltinCallTwo => {
+ if (datas[n].rhs != 0) {
+ end_offset += 1; // for the rparen/rbrace
+ n = datas[n].rhs;
+ } else if (datas[n].lhs != 0) {
+ end_offset += 1; // for the rparen/rbrace
+ n = datas[n].lhs;
+ } else {
+ end_offset += 2; // for the lparen and rparen
+ return main_tokens[n] + end_offset;
+ }
+ },
.ArrayInitDotTwoComma,
.BuiltinCallTwoComma,
.BlockTwoSemicolon,
@@ -861,6 +871,13 @@ pub const Tree = struct {
assert(extra.else_expr != 0);
n = extra.else_expr;
},
+ .Suspend => {
+ if (datas[n].lhs != 0) {
+ n = datas[n].lhs;
+ } else {
+ return main_tokens[n] + end_offset;
+ }
+ },
// These are not supported by lastToken() because implementation would
// require recursion due to the optional comma followed by rbrace.
lib/std/zig/parser_test.zig
@@ -2124,18 +2124,18 @@ test "zig fmt: error set declaration" {
// \\
// );
//}
-//
-//test "zig fmt: resume from suspend block" {
-// try testCanonical(
-// \\fn foo() void {
-// \\ suspend {
-// \\ resume @frame();
-// \\ }
-// \\}
-// \\
-// );
-//}
-//
+
+test "zig fmt: resume from suspend block" {
+ try testCanonical(
+ \\fn foo() void {
+ \\ suspend {
+ \\ resume @frame();
+ \\ }
+ \\}
+ \\
+ );
+}
+
//test "zig fmt: comments before error set decl" {
// try testCanonical(
// \\const UnexpectedError = error{
lib/std/zig/render.zig
@@ -238,17 +238,16 @@ fn renderExpression(ais: *Ais, tree: ast.Tree, node: ast.Node.Index, space: Spac
return renderExpression(ais, tree, block, space);
},
- .Suspend => unreachable, // TODO
- //.Suspend => {
- // const suspend_node = @fieldParentPtr(ast.Node.Suspend, "base", base);
-
- // if (suspend_node.body) |body| {
- // try renderToken(ais, tree, suspend_node.suspend_token, Space.Space);
- // return renderExpression(ais, tree, body, space);
- // } else {
- // return renderToken(ais, tree, suspend_node.suspend_token, space);
- // }
- //},
+ .Suspend => {
+ const suspend_token = main_tokens[node];
+ const body = datas[node].lhs;
+ if (body != 0) {
+ try renderToken(ais, tree, suspend_token, .Space);
+ return renderExpression(ais, tree, body, space);
+ } else {
+ return renderToken(ais, tree, suspend_token, space);
+ }
+ },
.Catch => {
const main_token = main_tokens[node];