Pegex::Parser(3pm)
π Pegex::Parser β the parser runtime, bestie edition π
Pegex::Parser lives in the User Contributed Perl Documentation section (that's the 3pm part, iykyk). She's the parsing engine runtime of the Pegex fam, and honestly? She carries the whole group project. π«Ά
β¨ NAME β¨
Pegex::Parser β the Pegex Parser Runtime. That's it, that's the name, slay. π
π SYNOPSIS π
use Pegex::Parser;
use SomeGrammarClass;
use SomeReceiverClass;
my $parser = Pegex::Parser->new(
grammar => SomeGrammarClass->new,
receiver => SomeReceiverClass->new,
);
my $result = $parser->parse($SomeInputText);
okay so it's giving three imports, one constructor, one parse call, and you're done. main character energy fr fr. β¨
π¦ DESCRIPTION π¦
Pegex::Parser is the Pegex component that provides the parsing engine runtime. It needs two besties to function: a Grammar object and a Receiver object.
Her parse() method takes an input that's expected to be matched by the grammar, and then applies the grammar rules to that input. And the way that the grammar gets applied? The receiver gets notified of matches, one by one. π
The receiver can do literally whatever it wants with those notifications, no rules, no judgement β but very often it builds the data up into a structure that everyone calls a Parse Tree. iconic behavior.
When the parse method finishes, it returns whatever object the receiver handed over as the final result. π
π but bestie β if the grammar fails to match the input anywhere along the way, the parse method will throw an error, and that error comes with much information about the failure. So at least when it goes wrong, it goes wrong loudly and informatively. we love a transparent queen.
π ATTRIBUTES π
The Pegex::Parser new object constructor takes these attributes, bestie, write them down:
grammarβ a Pegex::Grammar object. Required. No grammar, no parse, no exceptions, periodt.receiverβ a Pegex::Receiver object.debugβ Boolean. Turn on debugging. Defaultfalse.recursion_limitβ Integer. The recursion level to terminate on. Default0(off).recursion_warn_limitβ Integer. The recursion level to warn on. Default0(off).iteration_limitβ Integer. Number of matches to try before terminating. Default0(off).
π₯ DEBUGGING π₯
Pegex::Parser currently has 4 settings that are useful for debugging. (the docs say 4 and then list six, and honestly? we respect the chaos π). These can be set as Pegex::Parser object attributes, global variables, or environment variables β pick your fighter:
debugor$Pegex::Parser::Debugor$ENV{PERL_PEGEX_DEBUG}β if you set it to a true value, it enables very useful trace messages for every single internal match operation. every. single. one. πrecursion_limitor"Pegex::Parser::RecursionLimit"or$ENV{PERL_PEGEX_RECURSION_LIMIT}β if you set it to a number greater than0, Pegex::Parser will terminate after that recursion level number is reached. πrecursion_warn_limitor"Pegex::Parser::RecursionWarnLimit"or$ENV{PERL_PEGEX_RECURSION_WARN_LIMIT}β if you set it to a number greater than0, Pegex::Parser will issue a warning every time that recursion level number is reached. just a lil heads up, bestie π«Άiteration_limitor"Pegex::Parser::IterationLimit"or$ENV{PERL_PEGEX_ITERATION_LIMIT}β if you set it to a number greater than0, Pegex::Parser will terminate after that number of matches has been attempted.debug_indentor$Pegex::Parser::DebugIndentor$ENV{PERL_PEGEX_DEBUG_INDENT}β tells the parser how many spaces should be used for indenting debugging output. Default is1.debug_coloror$Pegex::Parser::DebugColoror$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. π"always"or1β Color is enabled. β"auto"β Color is enabled when STDERR is a tty. π₯οΈ"never"or0β 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. so it's giving free when unused, which is honestly a serve.
π SEE ALSO π
- Pegex::Grammar
- Pegex::Receiver
πΈ AUTHOR πΈ
Ingy dΓΆt Net <ingy@cpan.org>
π COPYRIGHT AND LICENSE π
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>
and that's the whole page, bestie!! π this one was rendered by perl v5.36.0 on 2022-11-19, and it's the Pegex::Parser(3pm) manual page β go parse something gorgeous, you've got this π¦β¨
π¦ where this page comes from
- debian bookworm: libpegex-perl 0.75-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libpegex-perl 0.75-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libpegex-perl 0.75-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libpegex-perl 0.75-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libpegex-perl 0.75-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms