FParsec 默认错误消息
假设我正在定义以下解析器:
let identifier = many1Satisfy isLetter //match an identifier
let parser = identifier //our parser is only to match identifiers
test parser " abc" //the text to parse contains a leading space which should yield us an error
解析时,正如人们所期望的那样,发生了错误:
Failure: Error in Ln: 1 Col: 1
abc
^
Unknown Error(s)
我很好奇为什么它不能确定问题是他正在等待一封信但找不到一封信。我是否希望自己以某种方式将该信息添加到解析器中?
Let's say I am defining the following parser:
let identifier = many1Satisfy isLetter //match an identifier
let parser = identifier //our parser is only to match identifiers
test parser " abc" //the text to parse contains a leading space which should yield us an error
When parsing, an error ocurrs, as one would expect:
Failure: Error in Ln: 1 Col: 1
abc
^
Unknown Error(s)
I am curious on why can't it decide the problem is that he's expecting a letter and can't find one. Am I expected to add that info somehow to the parser by myself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
至于为什么它不能告诉你出了什么问题:
我猜这是由于“many1Satisfy” - 你看到这个组合器包装了另一个解析器,我猜它只是不知道在“many1”的哪个状态下发生了错误,而不是什么错误 - 所以它说“未知错误(s )”
这应该有效:
as to why it can't tell you whats wrong:
I guess this is due to the "many1Satisfy" - you see this combinator wraps another parser and I guess it just don't know in which state of "many1" an error occured and not what error - so it says "Unknown Error(s)"
this should work:
空格不是常规字符。在您的情况下,您需要忽略空格,为此您需要使用忽略空格的解析器来组合解析器,并使用这个新的组合解析器来解析标识符。
检查4.6 处理空格
White space is not a regular character. In your case you need to ignore the white spaces and for that you need to compose your parser with the parser which ignores white spaces and use this new composed parser to parse the identifier.
Check 4.6 Handling whitespace