Pegex::Regex(3pm)

Pegex::Regex3pm

Use pegex like a regex

Usage

    {
        # 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;
    }

Overview

This is a trivial sugar module that lets you use Pegex parser grammars like regular expressions, if you're into that kind of thing.

This is basically a clone of Damian Conway's Regexp::Grammars module API. You put a grammar into a "qr{...}x" and apply it the input string you want to parse. If the parse is successful, you get a data structure of the content in "%/".

IMHO, building a recursive descent parser entirely inside of a regular expression, is not the clearest way to code. But, of course, TMTOWTDI. :)

Note

This module is just for experimental fun. See Pegex for the right way to use the Pegex parsing framework.

Tmtowtdi

Here's a Pegex::Regex code snippet:

    use Pegex::Regex;
    $text =~ qr{... Pegex grammar text ...};
    $data = \%/;

And the equivalent Pegex code:

    use Pegex;
    my $data = pegex('... Pegex grammar text ...')->parse($text);

Warning

This gateway drug, er, module, technically should not even work.

It turns your "grammar inside a regexp" into a Pegex::Grammar using qr{} overloading, and then turns your regexp itself into a shim that calls the parse method for you. This is highly magical and technically makes a reentrant call to the regex engine, which is not supported yet. Use at your own risk.

Better yet, do yourself a favor and learn how to use the Pegex toolset without this ::Regex sugar. ":-)"

Releases

7 releases since Debian 8 (Jessie); the text changed 5 times.

  1. 8
  2. 9
  3. 10
  4. 11
  5. 12–13
  6. Arch

Author

Ingy döt Net <[email protected]>

From perl-pegex 0.75-8 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.