GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  PEGEX::REGEX (3)

.ds Aq ’

NAME

Pegex::Regex - Use Pegex Like a Regex

CONTENTS

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

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 decscent 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. :-)

SEE ALSO

o Pegex
o Regexp::Grammars

AUTHOR

Ingy doet Net <ingy@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2010-2015. Ingy doet 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>

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 PEGEX::REGEX (3) 2015-01-28

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.