3

I'm going to use megaparsec for parsing a programming language for university project. However, I searched for finding a way to report multiple errors.

I know about withRecovery and I saw this issue but I didn't find about the case where errors happen on different positions.

for example in this java code :

class A
{ 
    public get() // line 3 column 10
    {
        return x // line 5 column 22
    }
}

There are error1 "expected type at line 3 column 10" and error2 "missing semicolon at line 5 column 22"

I know I can combine error messages with failure but how about multiple positions ? How do I do that ?

niceman
  • 2,653
  • 29
  • 57
  • 1
    [Here's](https://mrkkrp.github.io/megaparsec/tutorials/fun-with-the-recovery-feature.html) a blog post about the introduction of `withRecovery`. – Alec Sep 23 '16 at 21:02
  • @Alec thanks , I saw it but it makes ParseError part of the result of the parser, when you call `runParser` it will return `Either (ParseError ...) (Either (ParseError ...) a)` which seems kind of ugly to me ?!! – niceman Sep 24 '16 at 04:42

1 Answers1

0

If you're sure about Alec's suggestion, but don't want to have Either (ParseError ...) (Either (ParseError ...) a), you can just use Control.Monad.join on that value to turn it into an Either (ParseError ...) a. Sorry if this wasn't too helpful

Brendan Murphy
  • 208
  • 2
  • 6