Pegex::Parser - Pegex Parser Runtime
use Pegex::Parser; use SomeGrammarClass; use SomeReceiverClass; my $parser = Pegex::Parser->new( grammar => SomeGrammarClass->new, receiver => SomeReceiverClass->new, ); my $result = $parser->parse($SomeInputText);
Pegex::Parser is the Pegex component that provides the parsing engine runtime. It requires a Grammar object and a Receiver object. It's parse() method takes an input that is expected to be matched by the grammar, and applies the grammar rules to the input. As the grammar is applied, the receiver is notified of matches. The receiver is free to do whatever it wishes, but often times it builds the data into a structure that is commonly known as a Parse Tree.
parse()
When the parse method is complete it returns whatever object the receiver has provided as the final result. If the grammar fails to match the input along the way, the parse method will throw an error with much information about the failure.
The Pegex::Parser new object constructor takes these attributes:
new
grammar
A Pegex::Grammar object. Required.
receiver
A Pegex::Receiver object.
debug
Boolean. Turn on debugging. Default false.
recursion_limit
Integer. Recursion level to terminate on. Default 0 (off).
recursion_warn_limit
Integer. Recursion level to warn on. Default 0 (off).
iteration_limit
Integer. Number of matches to try before terminating. Default 0 (off).
Pegex::Parser currently has 4 settings that are useful for debugging. These can be set as Pegex::Parser object attributes, global variables or environment variables:
$Pegex::Parser::Debug
$ENV{PERL_PEGEX_DEBUG}
If set to a true value, it enables very useful trace messages for every internal match operation.
Pegex::Parser::RecursionLimit
$ENV{PERL_PEGEX_RECURSION_LIMIT}
If set to a number greater than 0, Pegex::Parser will terminate after that recursion level number is reached.
Pegex::Parser::RecursionWarnLimit
$ENV{PERL_PEGEX_RECURSION_WARN_LIMIT}
If set to a number greater than 0, Pegex::Parser will issue a warning every time that recursion level number is reached.
Pegex::Parser::IterationLimit
$ENV{PERL_PEGEX_ITERATION_LIMIT}
If set to a number greater than 0, Pegex::Parser will terminate after that number of matches has been attempted.
debug_indent
$Pegex::Parser::DebugIndent
$ENV{PERL_PEGEX_DEBUG_INDENT}
Tells the parser how many spaces should be used for indenting debugging output. Default is 1.
debug_color
$Pegex::Parser::DebugColor
$ENV{PERL_PEGEX_DEBUG_COLOR}
If enabled, it will color got and not events in the debugging output (bright_green and bright_red respectively). Color will be enabled by default for debugging. It requires Term::ANSIColor.
got
not
bright_green
bright_red
always
1
Color is enabled.
auto
Color is enabled when STDERR is a tty.
never
Color is disabled.
You can configure the specific colors used by appending them like this:
PERL_PEGEX_DEBUG_COLOR='always, cyan bold, black on_yellow'
For available colors, see Term::ANSIColor
Note: Using these variables incurs a slight performance hit, but if you don't use them all the debugging code is optimized away.
Pegex::Grammar
Pegex::Receiver
Ingy döt Net <ingy@cpan.org>
Copyright 2010-2020. Ingy döt Net.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
To install Pegex, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pegex
CPAN shell
perl -MCPAN -e shell install Pegex
For more information on module installation, please visit the detailed CPAN module installation guide.