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
21182118 bool need_implicit_final_void_statement = false;
21192119 bool semicolon_expected = true;
21202120 if (statement_node) {
2121 // label
21212122 semicolon_expected = false;
21222123 // if a label is the last thing in a block, add a void statement.
21232124 need_implicit_final_void_statement = true;
......@@ -2126,19 +2127,29 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand
21262127 if (!statement_node) {
21272128 statement_node = ast_parse_defer_expr(pc, token_index);
21282129 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;
21362134 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 }
21372140 } 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 }
21422153 }
21432154 }
21442155 }