Commit 29e6541db1

Vexu <15308111+Vexu@users.noreply.github.com>
2019-09-25 17:15:50
add noasync to zig fmt
1 parent 3907e3b
Changed files (2)
std/zig/parse.zig
@@ -1096,16 +1096,19 @@ fn parseErrorUnionExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No
 
 /// SuffixExpr
 ///     <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments
+///      / KEYWORD_noasync PrimaryTypeExpr SuffixOp* FnCallArguments
 ///      / PrimaryTypeExpr (SuffixOp / FnCallArguments)*
 fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
-    if (eatToken(it, .Keyword_async)) |async_token| {
-        if (eatToken(it, .Keyword_fn)) |token_fn| {
+    var maybe_async = eatAnnotatedToken(it, .Keyword_async) orelse eatAnnotatedToken(it, .Keyword_noasync);
+    if (maybe_async) |async_token| {
+        const token_fn = eatToken(it, .Keyword_fn);
+        if (async_token.ptr.id == .Keyword_async and token_fn != null) {
             // HACK: If we see the keyword `fn`, then we assume that
             //       we are parsing an async fn proto, and not a call.
             //       We therefore put back all tokens consumed by the async
             //       prefix...
-            putBackToken(it, token_fn);
-            putBackToken(it, async_token);
+            putBackToken(it, token_fn.?);
+            putBackToken(it, async_token.index);
             return parsePrimaryTypeExpr(arena, it, tree);
         }
         // 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 {
             .op = Node.SuffixOp.Op{
                 .Call = Node.SuffixOp.Op.Call{
                     .params = params.list,
-                    .async_token = async_token,
+                    .async_token = async_token.index,
                 },
             },
             .rtoken = params.rparen,
std/zig/parser_test.zig
@@ -2266,6 +2266,13 @@ test "zig fmt: async functions" {
     );
 }
 
+test "zig fmt: noasync" {
+    try testCanonical(
+        \\const a = noasync foo();
+        \\
+    );
+}
+
 test "zig fmt: Block after if" {
     try testCanonical(
         \\test "Block after if" {