scala/scala-parser-combinators

Parser returns an inappropriate failure msg when using repsep

Soya-Onishi opened this issue · 2 comments

This issue may be expected operation, but I feel failure msg is inappropriate.

execute below parser in version 1.1.1 and 1.1.2.

import scala.util.parsing.combinator._

object Parser extends JavaTokenParsers {
  def apply(str: String): ParseResult[List[Node]] = parseAll(top, str)

  private def top: Parser[List[Node]] = repsep(node, '\n')

  private def node: Parser[Node] = positioned(ident ~ ":" ~ ident ^^ {
    case v0 ~ _ ~ v1 => Node(v0, v1)
  })
}

parsed text (This text causes failure. An appropriate text is, for example, A : B.) is

A
A : B : C

In version 1.1.1, I got ':' expected but 'A' found. This failure message is expected message.

However, in version 1.1.2, I got end of input expected. This message loses information where is wrong point.

As a result that I checked difference of code between 1.1.1 and 1.1.2 lightly, I suspect that #108's change causes this. In addition, as far as I know, this problem occurs when using repsep (e.g. if parseAll uses node method directly, parser does not cause this problem)

Environment
scala version : 2.12.8
sbt version : 1.2.8

replaced by #234

The issue will be automatically closed by #234 once it gets merged. I think it's best to leave it open for now for others to see.