perl6

How can error reporting in grammars be improved?

烂漫一生 提交于 2019-11-27 09:15:30
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 debugging. 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 ...

How can I interpolate a variable into a Perl 6 regex?

老子叫甜甜 提交于 2019-11-26 21:37:23
问题 Synopsis 05 mentions that Perl 6 doesn't interpolate variables into a regex, but you can associate an external variable with a pattern. The docs don't mention this feature as far as I can tell. I think people are still going to want to build up a pattern from a string somehow, so I'm curious how that would work. Here's a program that demonstrates what happens now. I don't know if that's what is supposed to happen or what anyone intended. I insert a variable into a pattern. If you look at $r

How can error reporting in grammars be improved?

会有一股神秘感。 提交于 2019-11-26 14:36:15
问题 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'. 回答1: 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 debugging. First, you can embed arbitrary closures (code) in Perl 6 rules (or tokens or