mirror of
https://github.com/RGBCube/serenity
synced 2025-06-30 10:32:17 +00:00
LibJS: Parse labelled statements
All statements now have an optional label string that can be null.
This commit is contained in:
parent
5cd01ed79e
commit
10bf4ba3dc
4 changed files with 44 additions and 0 deletions
|
@ -269,6 +269,9 @@ NonnullRefPtr<Statement> Parser::parse_statement()
|
|||
consume();
|
||||
return create_ast_node<EmptyStatement>();
|
||||
default:
|
||||
auto result = try_parse_labelled_statement();
|
||||
if (!result.is_null())
|
||||
return result.release_nonnull();
|
||||
if (match_expression()) {
|
||||
auto expr = parse_expression(0);
|
||||
consume_or_insert_semicolon();
|
||||
|
@ -383,6 +386,27 @@ RefPtr<FunctionExpression> Parser::try_parse_arrow_function_expression(bool expe
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Statement> Parser::try_parse_labelled_statement()
|
||||
{
|
||||
save_state();
|
||||
ArmedScopeGuard state_rollback_guard = [&] {
|
||||
load_state();
|
||||
};
|
||||
|
||||
auto identifier = consume(TokenType::Identifier).value();
|
||||
if (!match(TokenType::Colon))
|
||||
return {};
|
||||
consume(TokenType::Colon);
|
||||
|
||||
if (!match_statement())
|
||||
return {};
|
||||
auto statement = parse_statement();
|
||||
|
||||
statement->set_label(identifier);
|
||||
state_rollback_guard.disarm();
|
||||
return statement;
|
||||
}
|
||||
|
||||
NonnullRefPtr<Expression> Parser::parse_primary_expression()
|
||||
{
|
||||
if (match_unary_prefixed_expression())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue