Skip to content

Commit 841fe0b

Browse files
committed
LibJS: Don't store current token in both Lexer and Parser
Just give Parser a way to access the one stored in Lexer.
1 parent d3e8fbd commit 841fe0b

File tree

4 files changed

+100
-98
lines changed

4 files changed

+100
-98
lines changed

Libraries/LibJS/Lexer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ bool Lexer::slash_means_division() const
636636
|| type == TokenType::TemplateLiteralEnd;
637637
}
638638

639-
Token Lexer::next()
639+
Token const& Lexer::next()
640640
{
641641
auto trivia_start = m_position;
642642
auto in_template = !m_template_states.is_empty();
@@ -970,7 +970,7 @@ Token Lexer::next()
970970
return m_current_token;
971971
}
972972

973-
Token Lexer::force_slash_as_regex()
973+
Token const& Lexer::force_slash_as_regex()
974974
{
975975
VERIFY(m_current_token.type() == TokenType::Slash || m_current_token.type() == TokenType::SlashEquals);
976976

Libraries/LibJS/Lexer.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ class JS_API Lexer {
1919
explicit Lexer(StringView source, StringView filename = "(unknown)"sv, size_t line_number = 1, size_t line_column = 0);
2020
explicit Lexer(Utf16String source, StringView filename = "(unknown)"sv, size_t line_number = 1, size_t line_column = 0);
2121

22-
Token next();
22+
// These both advance the lexer and return a reference to the current token.
23+
Token const& next();
24+
Token const& force_slash_as_regex();
25+
26+
[[nodiscard]] Token const& current_token() const { return m_current_token; }
2327

2428
Utf16String const& source() const { return m_source; }
2529
String const& filename() const { return m_filename; }
2630

2731
void disallow_html_comments() { m_allow_html_comments = false; }
2832

29-
Token force_slash_as_regex();
30-
3133
private:
3234
void consume();
3335
bool consume_exponent();

0 commit comments

Comments
 (0)