authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-09-25 18:15:50+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-25 12:44:11-04:00
log29e6541db1ad79656a3a7743de65bd452ea64bce
tree58c54e757cbff429a3663fb73654d45396ed2db7
parent3907e3b675daaa9869732aca6851bd2e0000000a

add noasync to zig fmt


2 files changed, 15 insertions(+), 5 deletions(-)

std/zig/parse.zig+8-5
...@@ -1096,16 +1096,19 @@ fn parseErrorUnionExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No...@@ -1096,16 +1096,19 @@ fn parseErrorUnionExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No
10961096
1097/// SuffixExpr1097/// SuffixExpr
1098/// <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments1098/// <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments
1099/// / KEYWORD_noasync PrimaryTypeExpr SuffixOp* FnCallArguments
1099/// / PrimaryTypeExpr (SuffixOp / FnCallArguments)*1100/// / PrimaryTypeExpr (SuffixOp / FnCallArguments)*
1100fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {1101fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
1101 if (eatToken(it, .Keyword_async)) |async_token| {1102 var maybe_async = eatAnnotatedToken(it, .Keyword_async) orelse eatAnnotatedToken(it, .Keyword_noasync);
1102 if (eatToken(it, .Keyword_fn)) |token_fn| {1103 if (maybe_async) |async_token| {
1104 const token_fn = eatToken(it, .Keyword_fn);
1105 if (async_token.ptr.id == .Keyword_async and token_fn != null) {
1103 // HACK: If we see the keyword `fn`, then we assume that1106 // HACK: If we see the keyword `fn`, then we assume that
1104 // we are parsing an async fn proto, and not a call.1107 // we are parsing an async fn proto, and not a call.
1105 // We therefore put back all tokens consumed by the async1108 // We therefore put back all tokens consumed by the async
1106 // prefix...1109 // prefix...
1107 putBackToken(it, token_fn);1110 putBackToken(it, token_fn.?);
1108 putBackToken(it, async_token);1111 putBackToken(it, async_token.index);
1109 return parsePrimaryTypeExpr(arena, it, tree);1112 return parsePrimaryTypeExpr(arena, it, tree);
1110 }1113 }
1111 // TODO: Implement hack for parsing `async fn ...` in ast_parse_suffix_expr1114 // TODO: Implement hack for parsing `async fn ...` in ast_parse_suffix_expr
...@@ -1135,7 +1138,7 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {...@@ -1135,7 +1138,7 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
1135 .op = Node.SuffixOp.Op{1138 .op = Node.SuffixOp.Op{
1136 .Call = Node.SuffixOp.Op.Call{1139 .Call = Node.SuffixOp.Op.Call{
1137 .params = params.list,1140 .params = params.list,
1138 .async_token = async_token,1141 .async_token = async_token.index,
1139 },1142 },
1140 },1143 },
1141 .rtoken = params.rparen,1144 .rtoken = params.rparen,
std/zig/parser_test.zig+7
...@@ -2266,6 +2266,13 @@ test "zig fmt: async functions" {...@@ -2266,6 +2266,13 @@ test "zig fmt: async functions" {
2266 );2266 );
2267}2267}
22682268
2269test "zig fmt: noasync" {
2270 try testCanonical(
2271 \\const a = noasync foo();
2272 \\
2273 );
2274}
2275
2269test "zig fmt: Block after if" {2276test "zig fmt: Block after if" {
2270 try testCanonical(2277 try testCanonical(
2271 \\test "Block after if" {2278 \\test "Block after if" {