diff --git a/shared/src/main/scala/scala/util/parsing/combinator/Parsers.scala b/shared/src/main/scala/scala/util/parsing/combinator/Parsers.scala index 4783afea..f6029423 100644 --- a/shared/src/main/scala/scala/util/parsing/combinator/Parsers.scala +++ b/shared/src/main/scala/scala/util/parsing/combinator/Parsers.scala @@ -949,5 +949,11 @@ trait Parsers { trait OnceParser[+T] extends Parser[T] { override def ~ [U](p: => Parser[U]): Parser[~[T, U]] = OnceParser{ (for(a <- this; b <- commit(p)) yield new ~(a,b)).named("~") } + + override def ~> [U](p: => Parser[U]): Parser[U] + = OnceParser{ (for(a <- this; b <- commit(p)) yield b).named("~>") } + + override def <~ [U](p: => Parser[U]): Parser[T] + = OnceParser{ (for(a <- this; b <- commit(p)) yield a).named("<~") } } } diff --git a/shared/src/test/scala/scala/util/parsing/combinator/t6464.scala b/shared/src/test/scala/scala/util/parsing/combinator/t6464.scala new file mode 100644 index 00000000..f1f1e264 --- /dev/null +++ b/shared/src/test/scala/scala/util/parsing/combinator/t6464.scala @@ -0,0 +1,42 @@ +import scala.util.parsing.input.CharSequenceReader +import scala.util.parsing.combinator.RegexParsers + +import org.junit.Test +import org.junit.Assert.assertEquals + +class t6464 { + object SspParser extends RegexParsers { + val ok: Parser[Any] = + ("<%" ~! rep(' ') ~ "\\w+".r ~ rep(' ') ~ "%>" + | "<%" ~! err("should not fail here, because of ~!")) + + val buggy: Parser[Any] = + ("<%" ~! rep(' ') ~> "\\w+".r <~ rep(' ') ~ "%>" + | "<%" ~! err("should not fail here, because of ~!")) + + } + + @Test + def test: Unit = { + assertEquals( + "[1.9] parsed: ((((<%~List( ))~hi)~List( ))~%>)", + SspParser.phrase(SspParser.ok)(new CharSequenceReader("<% hi %>")).toString) + + val expected = """[1.7] error: string matching regex '\w+' expected but '%' found + +<% %> + ^""" + + assertEquals( + expected, + SspParser.phrase(SspParser.ok)(new CharSequenceReader("<% %>")).toString) + + assertEquals( + "[1.9] parsed: hi", + SspParser.phrase(SspParser.buggy)(new CharSequenceReader("<% hi %>")).toString) + + assertEquals( + expected, + SspParser.phrase(SspParser.buggy)(new CharSequenceReader("<% %>")).toString) + } +}