authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-04-30 17:30:57-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-04-30 17:30:57-04:00
log7dc8d433abbf697f05eb1ad2003b6335f750557b
tree22ddf5420466c8c3a5f6ae4e8b02490ce92c5404
parent37d3ef28351027a83249080d3238d61d9346f6db

zig fmt: support labeled suspend


3 files changed, 34 insertions(+), 0 deletions(-)

std/zig/ast.zig+2
......@@ -1371,6 +1371,7 @@ pub const Node = struct {
13711371
13721372 pub const Suspend = struct {
13731373 base: Node,
1374 label: ?Token,
13741375 suspend_token: Token,
13751376 payload: ?&Node,
13761377 body: ?&Node,
......@@ -1392,6 +1393,7 @@ pub const Node = struct {
13921393 }
13931394
13941395 pub fn firstToken(self: &Suspend) Token {
1396 if (self.label) |label| return label;
13951397 return self.suspend_token;
13961398 }
13971399
std/zig/parser.zig+21
......@@ -1093,6 +1093,23 @@ pub const Parser = struct {
10931093 }) catch unreachable;
10941094 continue;
10951095 },
1096 Token.Id.Keyword_suspend => {
1097 const node = try arena.construct(ast.Node.Suspend {
1098 .base = ast.Node {
1099 .id = ast.Node.Id.Suspend,
1100 .doc_comments = null,
1101 .same_line_comment = null,
1102 },
1103 .label = ctx.label,
1104 .suspend_token = token,
1105 .payload = null,
1106 .body = null,
1107 });
1108 ctx.opt_ctx.store(&node.base);
1109 stack.append(State { .SuspendBody = node }) catch unreachable;
1110 try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } });
1111 continue;
1112 },
10961113 Token.Id.Keyword_inline => {
10971114 stack.append(State {
10981115 .Inline = InlineCtx {
......@@ -3046,6 +3063,7 @@ pub const Parser = struct {
30463063 const node = try self.createToCtxNode(arena, ctx, ast.Node.Suspend,
30473064 ast.Node.Suspend {
30483065 .base = undefined,
3066 .label = null,
30493067 .suspend_token = *token,
30503068 .payload = null,
30513069 .body = null,
......@@ -3655,6 +3673,9 @@ pub const Parser = struct {
36553673 },
36563674 ast.Node.Id.Suspend => {
36573675 const suspend_node = @fieldParentPtr(ast.Node.Suspend, "base", base);
3676 if (suspend_node.label) |label| {
3677 try stream.print("{}: ", self.tokenizer.getTokenSlice(label));
3678 }
36583679 try stream.print("{}", self.tokenizer.getTokenSlice(suspend_node.suspend_token));
36593680
36603681 if (suspend_node.body) |body| {
std/zig/parser_test.zig+11
......@@ -1,3 +1,14 @@
1test "zig fmt: labeled suspend" {
2 try testCanonical(
3 \\fn foo() void {
4 \\ s: suspend |p| {
5 \\ break :s;
6 \\ }
7 \\}
8 \\
9 );
10}
11
112test "zig fmt: comments before error set decl" {
213 try testCanonical(
314 \\const UnexpectedError = error {