LibJS: Add message string to Token

This allows us to communicate details about invalid tokens to the parser
without having to invent a bunch of specific invalid tokens like
TokenType::InvalidNumericLiteral.
This commit is contained in:
Linus Groh 2020-10-26 20:08:01 +00:00 committed by Andreas Kling
commit 03c1d43f6e
Notes: sideshowbarker 2024-07-19 01:41:40 +09:00
2 changed files with 10 additions and 2 deletions

View file

@ -181,8 +181,9 @@ enum class TokenCategory {
class Token {
public:
Token(TokenType type, StringView trivia, StringView value, size_t line_number, size_t line_column)
Token(TokenType type, String message, StringView trivia, StringView value, size_t line_number, size_t line_column)
: m_type(type)
, m_message(message)
, m_trivia(trivia)
, m_value(value)
, m_line_number(line_number)
@ -196,6 +197,7 @@ public:
const char* name() const;
static const char* name(TokenType);
const String& message() const { return m_message; }
const StringView& trivia() const { return m_trivia; }
const StringView& value() const { return m_value; }
size_t line_number() const { return m_line_number; }
@ -217,6 +219,7 @@ public:
private:
TokenType m_type;
String m_message;
StringView m_trivia;
StringView m_value;
size_t m_line_number;