From 08aacf0416ed926436c72f19240b2c50e2f5bea5 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Tue, 8 Jul 2025 09:50:41 +0200 Subject: [PATCH] extracted the parsing of the "expressions" to it's own function so we can just modify that once we get there --- src/parser/parser.cpp | 17 +++++++++++------ src/parser/parser.hpp | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp index 03a1ed5..c2fe8d7 100644 --- a/src/parser/parser.cpp +++ b/src/parser/parser.cpp @@ -50,14 +50,18 @@ namespace parser { next_error(t); return false; } + ast::expression* parser::parse_expression() { + // TODO: we are currently skipping expressions until we encounter a + // semicolon + for (; current.type != token::type::SEMICOLON; next_token()) {} + return nullptr; + }; ast::return_stmt* parser::parse_return() { ast::return_stmt* stmt = new ast::return_stmt(current); next_token(); - // TODO: we are currently skipping expressions until we encounter a - // semicolon - for (; current.type != token::type::SEMICOLON; next_token()) {} + stmt->value = parse_expression(); return stmt; } @@ -77,9 +81,10 @@ namespace parser { return nullptr; } - // TODO: we are currently skipping expressions until we encounter a - // semicolon - for (; current.type != token::type::SEMICOLON; next_token()) {} + stmt->value = parse_expression(); + return stmt; + } + return stmt; } diff --git a/src/parser/parser.hpp b/src/parser/parser.hpp index d53949f..a19c539 100644 --- a/src/parser/parser.hpp +++ b/src/parser/parser.hpp @@ -21,6 +21,7 @@ namespace parser { void next_token(); ast::statement* parse_statement(); + ast::expression* parse_expression(); ast::let_stmt* parse_let(); ast::return_stmt* parse_return(); bool expect_next(token::type);