mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:47:34 +00:00
LibJS: Allow lexer to run without logging errors
This commit is contained in:
parent
c2f8a5fffa
commit
cdb627a516
2 changed files with 9 additions and 1 deletions
|
@ -204,7 +204,8 @@ bool Lexer::is_numeric_literal_start() const
|
||||||
void Lexer::syntax_error(const char* msg)
|
void Lexer::syntax_error(const char* msg)
|
||||||
{
|
{
|
||||||
m_has_errors = true;
|
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()
|
Token Lexer::next()
|
||||||
|
|
|
@ -37,6 +37,12 @@ namespace JS {
|
||||||
class Lexer {
|
class Lexer {
|
||||||
public:
|
public:
|
||||||
explicit Lexer(StringView source);
|
explicit Lexer(StringView source);
|
||||||
|
Lexer(StringView source, bool log_errors)
|
||||||
|
: Lexer(source)
|
||||||
|
{
|
||||||
|
m_log_errors = log_errors;
|
||||||
|
}
|
||||||
|
|
||||||
Token next();
|
Token next();
|
||||||
bool has_errors() const { return m_has_errors; }
|
bool has_errors() const { return m_has_errors; }
|
||||||
|
|
||||||
|
@ -60,6 +66,7 @@ private:
|
||||||
bool m_has_errors = false;
|
bool m_has_errors = false;
|
||||||
size_t m_line_number = 1;
|
size_t m_line_number = 1;
|
||||||
size_t m_line_column = 1;
|
size_t m_line_column = 1;
|
||||||
|
bool m_log_errors = true;
|
||||||
|
|
||||||
static HashMap<String, TokenType> s_keywords;
|
static HashMap<String, TokenType> s_keywords;
|
||||||
static HashMap<String, TokenType> s_three_char_tokens;
|
static HashMap<String, TokenType> s_three_char_tokens;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue