1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:28:13 +00:00

LibJS: Parse ArrayExpression and start implementing Array objects

Note that property lookup is not functional yet.
This commit is contained in:
Andreas Kling 2020-03-20 20:29:57 +01:00
parent 0891f860f7
commit a82f64d3d6
9 changed files with 176 additions and 0 deletions

View file

@ -231,6 +231,8 @@ NonnullRefPtr<Expression> Parser::parse_primary_expression()
return parse_object_expression();
case TokenType::Function:
return parse_function_node<FunctionExpression>();
case TokenType::BracketOpen:
return parse_array_expression();
default:
m_has_errors = true;
expected("primary expression (missing switch case)");
@ -273,6 +275,22 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression()
return create_ast_node<ObjectExpression>();
}
NonnullRefPtr<ArrayExpression> Parser::parse_array_expression()
{
consume(TokenType::BracketOpen);
NonnullRefPtrVector<Expression> elements;
while (match_expression()) {
elements.append(parse_expression(0));
if (!match(TokenType::Comma))
break;
consume(TokenType::Comma);
}
consume(TokenType::BracketClose);
return create_ast_node<ArrayExpression>(move(elements));
}
NonnullRefPtr<Expression> Parser::parse_expression(int min_precedence, Associativity associativity)
{
if (match_unary_prefixed_expression())