mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:28:10 +00:00
LibJS: Force the lexer to parse a regex when expecting a statement
This commit is contained in:
parent
05444103e3
commit
106f9e30d7
4 changed files with 103 additions and 21 deletions
|
@ -400,6 +400,10 @@ NonnullRefPtr<Statement> Parser::parse_statement(AllowLabelledFunction allow_lab
|
|||
case TokenType::Semicolon:
|
||||
consume();
|
||||
return create_ast_node<EmptyStatement>({ m_state.current_token.filename(), rule_start.position(), position() });
|
||||
case TokenType::Slash:
|
||||
case TokenType::SlashEquals:
|
||||
m_state.current_token = m_state.lexer.force_slash_as_regex();
|
||||
[[fallthrough]];
|
||||
default:
|
||||
if (match_identifier_name()) {
|
||||
auto result = try_parse_labelled_statement(allow_labelled_function);
|
||||
|
@ -2556,6 +2560,8 @@ bool Parser::match_expression() const
|
|||
|| type == TokenType::This
|
||||
|| type == TokenType::Super
|
||||
|| type == TokenType::RegexLiteral
|
||||
|| type == TokenType::Slash // Wrongly recognized regex by lexer
|
||||
|| type == TokenType::SlashEquals // Wrongly recognized regex by lexer (/=a/ is a valid regex)
|
||||
|| type == TokenType::Yield
|
||||
|| match_unary_prefixed_expression();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue