Skip to content

Commit a5e75b2

Browse files
author
Amal Elshihaby
committed
Fix bug in repeatedly parsing scala#34
1 parent 45ed52f commit a5e75b2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ trait Parsers {
669669
* @param p a `Parser` that is to be applied successively to the input
670670
* @return A parser that returns a list of results produced by repeatedly applying `p` to the input.
671671
*/
672-
def rep[T](p: => Parser[T]): Parser[List[T]] = rep1(p) | success(List())
672+
def rep[T](p: => Parser[T]): Parser[List[T]] = rep1(p)
673673

674674
/** A parser generator for interleaved repetitions.
675675
*

src/test/scala/scala/util/parsing/combinator/JavaTokenParsersTest.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,28 @@ class JavaTokenParsersTest {
5555
parseFailure("with space", 6)
5656
}
5757

58+
@Test
59+
def repeatedlyParsesTest: Unit = {
60+
object TestTokenParser extends JavaTokenParsers
61+
import TestTokenParser._
62+
val p = ident ~ "(?i)AND".r.*
63+
64+
val parseResult = parseAll(p, "start start")
65+
parseResult match {
66+
case e @ Failure(message, next) =>
67+
assertEquals(next.pos.column, 7)
68+
assert(message.endsWith("string matching regex `(?i)AND' expected but `s' found"))
69+
case _ => sys.error(parseResult.toString)
70+
}
71+
72+
val parseResult2 = parseAll(p, "start AND AND")
73+
parseResult2 match {
74+
case Success(r, _) =>
75+
assertEquals("start", r._1)
76+
assertEquals("AND AND", r._2.mkString(" "))
77+
case _ => sys.error(parseResult.toString)
78+
}
79+
}
80+
81+
5882
}

0 commit comments

Comments
 (0)