Responding to previous comment from MB: "Have you the time to do this Damian?" The answer is yes, in the form of Regexp::Grammars, which Damian said himself is the successor of Parse::RecDescent.
To give credit to this module, PRD is very featureful and easy to use, it's very convenient to generate parsers, and the docs is quite complete. The only problem with it is, as many have pointed out, speed.
It is *seriously* slow, with parser generation can take up to half a second on my laptop with a moderate grammar (200-400 lines) and parsing can take seconds even minutes for a moderately long string. It is orders of magnitude slower than other parsers. Do think a few times before deciding you can take the performance hit of PRD.
For alternatives, try Regexp::Grammars. (Or Parse::Yapp or Parse::EYapp, as other reviewers have written.)
Parse::RecDescent used to be my second favourite module for parsing.
I like the powerful directives that make parsing much easier.
However there are three considerations where I feel Parse::Yapp is preferable:
- In RD is more difficult to deal with left recursive grammars. Usually you have to transform the "natural rules"
- In RD, the language described by the grammar depends on the order of the rules. But probably this is more a question of taste than a drawback.
This is why Parse::Yapp was my favourite module for parsing
even if it lacks most of the beautiful features provided by Parse::RecDescent.
For these reasons I wrote an extension of Parse::Yapp named 'Parse::Eyapp'. Any program that runs on Parse::Yapp works without changing a comma on Parse::Eyapp.
Parse::Eyapp provides extensions similar to the ones you can find in Parse::RecDescent. For example, using the directive %defaultaction works as RD "autoactions".
The directive %tree is similar to <autotree>, etc.
I tried to merge the best of Yapp and RecDescent
and added a few extensions. Among others:
translations schemes and a language for the manipulation of abstract syntax trees.
If you like Parse::RecDescent, give it a try to Parse::Eyapp.
Easy to use, very flexible, very powerful, well-documented and venerable, Parse::RecDescent is a very good module for parsing any text that could be described by a grammar. Compared to Parse::Yapp, Perl-byacc, this one definitely wins hands down in all those aspects. The only caveat is the speed of the module when dealing with long input strings - its processing increases polynomially to string length (nearly O(n3) in benchmark). I made a detailed comparison, usage example of Parse::RecDescent, Parse::Yapp, and Perl-byacc during my Entrez Gene parser project at sourceforge.net/docman/display_doc.ph...
This module is best for novice users, complex (context-sensitive or dynamic) grammars, or any situation where input is short or performance is no issue.
Clearly one of my favourite modules. I do not find it ease to use nor can I make any statement about the quality of the interface. But I am absolutedly willing to accept, that this is because of the sheer complexity of the functionality this module provides.
I would not hesitate to give it a straight 5 overall rating, if it
was not so slow (execution speed of the grammars).
Really great module.
When I tried using it, I realized that this module wiser than me, because it is capable accomplishing tasks that I can not do :)
Also afetr my PocketPC could easily run it, I got much more respect to my WinCE device :)
Also perlmonks.org community loves this module and find Parse::RecDescent questions very interesting to investigate and answer.
Learning Parse::RecDescent will make you smarter, and it might even help you get your job done. The documentation is fairly good, but I still needed to crack my copy of "lex & yacc" a few times while using it. The only major drawback of this module is its performance. It's probably the slowest module I've used since Date::Manip!
It's saved me a lot of time when writing the parser for the Math::Symbolic module. In fact, I doubt there would be a parser for the Math::Symbolic module if there hadn't been Parse::RecDescent to do the difficult work for me.
Writing P::RD grammars needs a bit of time to get accustomed to if you know yacc, but once you get the hang of it, it's not too difficult.
The one main gripe I have with this module is its speed. Compiling parsers takes forever. (As of version 0.112, the Math::Symbolic parser took about a second to compile on my 2GHz machine!) Parsing isn't blazingly fast either. Especially with long input strings.