title: Scala Parser Combinator Custom Error Messages
body: <p>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".</p>
  
  <p>So I attempted to implement some of that advice, but I am stuck understanding how the failure / err parsers work:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>My question is basically: if <code>foo</code> is being repeatedly attempted against the input string because of <code>repsep</code>, then why - since its definition includes a <code>|</code> on failure to try and force an <code>err</code> - is the error message from the leftmost terminal in the <code>foo</code> production being displayed?  </p>
  
  <p>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 <code>repsep</code> or something? I believe I am missing something about the conceptual model of what is going on :(  </p>