Skip to content

Commit 455e87c

Browse files
fix parser: mixed grouping and call
1 parent 576a439 commit 455e87c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Parser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ auto Parser::parse_binaryRLOperation(Lexem lxm, Operation opr, ParseNode tree, i
423423
}
424424
if(opr_precedence > 0){
425425
auto treeOpr = std::get_if<Operation>(&*tree);
426-
if(treeOpr && *treeOpr != Operation::OPR_Grouping && precedence(*treeOpr) > precedence(opr)){
426+
if(treeOpr && *treeOpr != Operation::OPR_Grouping && precedence(*treeOpr) > precedence(opr)){
427427
return std::nullopt;
428428
}
429429
}
@@ -619,7 +619,7 @@ bool Parser::parse_CallOperation(ParseNode tree, int opr_precedence)
619619
}
620620
if(opr_precedence > 0){
621621
auto treeOpr = std::get_if<Operation>(&*tree);
622-
if(treeOpr && precedence(*treeOpr) > precedence(Operation::OPR_Call)){
622+
if(treeOpr && *treeOpr != Operation::OPR_Grouping && precedence(*treeOpr) > precedence(Operation::OPR_Call)){
623623
return false;
624624
}
625625
}

tests/tests-parser.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,19 @@ TEST_CASE("Parser", "[parser]"){
573573
>>>1:Operation(d00:Addition)
574574
>>>>0:Literal(=)
575575
>>>>-5:Literal(4)
576+
)Parser");
577+
}
578+
SECTION("Mixed Grouping and Call"){
579+
is.str("(g());");
580+
auto tree = parser.parse();
581+
582+
os << '\n' << tree;
583+
CHECK(os.str() == R"Parser(
584+
1:Statement(0:TranslationUnit)
585+
>1:Statement(1:Expression)
586+
>>1:Operation(1300:Grouping)
587+
>>>1:Operation(1100:Call)
588+
>>>>-5:VarUse(name:g)
576589
)Parser");
577590
}
578591
}

0 commit comments

Comments
 (0)