'How to provide an explicit error/failure message in the Scala fastparse library?

I'm using Li Haoyi's FastParse library. I have several situations where I'd like to provide explicit failure messages.

For example:

  def courseRE[p: P]: P[Regex] =
    P(CharIn("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.|*+[]()-^$").repX(1).!).map { re =>
      try { re.r }
      catch { case e => failure(s"Ill-formed regular expression: ${re}.") }
    }

But there is (apparently) no failure function.

Any suggested work-arounds? Simply throwing an exception doesn't give any context information.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source