We don't bite newbies here... much | |
PerlMonks |
Re: advice with Parse::RecDescentby TheDamian (Vicar) |
on Dec 11, 2001 at 01:56 UTC ( [id://130789]=note: print w/replies, xml ) | Need Help?? |
There has been plenty of good advice already, but I suppose I should offer mine anyway. ;-)
RecDescent is overkill for this project, unless you expect it to grow in complexity (i.e. not just in the number of tags you're handling, but greater structural complexity of the data). A good indicator that a grammar is overkill is when it:
Moreover, when the data is line-based (i.e. each low-level rule in the grammar parses exactly one line), RecDescent is probably not needed. Your grammar seems to meet most of those criteria. On the other hand, the parsing task you have is very well suited for learning RecDescent. If I were implementing a parser for this in real life, rather than as a teaching exercise, I would probably bundle the regexes for each line type into a hash, and then iterate lines, testing against the various alternatives. Like so:
The result is quite readable and maintainable. And fast. Provided, of course, the data remains line-oriented. Finally, I do have big plans to rewrite RecDescent to make it much faster (though probably still Pure Perl). The original module was only supposed to be a quick-hack proof-of-concept for self-modifying parsers. It predates the /gc flag; hence the clunky (and slow!) parsing-by-substitution-of-copies idiom. But somehow escaped the lab and has subsequently infested a huge number of organizations, which now rely on it. There's probably a lesson in that. ;-)
In Section
Seekers of Perl Wisdom
|
|