aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-12-31 15:20:47 +0000
committergingerBill <bill@gingerbill.org>2018-12-31 15:20:47 +0000
commit8b2f902f3debfbf16f8be8e80388462587095766 (patch)
treee3fd9c03c8a1047a1376e178ce3d8d9e1ee3393e /src/parser.cpp
parentbbece7e910459cd1865db95d5a24c2dce1469d82 (diff)
Fix parsing issue with stray `}` and `case` at the file scope
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index f337cd08a..0f69ba56b 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -4544,7 +4544,20 @@ bool parse_file(Parser *p, AstFile *f) {
return false;
}
- f->decls = parse_stmt_list(f);
+ f->decls = array_make<Ast *>(heap_allocator());
+
+ while (f->curr_token.kind != Token_EOF) {
+ Ast *stmt = parse_stmt(f);
+ if (stmt && stmt->kind != Ast_EmptyStmt) {
+ array_add(&f->decls, stmt);
+ if (stmt->kind == Ast_ExprStmt &&
+ stmt->ExprStmt.expr != nullptr &&
+ stmt->ExprStmt.expr->kind == Ast_ProcLit) {
+ syntax_error(stmt, "Procedure literal evaluated but not used");
+ }
+ }
+ }
+
parse_setup_file_decls(p, f, base_dir, f->decls);
return true;