Skip to content

Commit 6ce410b

Browse files
committed
fix: sometimes ended prematurely
1 parent b22ae5e commit 6ce410b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

shared/src/main/scala/scala/util/parsing/combinator/Parsers.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,10 @@ trait Parsers {
11131113
case Success(rhs, next) => {
11141114
expandRight(rhs, next, prec) match {
11151115
case Right(Success(r, rnext)) => {
1116-
expandLeft(makeBinop(lhs, op, r), rnext, minLevel)
1116+
expandLeft(makeBinop(lhs, op, r), rnext, minLevel) match {
1117+
case Left(s: Success[Exp]) => Right(s)
1118+
case result => result
1119+
}
11171120
}
11181121
case Left(Success(r, rnext)) => Left(Success(makeBinop(lhs, op, r), rnext))
11191122
}

shared/src/test/scala/scala/util/parsing/combinator/PrecedenceParserTest.scala

+1
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ class PrecedenceParsersTest {
9999
testExp(Binop(Leaf(3), Plus, Binop(Leaf(9), Divide, Leaf(11))), "3 + 9 / 11")
100100
testExp(Binop(Binop(Leaf(6), Plus, Leaf(8)), Equals, Leaf(1)), "6 + 8 = 1")
101101
testExp(Binop(Leaf(4), Equals, Binop(Leaf(5), Minus, Leaf(3))), "4 = 5 - 3")
102+
testExp(Binop(Binop(Leaf(1), Minus, Binop(Leaf(2), Mult, Leaf(3))), Plus, Leaf(4)), "1 - 2 * 3 + 4")
102103
}
103104
}

0 commit comments

Comments
 (0)