From 2d2b3ba5edc794a75a42d3dc14aca811b9d26592 Mon Sep 17 00:00:00 2001 From: Itamar Date: Sat, 6 Feb 2021 15:48:46 +0200 Subject: [PATCH] LibCpp: Include CPP_DEBUG in AK/Debug.h --- AK/Debug.h.in | 4 ++++ Userland/Libraries/LibCpp/Parser.cpp | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/AK/Debug.h.in b/AK/Debug.h.in index acd657b32f..6a23a9935c 100644 --- a/AK/Debug.h.in +++ b/AK/Debug.h.in @@ -66,6 +66,10 @@ #cmakedefine01 CPP_LANGUAGE_SERVER_DEBUG #endif +#ifndef CPP_DEBUG +#cmakedefine01 CPP_DEBUG +#endif + #ifndef CRYPTO_DEBUG #cmakedefine01 CRYPTO_DEBUG #endif diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp index d9a5c8cc98..c5d00d5c6d 100644 --- a/Userland/Libraries/LibCpp/Parser.cpp +++ b/Userland/Libraries/LibCpp/Parser.cpp @@ -24,8 +24,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -// #define CPP_DEBUG - #ifdef CPP_DEBUG # define DEBUG_SPAM #endif @@ -33,6 +31,7 @@ #include "Parser.h" #include "AK/LogStream.h" #include "AST.h" +#include #include #include #include @@ -49,7 +48,7 @@ Parser::Parser(const StringView& program) continue; m_tokens.append(move(token)); } -#ifdef CPP_DEBUG +#if CPP_DEBUG dbgln("Program:"); dbgln("{}", m_program); dbgln("Tokens:"); @@ -229,10 +228,12 @@ bool Parser::match_variable_declaration() save_state(); ScopeGuard state_guard = [this] { load_state(); }; + // Type if (!peek(Token::Type::KnownType).has_value() && !peek(Token::Type::Identifier).has_value()) return false; consume(); + // Identifier if (!peek(Token::Type::Identifier).has_value()) return false; consume(); @@ -243,9 +244,10 @@ bool Parser::match_variable_declaration() error("initial value of variable is not an expression"); return false; } + return true; } - return true; + return match(Token::Type::Semicolon); } NonnullRefPtr Parser::parse_variable_declaration(ASTNode& parent) @@ -706,7 +708,7 @@ void Parser::error(StringView message) m_tokens[m_state.token_index].m_start.column); } m_errors.append(formatted_message); - dbgln("{}", formatted_message); + dbgln("{}", formatted_message); } bool Parser::match_expression() @@ -1019,5 +1021,4 @@ NonnullRefPtr Parser::parse_if_statement(ASTNode& parent) } return if_statement; } - }