From ec2c54ee2e1092fd8e8a26ce4044b35b69523640 Mon Sep 17 00:00:00 2001 From: Itamar Date: Fri, 2 Apr 2021 11:15:51 +0300 Subject: LibCpp: Parse "arrow" operator --- Userland/Libraries/LibCpp/AST.cpp | 3 +++ Userland/Libraries/LibCpp/AST.h | 1 + Userland/Libraries/LibCpp/Parser.cpp | 5 ++++- 3 files changed, 8 insertions(+), 1 deletion(-) (limited to 'Userland') diff --git a/Userland/Libraries/LibCpp/AST.cpp b/Userland/Libraries/LibCpp/AST.cpp index d3fe00e2fa..5dbedc52cf 100644 --- a/Userland/Libraries/LibCpp/AST.cpp +++ b/Userland/Libraries/LibCpp/AST.cpp @@ -215,6 +215,9 @@ void BinaryExpression::dump(size_t indent) const case BinaryOp::LogicalAnd: op_string = "&&"; break; + case BinaryOp::Arrow: + op_string = "->"; + break; } m_lhs->dump(indent + 1); diff --git a/Userland/Libraries/LibCpp/AST.h b/Userland/Libraries/LibCpp/AST.h index 902c9645fb..51289f0477 100644 --- a/Userland/Libraries/LibCpp/AST.h +++ b/Userland/Libraries/LibCpp/AST.h @@ -422,6 +422,7 @@ enum class BinaryOp { NotEqual, LogicalOr, LogicalAnd, + Arrow, }; class BinaryExpression : public Expression { diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp index 443bc79c5c..e00aeb2528 100644 --- a/Userland/Libraries/LibCpp/Parser.cpp +++ b/Userland/Libraries/LibCpp/Parser.cpp @@ -425,7 +425,8 @@ bool Parser::match_secondary_expression() || type == Token::Type::AndAnd || type == Token::Type::PipePipe || type == Token::Type::ExclamationMarkEquals - || type == Token::Type::PipePipe; + || type == Token::Type::PipePipe + || type == Token::Type::Arrow; } NonnullRefPtr Parser::parse_primary_expression(ASTNode& parent) @@ -577,6 +578,8 @@ NonnullRefPtr Parser::parse_secondary_expression(ASTNode& parent, No return parse_binary_expression(parent, lhs, BinaryOp::BitwiseOr); case Token::Type::PipePipe: return parse_binary_expression(parent, lhs, BinaryOp::LogicalOr); + case Token::Type::Arrow: + return parse_binary_expression(parent, lhs, BinaryOp::Arrow); case Token::Type::Equals: return parse_assignment_expression(parent, lhs, AssignmentOp::Assignment); case Token::Type::Dot: { -- cgit v1.2.3