mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-25 10:48:41 +00:00
LibJS: Add TokenType::TemplateLiteral
This is required for template literals - we're not quite there yet, but at
least the parser can now tell us when this token is encountered -
currently this yields "Unexpected token Invalid". Not really helpful.
The character is a "backtick", but as we already have
TokenType::{StringLiteral,RegexLiteral} this seemed like a fitting name.
This also enables syntax highlighting for template literals in the js
REPL and LibGUI's JSSyntaxHighlighter.
This commit is contained in:
committed by
Andreas Kling
parent
57caca3171
commit
95b51e857d
@@ -337,7 +337,7 @@ Token Lexer::next()
|
||||
}
|
||||
}
|
||||
token_type = TokenType::NumericLiteral;
|
||||
} else if (m_current_char == '"' || m_current_char == '\'') {
|
||||
} else if (m_current_char == '"' || m_current_char == '\'' || m_current_char == '`') {
|
||||
char stop_char = m_current_char;
|
||||
consume();
|
||||
while (m_current_char != stop_char && m_current_char != '\n' && !is_eof()) {
|
||||
@@ -351,7 +351,10 @@ Token Lexer::next()
|
||||
token_type = TokenType::UnterminatedStringLiteral;
|
||||
} else {
|
||||
consume();
|
||||
token_type = TokenType::StringLiteral;
|
||||
if (stop_char == '`')
|
||||
token_type = TokenType::TemplateLiteral;
|
||||
else
|
||||
token_type = TokenType::StringLiteral;
|
||||
}
|
||||
} else if (m_current_char == EOF) {
|
||||
token_type = TokenType::Eof;
|
||||
|
||||
Reference in New Issue
Block a user