| ... | @@ -212,6 +212,7 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) { | ... | @@ -212,6 +212,7 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) { |
| 212 | } | 212 | } |
| 213 | | 213 | |
| 214 | static AstNode *ast_parse_block_or_expression(ParseContext *pc, size_t *token_index, bool mandatory); | 214 | static AstNode *ast_parse_block_or_expression(ParseContext *pc, size_t *token_index, bool mandatory); |
| | 215 | static AstNode *ast_parse_block_expr_or_expression(ParseContext *pc, size_t *token_index, bool mandatory); |
| 215 | static AstNode *ast_parse_expression(ParseContext *pc, size_t *token_index, bool mandatory); | 216 | static AstNode *ast_parse_expression(ParseContext *pc, size_t *token_index, bool mandatory); |
| 216 | static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mandatory); | 217 | static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mandatory); |
| 217 | static AstNode *ast_parse_if_expr(ParseContext *pc, size_t *token_index, bool mandatory); | 218 | static AstNode *ast_parse_if_expr(ParseContext *pc, size_t *token_index, bool mandatory); |
| ... | @@ -701,7 +702,7 @@ static AstNode *ast_parse_try_expr(ParseContext *pc, size_t *token_index, bool m | ... | @@ -701,7 +702,7 @@ static AstNode *ast_parse_try_expr(ParseContext *pc, size_t *token_index, bool m |
| 701 | ast_eat_token(pc, token_index, TokenIdBinOr); | 702 | ast_eat_token(pc, token_index, TokenIdBinOr); |
| 702 | } | 703 | } |
| 703 | | 704 | |
| 704 | node->data.try_expr.else_node = ast_parse_block_or_expression(pc, token_index, true); | 705 | node->data.try_expr.else_node = ast_parse_block_expr_or_expression(pc, token_index, true); |
| 705 | } | 706 | } |
| 706 | | 707 | |
| 707 | return node; | 708 | return node; |
| ... | @@ -1439,7 +1440,7 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, size_t *token_index, bool ma | ... | @@ -1439,7 +1440,7 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, size_t *token_index, bool ma |
| 1439 | Token *else_token = &pc->tokens->at(*token_index); | 1440 | Token *else_token = &pc->tokens->at(*token_index); |
| 1440 | if (else_token->id == TokenIdKeywordElse) { | 1441 | if (else_token->id == TokenIdKeywordElse) { |
| 1441 | *token_index += 1; | 1442 | *token_index += 1; |
| 1442 | node->data.if_var_expr.else_node = ast_parse_block_or_expression(pc, token_index, true); | 1443 | node->data.if_var_expr.else_node = ast_parse_block_expr_or_expression(pc, token_index, true); |
| 1443 | } | 1444 | } |
| 1444 | | 1445 | |
| 1445 | return node; | 1446 | return node; |
| ... | @@ -1452,7 +1453,7 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, size_t *token_index, bool ma | ... | @@ -1452,7 +1453,7 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, size_t *token_index, bool ma |
| 1452 | Token *else_token = &pc->tokens->at(*token_index); | 1453 | Token *else_token = &pc->tokens->at(*token_index); |
| 1453 | if (else_token->id == TokenIdKeywordElse) { | 1454 | if (else_token->id == TokenIdKeywordElse) { |
| 1454 | *token_index += 1; | 1455 | *token_index += 1; |
| 1455 | node->data.if_bool_expr.else_node = ast_parse_block_or_expression(pc, token_index, true); | 1456 | node->data.if_bool_expr.else_node = ast_parse_block_expr_or_expression(pc, token_index, true); |
| 1456 | } | 1457 | } |
| 1457 | | 1458 | |
| 1458 | return node; | 1459 | return node; |
| ... | @@ -1860,15 +1861,15 @@ static bool statement_has_block_body(AstNode *node) { | ... | @@ -1860,15 +1861,15 @@ static bool statement_has_block_body(AstNode *node) { |
| 1860 | switch (node->type) { | 1861 | switch (node->type) { |
| 1861 | case NodeTypeIfBoolExpr: | 1862 | case NodeTypeIfBoolExpr: |
| 1862 | if (node->data.if_bool_expr.else_node) | 1863 | if (node->data.if_bool_expr.else_node) |
| 1863 | return node->data.if_bool_expr.else_node->type == NodeTypeBlock; | 1864 | return statement_has_block_body(node->data.if_bool_expr.else_node); |
| 1864 | return node->data.if_bool_expr.then_block->type == NodeTypeBlock; | 1865 | return node->data.if_bool_expr.then_block->type == NodeTypeBlock; |
| 1865 | case NodeTypeIfVarExpr: | 1866 | case NodeTypeIfVarExpr: |
| 1866 | if (node->data.if_var_expr.else_node) | 1867 | if (node->data.if_var_expr.else_node) |
| 1867 | return node->data.if_var_expr.else_node->type == NodeTypeBlock; | 1868 | return statement_has_block_body(node->data.if_var_expr.else_node); |
| 1868 | return node->data.if_var_expr.then_block->type == NodeTypeBlock; | 1869 | return node->data.if_var_expr.then_block->type == NodeTypeBlock; |
| 1869 | case NodeTypeTryExpr: | 1870 | case NodeTypeTryExpr: |
| 1870 | if (node->data.try_expr.else_node) | 1871 | if (node->data.try_expr.else_node) |
| 1871 | return node->data.try_expr.else_node->type == NodeTypeBlock; | 1872 | return statement_has_block_body(node->data.try_expr.else_node); |
| 1872 | return node->data.try_expr.then_node->type == NodeTypeBlock; | 1873 | return node->data.try_expr.then_node->type == NodeTypeBlock; |
| 1873 | case NodeTypeWhileExpr: | 1874 | case NodeTypeWhileExpr: |
| 1874 | return node->data.while_expr.body->type == NodeTypeBlock; | 1875 | return node->data.while_expr.body->type == NodeTypeBlock; |
| ... | @@ -1882,7 +1883,7 @@ static bool statement_has_block_body(AstNode *node) { | ... | @@ -1882,7 +1883,7 @@ static bool statement_has_block_body(AstNode *node) { |
| 1882 | case NodeTypeDefer: | 1883 | case NodeTypeDefer: |
| 1883 | return node->data.defer.expr->type == NodeTypeBlock; | 1884 | return node->data.defer.expr->type == NodeTypeBlock; |
| 1884 | default: | 1885 | default: |
| 1885 | zig_unreachable(); | 1886 | return false; |
| 1886 | } | 1887 | } |
| 1887 | } | 1888 | } |
| 1888 | | 1889 | |
| ... | @@ -2030,6 +2031,14 @@ static AstNode *ast_parse_ass_expr(ParseContext *pc, size_t *token_index, bool m | ... | @@ -2030,6 +2031,14 @@ static AstNode *ast_parse_ass_expr(ParseContext *pc, size_t *token_index, bool m |
| 2030 | return node; | 2031 | return node; |
| 2031 | } | 2032 | } |
| 2032 | | 2033 | |
| | 2034 | static AstNode *ast_parse_block_expr_or_expression(ParseContext *pc, size_t *token_index, bool mandatory) { |
| | 2035 | AstNode *block_expr = ast_parse_block_expr(pc, token_index, false); |
| | 2036 | if (block_expr) |
| | 2037 | return block_expr; |
| | 2038 | |
| | 2039 | return ast_parse_expression(pc, token_index, mandatory); |
| | 2040 | } |
| | 2041 | |
| 2033 | /* | 2042 | /* |
| 2034 | BlockOrExpression = Block | Expression | 2043 | BlockOrExpression = Block | Expression |
| 2035 | */ | 2044 | */ |