Printing PEG structure
OvermindDL1 <[email protected]> Sat, 13 Mar 2010 20:39:09 -0700
| Newsgroups | gmane.comp.parsers.spirit.devel |
|---|---|
| Message-ID | <[email protected]> |
I am curious. I know that the grammar for Spirit generates a kind of
bytecode at compile time that the parse functions can go over to do
the actual parsing (again, optimized at compile time). I am curious,
would it be possible to create such a function that goes over that
bytecode/typetree of Qi/Karma and can print out the PEG string
representation of what the parsing does? For terminals it does not
know about would need to override a function or so that lets it print
out its representation.
Would be great for debugging though.
rule<...> r1, r2;
r1 = int_ >> space >> double_%',';
r2 = r1 | (lit('"')>>*~char_('"')>>lit('"'));
r1.name("r1");
r2.name("r2");
ostringstream o;
peg_string(o, r2);
o.str(); // returns:
r2 = r1 | ('"' (~'"')* '"')
r1 = int space double (',' double)*
int = /* however this is defined */
space = ' '|'\t'|'\r'|'\n'
double = /* however this is defined */
Or something like that. Does not need to be pretty, just get the
point across, would be great to toss into documentation for a created
parser too.
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev