diff options
| author | gingerBill <bill@gingerbill.org> | 2021-08-22 11:28:44 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-08-22 11:28:44 +0100 |
| commit | 0decdaed1aa95ecf620932707f900e517994581f (patch) | |
| tree | 2463ce88311ed49def4f30ccf0f595634cadc044 /src/parser.cpp | |
| parent | d72f4a8a79bbb229e0fcbb2c6cc439ba979a9453 (diff) | |
| parent | 93b5befe45b6464f30f7a9404d1db2d84edf201f (diff) | |
Merge branch 'master' into multi-pointers
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 898dd4da6..2c29f651a 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4145,16 +4145,26 @@ Ast *parse_for_stmt(AstFile *f) { if (!is_range && parse_control_statement_semicolon_separator(f)) { init = cond; cond = nullptr; - if (f->curr_token.kind != Token_Semicolon) { - cond = parse_simple_stmt(f, StmtAllowFlag_None); - } - expect_semicolon(f, cond); - if (f->curr_token.kind != Token_OpenBrace && - f->curr_token.kind != Token_do) { - post = parse_simple_stmt(f, StmtAllowFlag_None); + + if (f->curr_token.kind == Token_OpenBrace || f->curr_token.kind == Token_do) { + syntax_error(f->curr_token, "Expected ';', followed by a condition expression and post statement, got %.*s", LIT(token_strings[f->curr_token.kind])); + } else { + if (f->curr_token.kind != Token_Semicolon) { + cond = parse_simple_stmt(f, StmtAllowFlag_None); + } + + if (f->curr_token.string != ";") { + syntax_error(f->curr_token, "Expected ';', got %.*s", LIT(token_to_string(f->curr_token))); + } else { + expect_semicolon(f, nullptr); + } + + if (f->curr_token.kind != Token_OpenBrace && + f->curr_token.kind != Token_do) { + post = parse_simple_stmt(f, StmtAllowFlag_None); + } } } - } |