改善Grako生成的解析器输出的错误 [英] Improving errors output by Grako-generated parser

查看:111
本文介绍了改善Grako生成的解析器输出的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出改善向Grako生成的解析器的用户显示的错误的最佳方法.似乎Grako生成的解析器在输入文件中遇到某些解析问题时显示的默认解析错误没有帮助.该错误似乎通常意味着当真正的错误与其他地方有所不同时,问题出在输入文件的一部分中.

I'm trying to figure out the best approach to improving the errors displayed to a user of a Grako-generated parser. It seems like the default parse errors displayed by the Grako-generated parser when it hits some parsing issue in the input file are not helpful. The errors often seem to imply the issue is in one part of the input file when the true error is somewhere different.

我一直在研究Grako Semantics类,以进行一些检查,如果检查失败,这些检查会显示更好的错误消息,但似乎还可能需要指定大量边缘情况才能捕捉到解析规则的所有可能方法都会失败.

I've been looking into the Grako Semantics class to put in some checks which would display better error messages if the checks fail, but it also seems like there could be tons of edge cases that must be specified to be able to catch all of the possible ways the parsing of a rule can fail.

有没有人可以推荐的建议或示例?

Does anyone have any recommendations or examples I can view?

推荐答案

PEG解析器将耗尽所有选项,有时会使您处于与最后一个也是最不可能的选项相对应的失败.

A PEG parser will exhaust all options, sometimes leaving you at a failure corresponding to the last, and least likely option.

使用Grako,您可以在语法中添加 cut 元素(~),以使解析器在可以确定某些选项匹配时将它们提交给某些选项.

With Grako, you can add cut elements (~) to the grammar to have the parser commit to certain options when it can be sure they are the ones to match.

term = '(' ~ expression ')' | int ; 

剪切元素还会修剪备忘录缓存,从而提高解析器性能.

Cut elements also prune the memoization cache, which improves parser performance.

这篇关于改善Grako生成的解析器输出的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆