Fixed issue where an indexer followed by a binary operator would ignore the binary
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-08-18 15:44:55 +02:00
parent b4897c77ec
commit faa3000d95
3 changed files with 57 additions and 2 deletions

View File

@@ -331,7 +331,10 @@ namespace Porygon::Parser {
/////////////////
ParsedExpression *Parser::ParseExpression(const Token *current) {
auto expression = this->ParseBinaryExpression(current, OperatorPrecedence::No);
return this->ParseBinaryExpression(current, OperatorPrecedence::No);
}
ParsedExpression* Parser::ParseComplexExpression(ParsedExpression* expression){
auto peekKind = this->Peek()->GetKind();
while (peekKind == TokenKind::OpenParenthesis ||
peekKind == TokenKind::OpenSquareBracket ||
@@ -455,8 +458,10 @@ namespace Porygon::Parser {
auto operand = this->ParseBinaryExpression(next, unaryPrecedence);
auto startPos = current->GetStartPosition();
left = new UnaryExpression(operatorKind, operand, startPos, operand->GetEndPosition() - startPos);
left = this -> ParseComplexExpression(left);
} else {
left = this->ParsePrimaryExpression(current);
left = this -> ParseComplexExpression(left);
}
while (true) {
auto next = this->Peek();
@@ -469,8 +474,9 @@ namespace Porygon::Parser {
auto right = this->ParseBinaryExpression(this->Next(), binaryPrecedence);
auto startPos = left->GetStartPosition();
left = new BinaryExpression(operatorKind, left, right, startPos, right->GetEndPosition() - startPos);
left = this -> ParseComplexExpression(left);
}
return left;
return this -> ParseComplexExpression(left);
}
ParsedExpression *Parser::ParsePrimaryExpression(const Token *current) {

View File

@@ -45,6 +45,7 @@ namespace Porygon::Parser {
// Expressions
ParsedExpression *ParseExpression(const Token *current);
ParsedExpression *ParseComplexExpression(ParsedExpression* previous);
ParsedExpression *ParseBinaryExpression(const Token *current, OperatorPrecedence parentPrecedence);
ParsedExpression *ParsePrimaryExpression(const Token *current);
ParsedExpression *ParseParenthesizedExpression(const Token *current);