From f95d0d7003f22917b0a8e22a5083edee357872d6 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sun, 22 Sep 2019 11:53:52 -0400 Subject: vbs bug fix --- parse.c | 27 ++++++++++----------------- test.toc | 2 +- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/parse.c b/parse.c index 114836c..8f55c17 100644 --- a/parse.c +++ b/parse.c @@ -400,6 +400,7 @@ static Token *expr_find_end(Parser *p, uint16_t flags, bool *is_vbs) { break; case KW_LBRACE: brace_level++; + could_be_vbs = true; break; case KW_RBRACE: brace_level--; @@ -417,10 +418,11 @@ static Token *expr_find_end(Parser *p, uint16_t flags, bool *is_vbs) { break; default: break; } - - } - if (!token_is_kw(token, KW_RBRACE) && !token_is_kw(token, KW_SEMICOLON)) + if (token->kw != KW_RBRACE && token->kw != KW_SEMICOLON && token->kw != KW_LBRACE) + could_be_vbs = false; + } else { could_be_vbs = false; + } if (token->kind == TOKEN_EOF) { if (brace_level > 0) { tokr_err(t, "Opening brace { was never closed."); /* FEATURE: Find out where this is */ @@ -1219,20 +1221,11 @@ static bool parse_stmt(Parser *p, Statement *s) { } bool success = parse_expr(p, &s->expr, end); - /* go past end regardless of whether successful or not */ - if (end->kind == TOKEN_KW) { - switch (end->kw) { - case KW_SEMICOLON: - t->token = end + 1; - break; - case KW_RBRACE: - t->token = end; /* the } is past the end of the expr */ - break; - default: assert(0); break; - } - } else { - t->token = end + 1; - } + /* go past end of expr regardless of whether successful or not */ + if (token_is_kw(end, KW_SEMICOLON)) + t->token = end + 1; /* skip ; */ + else + t->token = end; return success; } diff --git a/test.toc b/test.toc index f3a0fc6..82666ee 100644 --- a/test.toc +++ b/test.toc @@ -1,7 +1,7 @@ - main @= fn() { f := main; f(); { main(); } + f(); }; -- cgit v1.2.3