| author | |
| committer | |
| log | eabf378a56e0cd9720f43c36b85025228c4406d8 |
| tree | af80f2749253cc4f5c61c14c9f37519dc9146ab8 |
| parent | 0aede1a8fcd59b259215c05b43827405ad5da9c7 |
3 files changed, 43 insertions(+), 3 deletions(-)
lib/std/zig/parse.zig+8-2| ... | ... | @@ -891,11 +891,17 @@ const Parser = struct { |
| 891 | 891 | }); |
| 892 | 892 | }, |
| 893 | 893 | .keyword_suspend => { |
| 894 | const token = p.nextToken(); | |
| 895 | // TODO remove this special case when 0.9.0 is released. | |
| 896 | const block_expr: Node.Index = if (p.eatToken(.semicolon) != null) | |
| 897 | 0 | |
| 898 | else | |
| 899 | try p.expectBlockExprStatement(); | |
| 894 | 900 | return p.addNode(.{ |
| 895 | 901 | .tag = .@"suspend", |
| 896 | .main_token = p.nextToken(), | |
| 902 | .main_token = token, | |
| 897 | 903 | .data = .{ |
| 898 | .lhs = try p.expectBlockExprStatement(), | |
| 904 | .lhs = block_expr, | |
| 899 | 905 | .rhs = undefined, |
| 900 | 906 | }, |
| 901 | 907 | }); |
lib/std/zig/parser_test.zig+18| ... | ... | @@ -40,6 +40,21 @@ test "zig fmt: rewrite inline functions as callconv(.Inline)" { |
| 40 | 40 | ); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | // TODO Remove this after zig 0.9.0 is released. | |
| 44 | test "zig fmt: rewrite suspend without block expression" { | |
| 45 | try testTransform( | |
| 46 | \\fn foo() void { | |
| 47 | \\ suspend; | |
| 48 | \\} | |
| 49 | \\ | |
| 50 | , | |
| 51 | \\fn foo() void { | |
| 52 | \\ suspend {} | |
| 53 | \\} | |
| 54 | \\ | |
| 55 | ); | |
| 56 | } | |
| 57 | ||
| 43 | 58 | test "zig fmt: simple top level comptime block" { |
| 44 | 59 | try testCanonical( |
| 45 | 60 | \\// line comment |
| ... | ... | @@ -5023,6 +5038,9 @@ test "recovery: invalid comptime" { |
| 5023 | 5038 | } |
| 5024 | 5039 | |
| 5025 | 5040 | test "recovery: missing block after suspend" { |
| 5041 | // TODO Enable this after zig 0.9.0 is released. | |
| 5042 | if (true) return error.SkipZigTest; | |
| 5043 | ||
| 5026 | 5044 | try testError( |
| 5027 | 5045 | \\fn foo() void { |
| 5028 | 5046 | \\ suspend; |
lib/std/zig/render.zig+17-1| ... | ... | @@ -255,13 +255,29 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I |
| 255 | 255 | try renderToken(ais, tree, defer_token, .space); |
| 256 | 256 | return renderExpression(gpa, ais, tree, expr, space); |
| 257 | 257 | }, |
| 258 | .@"comptime", .@"suspend", .@"nosuspend" => { | |
| 258 | .@"comptime", .@"nosuspend" => { | |
| 259 | 259 | const comptime_token = main_tokens[node]; |
| 260 | 260 | const block = datas[node].lhs; |
| 261 | 261 | try renderToken(ais, tree, comptime_token, .space); |
| 262 | 262 | return renderExpression(gpa, ais, tree, block, space); |
| 263 | 263 | }, |
| 264 | 264 | |
| 265 | .@"suspend" => { | |
| 266 | const suspend_token = main_tokens[node]; | |
| 267 | const body = datas[node].lhs; | |
| 268 | if (body != 0) { | |
| 269 | try renderToken(ais, tree, suspend_token, .space); | |
| 270 | return renderExpression(gpa, ais, tree, body, space); | |
| 271 | } else { | |
| 272 | // TODO remove this special case when 0.9.0 is released. | |
| 273 | assert(space == .semicolon); | |
| 274 | try renderToken(ais, tree, suspend_token, .space); | |
| 275 | try ais.writer().writeAll("{}"); | |
| 276 | try ais.insertNewline(); | |
| 277 | return; | |
| 278 | } | |
| 279 | }, | |
| 280 | ||
| 265 | 281 | .@"catch" => { |
| 266 | 282 | const main_token = main_tokens[node]; |
| 267 | 283 | const fallback_first = tree.firstToken(datas[node].rhs); |