authorgravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-04-02 13:47:23-07:00
committergravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-04-02 13:47:23-07:00
loga33be6fc9906e010a44087dc2b7143717d875505
tree94053d6b0248f78ea90e26ffaa6917627c5bd471
parent8d03d666af1b8b14e6702c2502846e3c1a79e9da

defer without a block body requires a following semicolon


1 files changed, 22 insertions(+), 11 deletions(-)

src/parser.cpp+22-11
...@@ -2118,6 +2118,7 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand...@@ -2118,6 +2118,7 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand
2118 bool need_implicit_final_void_statement = false;2118 bool need_implicit_final_void_statement = false;
2119 bool semicolon_expected = true;2119 bool semicolon_expected = true;
2120 if (statement_node) {2120 if (statement_node) {
2121 // label
2121 semicolon_expected = false;2122 semicolon_expected = false;
2122 // if a label is the last thing in a block, add a void statement.2123 // if a label is the last thing in a block, add a void statement.
2123 need_implicit_final_void_statement = true;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,19 +2127,29 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand
2126 if (!statement_node) {2127 if (!statement_node) {
2127 statement_node = ast_parse_defer_expr(pc, token_index);2128 statement_node = ast_parse_defer_expr(pc, token_index);
2128 if (statement_node) {2129 if (statement_node) {
2129 // don't let defer be the last statement in a block2130 // defer
2130 need_implicit_final_void_statement = true;2131 if (statement_has_block_body(statement_node)) {
2131 } else {2132 // don't let defer be the last statement in a block
2132 statement_node = ast_parse_block_expr(pc, token_index, false);2133 need_implicit_final_void_statement = true;
2133 }
2134 if (statement_node) {
2135 if (statement_has_block_body(statement_node))
2136 semicolon_expected = false;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 } else {2140 } else {
2138 statement_node = ast_parse_expression(pc, token_index, false);2141 statement_node = ast_parse_block_expr(pc, token_index, false);
2139 if (!statement_node) {2142 if (statement_node) {
2140 // final semicolon means add a void statement.2143 // block expr
2141 need_implicit_final_void_statement = true;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 }