multiple errors with different positions using megaparsec

对着背影说爱祢 提交于 2020-02-22 06:15:13

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/39667592/multiple-errors-with-different-positions-using-megaparsec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!