1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00

LibJS: Remove syntax errors from lexer

Giving the lexer the ability to generate errors adds unnecessary
complexity - also it only calls its syntax_error() function in one place
anyway ("unterminated string literal"). But since the lexer *also* emits
tokens like Eof or UnterminatedStringLiteral, it should be up to the
consumer of these tokens to decide what to do.

Also remove the option to not print errors to stderr as that's not
relevant anymore.
This commit is contained in:
Linus Groh 2020-05-14 16:08:40 +01:00 committed by Andreas Kling
parent 3485613f4a
commit 00b61a212f
4 changed files with 2 additions and 20 deletions

View file

@ -37,14 +37,8 @@ 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; }
private:
void consume();
@ -60,16 +54,12 @@ private:
bool match(char, char, char) const;
bool match(char, char, char, char) const;
void syntax_error(const char*);
StringView m_source;
size_t m_position = 0;
Token m_current_token;
int m_current_char = 0;
bool m_has_errors = false;
size_t m_line_number = 1;
size_t m_line_column = 1;
bool m_log_errors = true;
struct TemplateState {
bool in_expr;