I have read a few posts on here about Scala parser-combinators and better error handling, but a lot of the "solutions" seem to say "just use '~!'", or "Anticipate failure cases with grammar rules".
So I attempted to implement some of that advice, but I am stuck understanding how the failure / err parsers work:
val foo: Parser[String] = """foo""".r | err("Custom Message")
val test: Parser[List[String]] = repsep(foo, ",") | err("Custom Message Repsep")
val r = parseAll(foo, ""bar") //[1.1] error: Custom Message -- YAY
val r = parseAll(test, "foo, bar") //[1.2] failure: string matching regex `foo' expected but `b' found -- NOOOOOO
My question is basically: if foo is being repeatedly attempted against the input string because of repsep, then why - since its definition includes a | on failure to try and force an err - is the error message from the leftmost terminal in the foo production being displayed?
Is there a way to view a stack of error messages in the parse result and always find mine and display to the user? Or do I need to implement my own version of repsep or something? I believe I am missing something about the conceptual model of what is going on :(
opaquethat wraps a parser and yields a custom error message that is useful on failure. E.g.:val test = foo.rep(1,",").opaque("Custom Message Repsep")- mephicide