| ... | ... | @@ -2118,6 +2118,7 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand |
| 2118 | 2118 | bool need_implicit_final_void_statement = false; |
| 2119 | 2119 | bool semicolon_expected = true; |
| 2120 | 2120 | if (statement_node) { |
| 2121 | // label |
| 2121 | 2122 | semicolon_expected = false; |
| 2122 | 2123 | // if a label is the last thing in a block, add a void statement. |
| 2123 | 2124 | need_implicit_final_void_statement = true; |
| ... | ... | @@ -2126,19 +2127,29 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand |
| 2126 | 2127 | if (!statement_node) { |
| 2127 | 2128 | statement_node = ast_parse_defer_expr(pc, token_index); |
| 2128 | 2129 | if (statement_node) { |
| 2129 | | // don't let defer be the last statement in a block |
| 2130 | | need_implicit_final_void_statement = true; |
| 2131 | | } else { |
| 2132 | | statement_node = ast_parse_block_expr(pc, token_index, false); |
| 2133 | | } |
| 2134 | | if (statement_node) { |
| 2135 | | if (statement_has_block_body(statement_node)) |
| 2130 | // defer |
| 2131 | if (statement_has_block_body(statement_node)) { |
| 2132 | // don't let defer be the last statement in a block |
| 2133 | need_implicit_final_void_statement = true; |
| 2136 | 2134 | semicolon_expected = false; |
| 2135 | } else { |
| 2136 | // defer without a block body requires a semicolon |
| 2137 | Token *token = &pc->tokens->at(*token_index); |
| 2138 | ast_expect_token(pc, token, TokenIdSemicolon); |
| 2139 | } |
| 2137 | 2140 | } else { |
| 2138 | | statement_node = ast_parse_expression(pc, token_index, false); |
| 2139 | | if (!statement_node) { |
| 2140 | | // final semicolon means add a void statement. |
| 2141 | | need_implicit_final_void_statement = true; |
| 2141 | statement_node = ast_parse_block_expr(pc, token_index, false); |
| 2142 | if (statement_node) { |
| 2143 | // block expr |
| 2144 | if (statement_has_block_body(statement_node)) |
| 2145 | semicolon_expected = false; |
| 2146 | } else { |
| 2147 | statement_node = ast_parse_expression(pc, token_index, false); |
| 2148 | if (!statement_node) { |
| 2149 | // no statement. |
| 2150 | // final semicolon means add a void statement. |
| 2151 | need_implicit_final_void_statement = true; |
| 2152 | } |
| 2142 | 2153 | } |
| 2143 | 2154 | } |
| 2144 | 2155 | } |