| ... | ... | @@ -648,35 +648,37 @@ static AstNode *ast_parse_asm_expr(ParseContext *pc, size_t *token_index, bool m |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | /* |
| 651 | | SuspendExpression(body) = "suspend" option(("|" Symbol "|" body)) |
| 651 | SuspendExpression(body) = "suspend" option( body ) |
| 652 | 652 | */ |
| 653 | 653 | static AstNode *ast_parse_suspend_block(ParseContext *pc, size_t *token_index, bool mandatory) { |
| 654 | 654 | size_t orig_token_index = *token_index; |
| 655 | Token *token = &pc->tokens->at(*token_index); |
| 656 | Token *suspend_token = nullptr; |
| 655 | 657 | |
| 656 | | Token *suspend_token = &pc->tokens->at(*token_index); |
| 657 | 658 | if (suspend_token->id == TokenIdKeywordSuspend) { |
| 658 | 659 | *token_index += 1; |
| 660 | suspend_token = token; |
| 661 | token = &pc->tokens->at(*token_index); |
| 659 | 662 | } else if (mandatory) { |
| 660 | | ast_expect_token(pc, suspend_token, TokenIdKeywordSuspend); |
| 663 | ast_expect_token(pc, token, TokenIdKeywordSuspend); |
| 661 | 664 | zig_unreachable(); |
| 662 | 665 | } else { |
| 663 | 666 | return nullptr; |
| 664 | 667 | } |
| 665 | 668 | |
| 666 | | Token *bar_token = &pc->tokens->at(*token_index); |
| 667 | | if (bar_token->id == TokenIdBinOr) { |
| 668 | | *token_index += 1; |
| 669 | | } else if (mandatory) { |
| 670 | | ast_expect_token(pc, suspend_token, TokenIdBinOr); |
| 671 | | zig_unreachable(); |
| 672 | | } else { |
| 673 | | *token_index = orig_token_index; |
| 674 | | return nullptr; |
| 669 | //guessing that semicolon is checked elsewhere? |
| 670 | if (token->id != TokenIdLBrace) { |
| 671 | if (mandatory) { |
| 672 | ast_expect_token(pc, token, TokenIdLBrace); |
| 673 | zig_unreachable(); |
| 674 | } else { |
| 675 | *token_index = orig_token_index; |
| 676 | return nullptr; |
| 677 | } |
| 675 | 678 | } |
| 676 | 679 | |
| 680 | //Expect that we have a block; |
| 677 | 681 | AstNode *node = ast_create_node(pc, NodeTypeSuspend, suspend_token); |
| 678 | | node->data.suspend.promise_symbol = ast_parse_symbol(pc, token_index); |
| 679 | | ast_eat_token(pc, token_index, TokenIdBinOr); |
| 680 | 682 | node->data.suspend.block = ast_parse_block(pc, token_index, true); |
| 681 | 683 | |
| 682 | 684 | return node; |
| ... | ... | @@ -3134,7 +3136,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont |
| 3134 | 3136 | visit_field(&node->data.await_expr.expr, visit, context); |
| 3135 | 3137 | break; |
| 3136 | 3138 | case NodeTypeSuspend: |
| 3137 | | visit_field(&node->data.suspend.promise_symbol, visit, context); |
| 3138 | 3139 | visit_field(&node->data.suspend.block, visit, context); |
| 3139 | 3140 | break; |
| 3140 | 3141 | } |