Tracing parse failures by hand while developing a compiler can be really a daunting task, because the real problem can appear everywhere -- the grammar definition, the input string being matched, or even the regex engine itself.
So I've implemented a graphical tracer for Perl 6 regexes atop PCR (Pugs::Compiler::Rule). You can find some small online demos here:
-
http://agentzh.org/misc/tracer/digits/index.html (Firefox only)
-
http://agentzh.org/misc/tracer/grammar/index.html (Tracing PCR's own grammar parser)
To generate the HTML pages (say, the first demo) yourself, simply check out the Pugs repository , ``cd'' into perl5/Pugs-Compiler-Rule, and enter the following commands:
$ perl util/compile_p6grammar.pl -D \ examples/digits.grammar > Digits.pm $ echo '7c3d54' > digits.input $ perl -Ilib -MDigits -e \ 'undef $/; print Digits->count(<>)->(), "\n"' \ digits.input > trace.out $ perl util/gen-tracer-view.pl --outdir tmp/digits \ examples/digits.grammar digits.input < trace.out $ firefox tmp/digits/index.html
As of this writing, the tracer interface still needs love and I'm adding cooler features like ``random jump'', ``stepping in a specified pace'', and ``stepping back''. If you like to help, just join #perl6 and get a Pugs commit bit ;)
I think this tool should be very useful for both regex engine developers and compiler writers, especially when parsing fails in an unexpected way. And it can also be beneficial to Perl 6 beginners who want to learn the shiny new regex syntax and complicated matching behaviors by just ``stepping through'' the actual parsing process. moritz++ said on #perl6 that he would build a CGI script to make my demos above ``alive'' when he had the tuits; let's just wait and see ;)
It should be warned that the regex syntax supported by the current PCR implementation is already a little out-of-date regarding the lastest Synopsis 5 . (Thanks TimToady++ for tweaking the regex syntax during the meantime ;)) I'll try to port KindaPerl6 's perl5rx backend over to PCR later.
Hey, it'll be nicer to have KindaPerl6, PGE , Parse::RecDescent, or even the Perl 5 regex engine to work with my tracer as well! :)
Stay tuned!
-agentzh
Recent Comments