mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:08:10 +00:00
LibJS: Lex and parse regex literals, add RegExp objects
This adds regex parsing/lexing, as well as a relatively empty RegExpObject. The purpose of this patch is to allow the engine to not get hung up on parsing regexes. This will aid in finding new syntax errors (say, from google or twitter) without having to replace all of their regexes first!
This commit is contained in:
parent
984a6ff97b
commit
61ac1d3ffa
20 changed files with 424 additions and 5 deletions
|
@ -464,6 +464,8 @@ NonnullRefPtr<Expression> Parser::parse_primary_expression()
|
|||
return parse_function_node<FunctionExpression>();
|
||||
case TokenType::BracketOpen:
|
||||
return parse_array_expression();
|
||||
case TokenType::RegexLiteral:
|
||||
return parse_regexp_literal();
|
||||
case TokenType::TemplateLiteralStart:
|
||||
return parse_template_literal(false);
|
||||
case TokenType::New:
|
||||
|
@ -475,6 +477,13 @@ NonnullRefPtr<Expression> Parser::parse_primary_expression()
|
|||
}
|
||||
}
|
||||
|
||||
NonnullRefPtr<RegExpLiteral> Parser::parse_regexp_literal()
|
||||
{
|
||||
auto content = consume().value();
|
||||
auto flags = match(TokenType::RegexFlags) ? consume().value() : "";
|
||||
return create_ast_node<RegExpLiteral>(content.substring_view(1, content.length() - 2), flags);
|
||||
}
|
||||
|
||||
NonnullRefPtr<Expression> Parser::parse_unary_prefixed_expression()
|
||||
{
|
||||
auto precedence = operator_precedence(m_parser_state.m_current_token.type());
|
||||
|
@ -1449,6 +1458,7 @@ bool Parser::match_expression() const
|
|||
|| type == TokenType::ParenOpen
|
||||
|| type == TokenType::Function
|
||||
|| type == TokenType::This
|
||||
|| type == TokenType::RegexLiteral
|
||||
|| match_unary_prefixed_expression();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue