scala / scala-parser-combinators

simple combinator-based parsing for Scala. formerly part of the Scala standard library, now a separate community-maintained module
Apache License 2.0
649 stars 131 forks source link

`phrase` method loses error context when successful parse result has lastFailure #518

Open i10416 opened 1 year ago

i10416 commented 1 year ago

When phrase is applied to successful parse result which has lastFailure, it returns only the original failure. I think it would be better to add a message that indicates the EOF is expected in the same way as it does when lastFailure is None.

For example, the following p fails because there are trailing spaces after d, but error message comes from c parse failure which doesn't have any hint for EOF.

val input = "a b d  "
val p = phase(/* a parser that parses `a b (c or d)`*/)

https://github.com/scala/scala-parser-combinators/blob/82d8524c7be74d15f29f5166293d8a7c7f3641ce/shared/src/main/scala/scala/util/parsing/combinator/Parsers.scala#L996