From: Brian Ingerson [mailto:[EMAIL PROTECTED]] > > On 13/12/01 09:40 +0000, John McNamara wrote: > > > > > >New Features: > > > ... > > > - Remove dependency on Parse::RecDescent (precompile the parser) > > > ... > > > > Will this work? The pre-compiled grammar will still have a run-time > > dependency on Parse::RecDescent. > > That's not my understanding of how it works. > > I'm pretty sure that P::RD bundles in the runtime components.
Unless the documentation is out of date, and you're refering to a new feature... I believe you are mistaken. P::RD just allows you to precompile the grammar's rules not a whole parser. >From the documentation: > A grammar may be precompiled using the Precompile class method. > For example, to precompile a grammar stored in the scalar > $grammar, and produce a class named PreGrammar in a module > file named PreGrammar.pm, you could use: > > use Parse::RecDescent; > > Parse::RecDescent->Precompile($grammar, "PreGrammar"); > > The first argument is the grammar string, the second is the name > of the class to be built. The name of the module file is > generated automatically by appending ".pm" to the last element > of the class name. Thus > > Parse::RecDescent->Precompile($grammar, "My::New::Parser"); > > would produce a module file named Parser.pm. > > It is somewhat tedious to have to write a small Perl program > just to generate a precompiled grammar class, so > Parse::RecDescent has some special magic that allows you to do > the job directly from the command-line. > > If your grammar is specified in a file named grammar, you can > generate a class named Yet::Another::Grammar like so: > > > perl -MParse::RecDescent - grammar Yet::Another::Grammar > > > This would produce a file named Grammar.pm containing the full > definition of a class called Yet::Another::Grammar. Of course, > to use that class, you would need to put the Grammar.pm file in > a directory named Yet/Another, somewhere in your Perl include > path. > > Having created the new class, it's very easy to use it to build > a parser. You simply use the new module, and then call its new > method to create a parser object. For example: > > use Yet::Another::Grammar; > my $parser = Yet::Another::Grammar->new(); > > > The effect of these two lines is exactly the same as: > > use Parse::RecDescent; > > open GRAMMAR_FILE, "grammar" or die; > local $/; > my $grammar = <GRAMMAR_FILE>; > > my $parser = Parse::RecDescent->new($grammar); > > only considerably faster. > > Note however that the parsers produced by either approach are > exactly the same, so whilst precompilation has an effect on > set-up speed, it has no effect on parsing speed. RecDescent > 2.0 will address that problem.
