jnthn / grammar-debugger

Grammar::Debugger and Grammer::Tracer Perl 6 modules
36 stars 20 forks source link

add a larger grammar to serve as both example & benchmark #9

Open meisl opened 10 years ago

meisl commented 10 years ago

How about

use v6;
use Grammar::Debugger;
grammar SelfDescribing {
    ...
}
SelfDescribing.parsefile($?FILE);

?

meisl commented 10 years ago

Note: of course I don't mean the trivial solution à la rule TOP { .* } - rather it should produce a parse-tree that's actually useable, ie could (theoritically) be turned into something executable that does exactly what it does (=same as perl6 SelfDescribing.pm).

Besides having a benchmark for Tracer/Debugger, this could also be used as an example how to develop/test/debug a grammar. I, personally, find the self-referential nature of it highly motivating. Maybe some tutorial grows out of it, sometime?

Now, having set the requirement of being able to parse itself AND produce a reasonable parse-tree, the real challenge will be to keep it as small as possible but still have it meet said requirement. This seems crucial for using it for demonstration/teaching. Re this I've found that the regex features used / spelling out rules for these is what makes it actually hard (=explode)...