LibJS: Parse CallExpression arguments

This commit is contained in:
Andreas Kling 2020-03-12 19:35:23 +01:00
commit 92d1014051
Notes: sideshowbarker 2024-07-19 08:20:29 +09:00

View file

@ -191,13 +191,24 @@ NonnullOwnPtr<Expression> Parser::parse_secondary_expression(NonnullOwnPtr<Expre
NonnullOwnPtr<CallExpression> Parser::parse_call_expression(NonnullOwnPtr<Expression> lhs) NonnullOwnPtr<CallExpression> Parser::parse_call_expression(NonnullOwnPtr<Expression> lhs)
{ {
// FIXME: allow arguments
consume(TokenType::ParenOpen); consume(TokenType::ParenOpen);
NonnullOwnPtrVector<Expression> arguments;
for (;;) {
if (match_expression()) {
arguments.append(parse_expression());
if (!match(TokenType::Comma))
break;
consume();
}
}
consume(TokenType::ParenClose); consume(TokenType::ParenClose);
// FIXME: Allow lhs expression instead of just a string // FIXME: Allow lhs expression instead of just a string
if (lhs->is_identifier()) { if (lhs->is_identifier()) {
return make<CallExpression>(static_cast<Identifier*>(lhs.ptr())->string()); return make<CallExpression>(static_cast<Identifier*>(lhs.ptr())->string(), move(arguments));
} }
m_has_errors = true; m_has_errors = true;