1Pegex::Regex(3) User Contributed Perl Documentation Pegex::Regex(3)
2
3
4
6 Pegex::Regex - Use Pegex Like a Regex
7
9 {
10 # Turn on Pegex regular expressions in lexical scope.
11 use Pegex::Regex;
12 my $grammar = qr{$grammar_text}x;
13 $text =~ $grammar;
14 my $result = \%/;
15
16 # Turn off Pegex in this scope.
17 no Pegex::Regex;
18 }
19
21 This is a trivial sugar module that lets you use Pegex parser grammars
22 like regular expressions, if you're into that kind of thing.
23
24 This is basically a clone of Damian Conway's Regexp::Grammars module
25 API. You put a grammar into a "qr{...}x" and apply it the input string
26 you want to parse. If the parse is successful, you get a data structure
27 of the content in "%/".
28
29 IMHO, building a recursive descent parser entirely inside of a regular
30 expression, is not the clearest way to code. But, of course, TMTOWTDI.
31 :)
32
34 This module is just for experimental fun. See Pegex for the right way
35 to use the Pegex parsing framework.
36
38 Here's a Pegex::Regex code snippet:
39
40 use Pegex::Regex;
41 $text =~ qr{... Pegex grammar text ...};
42 $data = \%/;
43
44 And the equivalent Pegex code:
45
46 use Pegex;
47 my $data = pegex('... Pegex grammar text ...')->parse($text);
48
50 This gateway drug, er, module, technically should not even work.
51
52 It turns your "grammar inside a regexp" into a Pegex::Grammar using
53 qr{} overloading, and then turns your regexp itself into a shim that
54 calls the parse method for you. This is highly magical and technically
55 makes a reentrant call to the regex engine, which is not supported yet.
56 Use at your own risk.
57
58 Better yet, do yourself a favor and learn how to use the Pegex toolset
59 without this ::Regex sugar. ":-)"
60
62 • Pegex
63
64 • Regexp::Grammars
65
67 Ingy döt Net <ingy@cpan.org>
68
70 Copyright 2010-2020. Ingy döt Net.
71
72 This program is free software; you can redistribute it and/or modify it
73 under the same terms as Perl itself.
74
75 See <http://www.perl.com/perl/misc/Artistic.html>
76
77
78
79perl v5.34.0 2021-07-22 Pegex::Regex(3)