Skip to content

Commit

Permalink
Fix incorrect lookup when parsing grouped expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
asynchroza committed Nov 6, 2023
1 parent deb5899 commit f1913fd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions nulascript/parser/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,8 @@ Expression* Parser::parseParensExpressions() {
getNextToken();

auto expression = parseExpression(Precedence::LOWEST);
std::cout << expression->toString() << std::endl;

if (!isEqualToPeekedTokenType(TokenType::RPAR)) {
if (!peekAndLoadExpectedToken(TokenType::RPAR)) {
return nullptr;
}

Expand Down
4 changes: 2 additions & 2 deletions nulascript/tests/parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ TEST(ParserSuite, TestAstToString) {
return a;
);

std::string expectedResult = "let a = ;\nreturn ;\n";
std::string expectedResult = "let a = ;return ;";
// clang-format on

Lexer l(input);
Expand Down Expand Up @@ -475,7 +475,7 @@ TEST(ParserSuite, TestOperatorPrecedence) {
{"a + b * c is not a * d + p * q",
"((a + (b * c)) is not ((a * d) + (p * q)))"},
{"false == a + b", "(false == (a + b))"},
{"a + (b + c) + d", "(a + (b + c)) + d)"}};
{"a + (b + c) + d", "((a + (b + c)) + d)"}};

for (auto test : precedenceTests) {
Lexer l(test.input);
Expand Down

0 comments on commit f1913fd

Please sign in to comment.