From e3cbba08b1e975da23a66b6050cf8b29d78bc714 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Tue, 8 Jul 2025 18:08:17 +0200 Subject: [PATCH] fixed tests --- src/parser/parser.cpp | 16 ++++++++++++++++ src/parser/parser.hpp | 1 + 2 files changed, 17 insertions(+) diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp index 5ec562c..35cf831 100644 --- a/src/parser/parser.cpp +++ b/src/parser/parser.cpp @@ -16,6 +16,12 @@ namespace parser { next = lexer.next_token(); } + void parser::skip_until_semicolon() { + for (; current.type != token::type::SEMICOLON + && current.type != token::type::END_OF_FILE; + next_token()) {}; + } + ast::program* parser::parse_program() { ast::program* p = new ast::program(); @@ -51,6 +57,8 @@ namespace parser { next_token(); stmt->value = parse_expression(); + if (next.type == token::type::SEMICOLON) + next_token(); return stmt; } @@ -60,6 +68,7 @@ namespace parser { if (!expect_next(token::type::IDENTIFIER)) { delete stmt; + skip_until_semicolon(); return nullptr; } @@ -67,10 +76,14 @@ namespace parser { if (!expect_next(token::type::ASSIGN)) { delete stmt; + skip_until_semicolon(); return nullptr; } + next_token(); stmt->value = parse_expression(); + if (next.type == token::type::SEMICOLON) + next_token(); return stmt; } @@ -79,6 +92,9 @@ namespace parser { stmt->expression = parse_expression(); + if (next.type == token::type::SEMICOLON) + next_token(); + return stmt; }; diff --git a/src/parser/parser.hpp b/src/parser/parser.hpp index 078905c..a628440 100644 --- a/src/parser/parser.hpp +++ b/src/parser/parser.hpp @@ -32,6 +32,7 @@ namespace parser { std::unordered_map infix_parse_fns; void next_token(); + void skip_until_semicolon(); ast::statement* parse_statement(); ast::expression* parse_expression(); ast::let_stmt* parse_let();