summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Parser.cpp
diff options
context:
space:
mode:
authorConrad Pankoff <deoxxa@fknsrs.biz>2020-03-12 23:09:15 +1100
committerAndreas Kling <kling@serenityos.org>2020-03-12 13:42:23 +0100
commit2b36b4f09ff280ae821b73d73035ba95421701e8 (patch)
tree787fcc7834bcf637a7a75403e52f36f557f33520 /Libraries/LibJS/Parser.cpp
parent0fe87c5fec856e174157a6adce5a41e760851885 (diff)
downloadserenity-2b36b4f09ff280ae821b73d73035ba95421701e8.zip
LibJS: Implement +=, -=, *=, and /= assignment operators
Diffstat (limited to 'Libraries/LibJS/Parser.cpp')
-rw-r--r--Libraries/LibJS/Parser.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp
index 38e278300c..c022b96b6c 100644
--- a/Libraries/LibJS/Parser.cpp
+++ b/Libraries/LibJS/Parser.cpp
@@ -124,15 +124,27 @@ NonnullOwnPtr<Expression> Parser::parse_secondary_expression(NonnullOwnPtr<Expre
case TokenType::Plus:
consume();
return make<BinaryExpression>(BinaryOp::Plus, move(lhs), parse_expression());
+ case TokenType::PlusEquals:
+ consume();
+ return make<AssignmentExpression>(AssignmentOp::PlusEquals, move(lhs), parse_expression());
case TokenType::Minus:
consume();
return make<BinaryExpression>(BinaryOp::Minus, move(lhs), parse_expression());
+ case TokenType::MinusEquals:
+ consume();
+ return make<AssignmentExpression>(AssignmentOp::MinusEquals, move(lhs), parse_expression());
case TokenType::Asterisk:
consume();
return make<BinaryExpression>(BinaryOp::Asterisk, move(lhs), parse_expression());
+ case TokenType::AsteriskEquals:
+ consume();
+ return make<AssignmentExpression>(AssignmentOp::AsteriskEquals, move(lhs), parse_expression());
case TokenType::Slash:
consume();
return make<BinaryExpression>(BinaryOp::Slash, move(lhs), parse_expression());
+ case TokenType::SlashEquals:
+ consume();
+ return make<AssignmentExpression>(AssignmentOp::SlashEquals, move(lhs), parse_expression());
case TokenType::GreaterThanEquals:
consume();
return make<BinaryExpression>(BinaryOp::GreaterThanEquals, move(lhs), parse_expression());
@@ -250,9 +262,13 @@ bool Parser::match_secondary_expression() const
{
auto type = m_current_token.type();
return type == TokenType::Plus
+ || type == TokenType::PlusEquals
|| type == TokenType::Minus
+ || type == TokenType::MinusEquals
|| type == TokenType::Asterisk
+ || type == TokenType::AsteriskEquals
|| type == TokenType::Slash
+ || type == TokenType::SlashEquals
|| type == TokenType::Equals
|| type == TokenType::GreaterThanEquals
|| type == TokenType::LessThanEquals