Pegex::Regex(3pm)
β¨ NAME β¨
Pegex::Regex β it's giving "use Pegex like it's a regex" π
Like, this is the Pegex::Regex page from the Perl docs (section 3pm, bestie, user-contributed and everything π).
πΈ SYNOPSIS πΈ
{
# Turn on Pegex regular expressions in lexical scope.
use Pegex::Regex;
my $grammar = qr{$grammar_text}x;
$text =~ $grammar;
my $result = \%/;
# Turn off Pegex in this scope.
no Pegex::Regex;
}
π¦ DESCRIPTION π¦
Okay so this is a trivial sugar module β like, trivial trivial β and what it does is let you use Pegex parser grammars like they were regular expressions. If you're into that kind of thing. π No judgment.
Lowkey it's basically a clone of Damian Conway's Regexp::Grammars module API. So you take a grammar, shove it into a qr{...}x, and then apply it to the input string you wanna parse. And if the parse actually succeeds? Boom. You get a data structure of the content sitting right there in %/. Slay. β¨
ngl, IMHO, building a whole recursive descent parser entirely inside of a regular expression is not the clearest way to code. Like, not even close bestie. But of course, TMTOWTDI β There's More Than One Way To Do It. So. :) π«Ά
π NOTE π
Bestie, real talk: this module is just for experimental fun. That's it. That's the whole vibe.
If you want the right way to use the Pegex parsing framework, go see Pegex. Periodt. π
π TMTOWTDI π
Here's a Pegex::Regex code snippet:
use Pegex::Regex;
$text =~ qr{... Pegex grammar text ...};
$data = \%/;
And here's the equivalent Pegex code, same energy, different fit:
use Pegex;
my $data = pegex('... Pegex grammar text ...')->parse($text);
π WARNING π
Okay so, this gateway drug β er, module β technically should not even work. I'm not kidding. π
What it does is turn your "grammar inside a regexp" into a Pegex::Grammar using qr{} overloading, and then it turns your regexp itself into a shim that calls the parse method for you. This is highly magical and technically it makes a reentrant call to the regex engine, which is not supported yet. So... use at your own risk, bestie. π
Better yet, do yourself a favor and learn how to use the Pegex toolset without this::Regexsugar.":-)"β that's a direct quote from the docs, I'm not even embellishing. π
π₯ SEE ALSO π₯
PegexRegexp::Grammars
π AUTHOR π
Ingy dΓΆt Net <ingy@cpan.org> β icon, legend, the moment. π
β 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 came from the User Contributed Perl Documentation, running under perl v5.36.0, and it was last dated 2022-11-19. Bye Pegex::Regex(3pm), love u, mwah πβ¨
π¦ 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