1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:48:11 +00:00

LibJS: Integrate labels into the Interpreter

The interpreter now considers a statement or block's label when
considering whether or not to break. All statements can be labelled.
This commit is contained in:
Matthew Olsson 2020-05-28 13:36:59 -07:00 committed by Andreas Kling
parent 03615a7872
commit d52ea37717
6 changed files with 87 additions and 21 deletions

View file

@ -269,9 +269,11 @@ 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(TokenType::Identifier)) {
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();
@ -1117,7 +1119,7 @@ NonnullRefPtr<BreakStatement> Parser::parse_break_statement()
consume();
return create_ast_node<BreakStatement>(target_label);
}
if (match_identifier_name() && !m_parser_state.m_current_token.trivia().contains('\n'))
if (match(TokenType::Identifier) && !m_parser_state.m_current_token.trivia().contains('\n'))
target_label = consume().value();
consume_or_insert_semicolon();
return create_ast_node<BreakStatement>(target_label);
@ -1131,7 +1133,7 @@ NonnullRefPtr<ContinueStatement> Parser::parse_continue_statement()
consume();
return create_ast_node<ContinueStatement>(target_label);
}
if (match_identifier_name() && !m_parser_state.m_current_token.trivia().contains('\n'))
if (match(TokenType::Identifier) && !m_parser_state.m_current_token.trivia().contains('\n'))
target_label = consume().value();
consume_or_insert_semicolon();
return create_ast_node<ContinueStatement>(target_label);