diff options
author | Linus Groh <mail@linusgroh.de> | 2020-04-03 13:02:31 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-03 14:10:09 +0200 |
commit | a58640ce6bdc640d1a35b753b5ff5411fa4f522f (patch) | |
tree | e22098beca2319d99f315617a2e388fb680f2819 /Libraries/LibJS/Parser.cpp | |
parent | 0622181d1f883e787222bdbbbbd5f7ebf58c7a5a (diff) | |
download | serenity-a58640ce6bdc640d1a35b753b5ff5411fa4f522f.zip |
LibJS: Parse binary bitwise operators
The Lexer and AST already have all the functionality required in place,
so this is just updating Parser::match_secondary_expression() and
Parser::parse_expression() to handle TokenType::{Ampersand,Pipe,Caret},
as well as adding some tests.
Diffstat (limited to 'Libraries/LibJS/Parser.cpp')
-rw-r--r-- | Libraries/LibJS/Parser.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index da735be71e..a212969c02 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -490,6 +490,15 @@ NonnullRefPtr<Expression> Parser::parse_secondary_expression(NonnullRefPtr<Expre case TokenType::Instanceof: consume(); return create_ast_node<BinaryExpression>(BinaryOp::InstanceOf, move(lhs), parse_expression(min_precedence, associativity)); + case TokenType::Ampersand: + consume(); + return create_ast_node<BinaryExpression>(BinaryOp::BitwiseAnd, 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::Caret: + consume(); + return create_ast_node<BinaryExpression>(BinaryOp::BitwiseXor, move(lhs), parse_expression(min_precedence, associativity)); case TokenType::ParenOpen: return parse_call_expression(move(lhs)); case TokenType::Equals: @@ -877,7 +886,10 @@ bool Parser::match_secondary_expression() const || type == TokenType::PlusPlus || type == TokenType::MinusMinus || type == TokenType::Instanceof - || type == TokenType::QuestionMark; + || type == TokenType::QuestionMark + || type == TokenType::Ampersand + || type == TokenType::Pipe + || type == TokenType::Caret; } bool Parser::match_statement() const |