|$compiler = Pegex::Compiler->new();||Return a new Pegex::Compiler object.|
|$grammar_tree = $compiler->compile($grammar_input);||Compile a grammar text into a grammar tree that can be used by a Pegex::Parser. This method is calls the parse and combinate methods and returns the resulting tree.|
The first step of a compile is parse. This applies the Pegex language
grammar to your grammar text and produces an unoptimized tree.
This method returns $self so you can chain it to other methods.
Before a Pegex grammar tree can be used to parse things, it needs to be
combinated. This process turns the regex tokens into real regexes. It also
combines some rules together and eliminates rules that are not needed or have
been combinated. The result is a Pegex grammar tree that can be used by a
NOTE: While the parse phase of a compile is always the same for various
|$compiler->tree()||Return the current state of the grammar tree (as a hash ref).|
|$compiler->to_yaml()||Serialize the current grammar tree to YAML.|
|$compiler->to_json()||Serialize the current grammar tree to JSON.|
|$compiler->to_perl()||Serialize the current grammar tree to Perl.|
When you write a Pegex based module you will want to precompile your grammar into Perl so that it has no load penalty. Pegex::Grammar provides a special mechanism for this. Say you have a class like this:
Simply use this command:
perl -Ilib -MMyThing::Grammar=compile
and Pegex::Grammar will call Pegex::Compile to put your compiled grammar inside your tree subroutine. It will actually write the text into your module. This makes it trivial to update your grammar module after making changes to the grammar file.
Ingy doet Net <firstname.lastname@example.org>
Copyright 2010-2015. Ingy doet Net.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|perl v5.20.3||PEGEX::COMPILER (3)||2015-01-28|