summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Parser.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-05-04 22:34:45 +0100
committerAndreas Kling <kling@serenityos.org>2020-05-05 11:12:27 +0200
commit3e754a15d48e094bfaa6ce4faf4eb1bb1a07399a (patch)
treece867e166b1a14257429b0dfdda8e38c4998b5ec /Libraries/LibJS/Parser.cpp
parent8e4301dea610850b847f92737de09f030e4efac7 (diff)
downloadserenity-3e754a15d48e094bfaa6ce4faf4eb1bb1a07399a.zip
LibJS: Implement bitwise assignment operators (&=, |=, ^=)
Diffstat (limited to 'Libraries/LibJS/Parser.cpp')
-rw-r--r--Libraries/LibJS/Parser.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp
index e9d258bd53..64eb68a4c9 100644
--- a/Libraries/LibJS/Parser.cpp
+++ b/Libraries/LibJS/Parser.cpp
@@ -140,7 +140,9 @@ Parser::Parser(Lexer lexer)
g_operator_precedence.set(TokenType::ShiftLeftEquals, 3);
g_operator_precedence.set(TokenType::ShiftRightEquals, 3);
g_operator_precedence.set(TokenType::UnsignedShiftRightEquals, 3);
+ g_operator_precedence.set(TokenType::AmpersandEquals, 3);
g_operator_precedence.set(TokenType::PipeEquals, 3);
+ g_operator_precedence.set(TokenType::CaretEquals, 3);
g_operator_precedence.set(TokenType::Yield, 2);
@@ -668,12 +670,21 @@ NonnullRefPtr<Expression> Parser::parse_secondary_expression(NonnullRefPtr<Expre
case TokenType::Ampersand:
consume();
return create_ast_node<BinaryExpression>(BinaryOp::BitwiseAnd, move(lhs), parse_expression(min_precedence, associativity));
+ case TokenType::AmpersandEquals:
+ consume();
+ return create_ast_node<AssignmentExpression>(AssignmentOp::BitwiseAndAssignment, move(lhs), parse_expression(min_precedence, associativity));
case TokenType::Pipe:
consume();
return create_ast_node<BinaryExpression>(BinaryOp::BitwiseOr, move(lhs), parse_expression(min_precedence, associativity));
+ case TokenType::PipeEquals:
+ consume();
+ return create_ast_node<AssignmentExpression>(AssignmentOp::BitwiseOrAssignment, move(lhs), parse_expression(min_precedence, associativity));
case TokenType::Caret:
consume();
return create_ast_node<BinaryExpression>(BinaryOp::BitwiseXor, move(lhs), parse_expression(min_precedence, associativity));
+ case TokenType::CaretEquals:
+ consume();
+ return create_ast_node<AssignmentExpression>(AssignmentOp::BitwiseXorAssignment, move(lhs), parse_expression(min_precedence, associativity));
case TokenType::ShiftLeft:
consume();
return create_ast_node<BinaryExpression>(BinaryOp::LeftShift, move(lhs), parse_expression(min_precedence, associativity));
@@ -1199,8 +1210,11 @@ bool Parser::match_secondary_expression() const
|| type == TokenType::Instanceof
|| type == TokenType::QuestionMark
|| type == TokenType::Ampersand
+ || type == TokenType::AmpersandEquals
|| type == TokenType::Pipe
+ || type == TokenType::PipeEquals
|| type == TokenType::Caret
+ || type == TokenType::CaretEquals
|| type == TokenType::ShiftLeft
|| type == TokenType::ShiftLeftEquals
|| type == TokenType::ShiftRight