我的个人喜好(此答案写在Comma出现之前的几年; Comma还涵盖了非语法代码的调试;实际上还有很多其他内容)是使用Rakudo调试器,该调试器提供Grammar :: Tracer所做的一切,此外(所有步进,断点等所有Perl 6代码(包括正则表达式和语法)都包括在内).此视频中引入了调试器.如果还有其他问题,建议您访问始终友好的 IRC频道#乐.Is there a way to get Perl 6 to generate an error message if a grammar does not match? Or at least return the position of the last data it processed? It is quite hard to fix syntax errors if all I get from the parser is 'no match'. 解决方案 If your focus is generating messages for users of your grammar, see Generating Good Parse Errors from a Parser and Grammar::ErrorReporting.The rest of this answer is about development and debugging of grammars.May 2020 update The obvious choice now is to use the Grammar Live View feature of the Comma IDE.First, you can embed arbitrary closures (code) in Perl 6 rules (or tokens or regexes). Just type { your code goes here } in the middle of a rule. So you could just sprinkle { say ... } statements where helpful for debugging. (Note that $/ and its relatives $0, $1 etc. and named sub-captures $<foo> etc. are automatically updated to refer to the current Match object and its sub-captures corresponding to the enclosing rule immediately prior to entering the closure. So you can introspect how the match is going at that point in the regex.)But there are better options.Are you using the "batteries included" Rakudo Star distribution? (You should be unless you've got good reason not to.) If so, you can add the line use Grammar::Tracer; (as described in the slides at http://www.jnthn.net/papers/2011-yapceu-grammars.pdf) to get a full trace of a parse.My personal preference (edit: this answer was written years before Comma arrived on the scene; Comma also covers debugging of non-grammar code; and indeed a whole heck of a lot else besides) is to use the Rakudo debugger which provides everything Grammar::Tracer does plus a whole lot more besides (single stepping, breakpoints, etc. of all Perl 6 code including regexes and grammars). The debugger is introduced in this video.If you have any more questions, I recommend you visit the always friendly IRC channel #raku. 这篇关于如何改进语法中的错误报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-17 09:12
查看更多