diff options
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -736,17 +736,23 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) { e->kind = EXPR_WHILE; WhileExpr *w = &e->while_; t->token++; - Token *cond_end = expr_find_end(p, EXPR_CAN_END_WITH_LBRACE, NULL); - if (!cond_end) return false; - if (!token_is_kw(cond_end, KW_LBRACE)) { - t->token = cond_end; - tokr_err(t, "Expected { to open while body."); - return false; + if (token_is_kw(t->token, KW_LBRACE)) { + /* infinite loop */ + w->cond = NULL; + } else { + Token *cond_end = expr_find_end(p, EXPR_CAN_END_WITH_LBRACE, NULL); + if (!cond_end) return false; + if (!token_is_kw(cond_end, KW_LBRACE)) { + t->token = cond_end; + tokr_err(t, "Expected { to open while body."); + return false; + } + Expression *cond = parser_new_expr(p); + w->cond = cond; + + if (!parse_expr(p, cond, cond_end)) + return false; } - Expression *cond = parser_new_expr(p); - w->cond = cond; - if (!parse_expr(p, cond, cond_end)) - return false; if (!parse_block(p, &w->body)) return false; return true; } |