zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit a33be6fc9906e010a44087dc2b7143717d875505 (tree)
parent 8d03d666af1b8b14e6702c2502846e3c1a79e9da
Author: Josh Wolfe <thejoshwolfe@gmail.com>
Date:   Sun,  2 Apr 2017 13:47:23 -0700

defer without a block body requires a following semicolon

Diffstat:
Msrc/parser.cpp | 33++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/parser.cpp b/src/parser.cpp @@ -2118,6 +2118,7 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand bool need_implicit_final_void_statement = false; bool semicolon_expected = true; if (statement_node) { + // label semicolon_expected = false; // if a label is the last thing in a block, add a void statement. need_implicit_final_void_statement = true; @@ -2126,19 +2127,29 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand if (!statement_node) { statement_node = ast_parse_defer_expr(pc, token_index); if (statement_node) { - // don't let defer be the last statement in a block - need_implicit_final_void_statement = true; - } else { - statement_node = ast_parse_block_expr(pc, token_index, false); - } - if (statement_node) { - if (statement_has_block_body(statement_node)) + // defer + if (statement_has_block_body(statement_node)) { + // don't let defer be the last statement in a block + need_implicit_final_void_statement = true; semicolon_expected = false; + } else { + // defer without a block body requires a semicolon + Token *token = &pc->tokens->at(*token_index); + ast_expect_token(pc, token, TokenIdSemicolon); + } } else { - statement_node = ast_parse_expression(pc, token_index, false); - if (!statement_node) { - // final semicolon means add a void statement. - need_implicit_final_void_statement = true; + statement_node = ast_parse_block_expr(pc, token_index, false); + if (statement_node) { + // block expr + if (statement_has_block_body(statement_node)) + semicolon_expected = false; + } else { + statement_node = ast_parse_expression(pc, token_index, false); + if (!statement_node) { + // no statement. + // final semicolon means add a void statement. + need_implicit_final_void_statement = true; + } } } }