使用megaparsec在不同位置出现多个错误 [英] multiple errors with different positions using megaparsec
问题描述
我将使用megaparsec解析大学项目的编程语言.但是,我搜寻了一种报告多个错误的方法.
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.
我对withRecovery有所了解,我看到了这个问题,但是我没有找到错误发生在不同位置的情况.
I know about withRecovery and I saw this issue but I didn't find about the case where errors happen on different positions.
例如此Java代码中的:
for example in this java code :
class A
{
public get() // line 3 column 10
{
return x // line 5 column 22
}
}
有错误1第3行第10列的预期类型"和错误2在第5行第22列缺少分号"
There are error1 "expected type at line 3 column 10" and error2 "missing semicolon at line 5 column 22"
我知道我可以将错误消息与failure
合并,但是多个位置呢?我该怎么办?
I know I can combine error messages with failure
but how about multiple positions ? How do I do that ?
推荐答案
如果您确定有关Alec的建议,但又不想使用Either (ParseError ...) (Either (ParseError ...) a)
,则可以对该值使用Control.Monad.join来将其转换为Either (ParseError ...) a
.抱歉,如果此工具不太有用
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
这篇关于使用megaparsec在不同位置出现多个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!