From d94bb99381eb1ec136a572b7fe390fd70cc76320 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Tue, 15 Jul 2025 00:04:58 +0200 Subject: [PATCH] fixed implementation of parse block --- src/parser/parser.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp index c6860e5..e1660b6 100644 --- a/src/parser/parser.cpp +++ b/src/parser/parser.cpp @@ -301,18 +301,22 @@ namespace parser { ast::block_stmt* parser::parse_block() { TRACE_FUNCTION; ast::block_stmt* ret = new ast::block_stmt(current); - // ret->statements.push_back(parse_statement()); - next_token(); - int i = 0; - while (current.type != token::type::RBRACE && i++ < 10) { - // for (next_token(); next.type != token::type::RBRACE; - // next_token()) { + + for (next_token(); current.type != token::type::RBRACE + && current.type != token::type::END_OF_FILE; + next_token()) { ast::statement* stmt = parse_statement(); if (stmt != nullptr) ret->statements.push_back(stmt); - next_token(); } + if (current.type != token::type::RBRACE) { + next_error(token::type::RBRACE); + delete ret; + return nullptr; + } + + return ret; }