From cdb627a516ae4d84554b603450b899651e798847 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Sun, 5 Apr 2020 16:19:25 +0430 Subject: [PATCH] LibJS: Allow lexer to run without logging errors --- Libraries/LibJS/Lexer.cpp | 3 ++- Libraries/LibJS/Lexer.h | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Libraries/LibJS/Lexer.cpp b/Libraries/LibJS/Lexer.cpp index 1cf08bd29d..b29bef244d 100644 --- a/Libraries/LibJS/Lexer.cpp +++ b/Libraries/LibJS/Lexer.cpp @@ -204,7 +204,8 @@ bool Lexer::is_numeric_literal_start() const void Lexer::syntax_error(const char* msg) { m_has_errors = true; - fprintf(stderr, "Syntax Error: %s (line: %zu, column: %zu)\n", msg, m_line_number, m_line_column); + if (m_log_errors) + fprintf(stderr, "Syntax Error: %s (line: %zu, column: %zu)\n", msg, m_line_number, m_line_column); } Token Lexer::next() diff --git a/Libraries/LibJS/Lexer.h b/Libraries/LibJS/Lexer.h index eb1564b280..e896d3ca2a 100644 --- a/Libraries/LibJS/Lexer.h +++ b/Libraries/LibJS/Lexer.h @@ -37,6 +37,12 @@ namespace JS { class Lexer { public: explicit Lexer(StringView source); + Lexer(StringView source, bool log_errors) + : Lexer(source) + { + m_log_errors = log_errors; + } + Token next(); bool has_errors() const { return m_has_errors; } @@ -60,6 +66,7 @@ private: bool m_has_errors = false; size_t m_line_number = 1; size_t m_line_column = 1; + bool m_log_errors = true; static HashMap s_keywords; static HashMap s_three_char_tokens;