mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:07:34 +00:00
LibJS: Clean up token constructor and use method instead for identifiers
Having two large constructor with just one parameter difference in the middle seems quite dangerous so just do it with a method.
This commit is contained in:
parent
3fee7b0d0b
commit
bbddfeef4b
2 changed files with 17 additions and 35 deletions
|
@ -768,28 +768,18 @@ Token Lexer::next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (identifier.has_value()) {
|
m_current_token = Token(
|
||||||
m_current_token = Token(
|
token_type,
|
||||||
token_type,
|
token_message,
|
||||||
token_message,
|
m_source.substring_view(trivia_start - 1, value_start - trivia_start),
|
||||||
m_source.substring_view(trivia_start - 1, value_start - trivia_start),
|
m_source.substring_view(value_start - 1, m_position - value_start),
|
||||||
m_source.substring_view(value_start - 1, m_position - value_start),
|
m_filename,
|
||||||
identifier.release_value(),
|
value_start_line_number,
|
||||||
m_filename,
|
value_start_column_number,
|
||||||
value_start_line_number,
|
m_position);
|
||||||
value_start_column_number,
|
|
||||||
m_position);
|
if (identifier.has_value())
|
||||||
} else {
|
m_current_token.set_identifier_value(identifier.release_value());
|
||||||
m_current_token = Token(
|
|
||||||
token_type,
|
|
||||||
token_message,
|
|
||||||
m_source.substring_view(trivia_start - 1, value_start - trivia_start),
|
|
||||||
m_source.substring_view(value_start - 1, m_position - value_start),
|
|
||||||
m_filename,
|
|
||||||
value_start_line_number,
|
|
||||||
value_start_column_number,
|
|
||||||
m_position);
|
|
||||||
}
|
|
||||||
|
|
||||||
if constexpr (LEXER_DEBUG) {
|
if constexpr (LEXER_DEBUG) {
|
||||||
dbgln("------------------------------");
|
dbgln("------------------------------");
|
||||||
|
|
|
@ -193,19 +193,6 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Token(TokenType type, String message, StringView trivia, StringView original_value, FlyString value, StringView filename, size_t line_number, size_t line_column, size_t offset)
|
|
||||||
: m_type(type)
|
|
||||||
, m_message(message)
|
|
||||||
, m_trivia(trivia)
|
|
||||||
, m_original_value(original_value)
|
|
||||||
, m_value(move(value))
|
|
||||||
, m_filename(filename)
|
|
||||||
, m_line_number(line_number)
|
|
||||||
, m_line_column(line_column)
|
|
||||||
, m_offset(offset)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
TokenType type() const { return m_type; }
|
TokenType type() const { return m_type; }
|
||||||
TokenCategory category() const;
|
TokenCategory category() const;
|
||||||
static TokenCategory category(TokenType);
|
static TokenCategory category(TokenType);
|
||||||
|
@ -239,6 +226,11 @@ public:
|
||||||
String string_value(StringValueStatus& status) const;
|
String string_value(StringValueStatus& status) const;
|
||||||
String raw_template_value() const;
|
String raw_template_value() const;
|
||||||
|
|
||||||
|
void set_identifier_value(FlyString value)
|
||||||
|
{
|
||||||
|
m_value = move(value);
|
||||||
|
}
|
||||||
|
|
||||||
bool is_identifier_name() const;
|
bool is_identifier_name() const;
|
||||||
bool trivia_contains_line_terminator() const;
|
bool trivia_contains_line_terminator() const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue