Pegex::Regex(3pm)

πŸ“¦
version 0.75 Β· 6 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ 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 ::Regex sugar. ":-)" β€” that's a direct quote from the docs, I'm not even embellishing. πŸ’…

πŸ”₯ SEE ALSO πŸ”₯

  • Pegex
  • Regexp::Grammars

🌈 AUTHOR 🌈

Ingy dΓΆt Net <ingy@cpan.org> β€” icon, legend, the moment. πŸ‘‘


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