LibJS: Implement basic MemberExpression parsing

At last we can parse "hello friends".length :^)
This commit is contained in:
Andreas Kling 2020-03-12 13:05:57 +01:00
parent ed100bc6f4
commit f405cb6a77
Notes: sideshowbarker 2024-07-19 08:45:18 +09:00
2 changed files with 6 additions and 4 deletions

View file

@ -1,3 +1 @@
function foo() {
"hello friends".length
}
"hello friends".length

View file

@ -132,6 +132,9 @@ NonnullOwnPtr<Expression> Parser::parse_secondary_expression(NonnullOwnPtr<Expre
case TokenType::Equals:
consume();
return make<AssignmentExpression>(AssignmentOp::Assign, move(lhs), parse_expression());
case TokenType::Period:
consume();
return make<MemberExpression>(move(lhs), parse_expression());
default:
m_has_errors = true;
expected("secondary expression (missing switch case)");
@ -239,7 +242,8 @@ bool Parser::match_secondary_expression() const
|| type == TokenType::Asterisk
|| type == TokenType::Slash
|| type == TokenType::Equals
|| type == TokenType::ParenOpen;
|| type == TokenType::ParenOpen
|| type == TokenType::Period;
}
bool Parser::match_statement() const