From d3f628907a6b9e5b863c9d5235e6dadf57f42ca2 Mon Sep 17 00:00:00 2001 From: kristopher tate Date: Sun, 29 Jul 2018 17:11:43 +0900 Subject: [PATCH] src/parser.cpp: remove promise_symbol from suspend; Tracking Issue #1296 ; --- src/parser.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/parser.cpp b/src/parser.cpp index a93d8de83..e2a818a56 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -648,35 +648,37 @@ static AstNode *ast_parse_asm_expr(ParseContext *pc, size_t *token_index, bool m } /* -SuspendExpression(body) = "suspend" option(("|" Symbol "|" body)) +SuspendExpression(body) = "suspend" option( body ) */ static AstNode *ast_parse_suspend_block(ParseContext *pc, size_t *token_index, bool mandatory) { size_t orig_token_index = *token_index; + Token *token = &pc->tokens->at(*token_index); + Token *suspend_token = nullptr; - Token *suspend_token = &pc->tokens->at(*token_index); if (suspend_token->id == TokenIdKeywordSuspend) { *token_index += 1; + suspend_token = token; + token = &pc->tokens->at(*token_index); } else if (mandatory) { - ast_expect_token(pc, suspend_token, TokenIdKeywordSuspend); + ast_expect_token(pc, token, TokenIdKeywordSuspend); zig_unreachable(); } else { return nullptr; } - Token *bar_token = &pc->tokens->at(*token_index); - if (bar_token->id == TokenIdBinOr) { - *token_index += 1; - } else if (mandatory) { - ast_expect_token(pc, suspend_token, TokenIdBinOr); - zig_unreachable(); - } else { - *token_index = orig_token_index; - return nullptr; + //guessing that semicolon is checked elsewhere? + if (token->id != TokenIdLBrace) { + if (mandatory) { + ast_expect_token(pc, token, TokenIdLBrace); + zig_unreachable(); + } else { + *token_index = orig_token_index; + return nullptr; + } } + //Expect that we have a block; AstNode *node = ast_create_node(pc, NodeTypeSuspend, suspend_token); - node->data.suspend.promise_symbol = ast_parse_symbol(pc, token_index); - ast_eat_token(pc, token_index, TokenIdBinOr); node->data.suspend.block = ast_parse_block(pc, token_index, true); return node; @@ -3134,7 +3136,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont visit_field(&node->data.await_expr.expr, visit, context); break; case NodeTypeSuspend: - visit_field(&node->data.suspend.promise_symbol, visit, context); visit_field(&node->data.suspend.block, visit, context); break; }