Improving errors output by Grako-generated parser

痞子三分冷 提交于 2019-12-25 08:57:05

问题


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.

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?


回答1:


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

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.



来源:https://stackoverflow.com/questions/38468395/improving-errors-output-by-grako-generated-parser

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