1Pegex(3) User Contributed Perl Documentation Pegex(3)
2
3
4
6 Pegex - Acmeist PEG Parser Framework
7
9 This document describes Pegex version 0.75.
10
12 use Pegex;
13 my $result = pegex($grammar)->parse($input);
14
15 or with options:
16
17 use Pegex;
18 use ReceiverClass;
19 my $parser = pegex($grammar, 'ReceiverClass');
20 my $result = $parser->parse($input);
21
22 or more explicitly:
23
24 use Pegex::Parser;
25 use Pegex::Grammar;
26 my $pegex_grammar = Pegex::Grammar->new(
27 text => $grammar,
28 );
29 my $parser = Pegex::Parser->new(
30 grammar => $pegex_grammar,
31 );
32 my $result = $parser->parse($input);
33
34 or customized explicitly:
35
36 {
37 package MyGrammar;
38 use Pegex::Base;
39 extends 'Pegex::Grammar';
40 has text => "your grammar definition text goes here";
41 has receiver => "MyReceiver";
42 }
43 {
44 package MyReceiver;
45 use base 'Pegex::Receiver';
46 got_some_rule { ... }
47 got_other_rule { ... }
48 }
49 use Pegex::Parser;
50 my $parser = Pegex::Parser->new(
51 grammar => MyGrammar->new,
52 receiver => MyReceiver->new,
53 );
54 $parser->parse($input);
55 my $result = $parser->receiver->data;
56
58 Pegex is an Acmeist parser framework. It allows you to easily create
59 parsers that will work equivalently in lots of programming languages!
60 The inspiration for Pegex comes from the parsing engine upon which the
61 postmodern programming language Perl 6 is based on. Pegex brings this
62 beauty to the other justmodern languages that have a normal regular
63 expression engine available.
64
65 Pegex gets it name by combining Parsing Expression Grammars (PEG), with
66 Regular Expressions (Regex). That's actually what Pegex does.
67
68 PEG is the cool new way to elegantly specify recursive descent
69 grammars. The Perl 6 language is defined in terms of a self modifying
70 PEG language called Perl 6 Rules. Regexes are familiar to programmers
71 of most modern programming languages. Pegex defines a simple PEG
72 syntax, where all the terminals are regexes. This means that Pegex can
73 be quite fast and powerful.
74
75 Pegex attempts to be the simplest way to define new (or old) Domain
76 Specific Languages (DSLs) that need to be used in several programming
77 languages and environments. Things like JSON, YAML, Markdown etc. It
78 also great for writing parsers/compilers that only need to work in one
79 language.
80
82 The "Pegex.pm" module itself (this module) is just a trivial way to use
83 the Pegex framework. It is only intended for the simplest of uses.
84
85 This module exports a single function, "pegex", which takes a Pegex
86 grammar string as input. You may also pass a receiver class name after
87 the grammar.
88
89 my $parser = pegex($grammar, 'MyReceiver');
90
91 The "pegex" function returns a Pegex::Parser object, on which you would
92 typically call the "parse()" method, which (on success) will return a
93 data structure of the parsed data.
94
95 See Pegex::API for more details.
96
98 Pegex (Pegex::Parser) has many easy to use methods of debugging. See
99 the "Debugging" section of Pegex::Parser for details.
100
102 • Pegex::Overview
103
104 • Pegex::API
105
106 • Pegex::Syntax
107
108 • Pegex::Tutorial
109
110 • Pegex::Resources
111
112 • Pegex::Parser
113
114 • <http://github.com/ingydotnet/pegex-pm>
115
116 • <irc://freenode.net#pegex>
117
119 Ingy döt Net <ingy@cpan.org>
120
122 Copyright 2010-2020. Ingy döt Net.
123
124 This program is free software; you can redistribute it and/or modify it
125 under the same terms as Perl itself.
126
127 See <http://www.perl.com/perl/misc/Artistic.html>
128
129
130
131perl v5.32.1 2021-01-27 Pegex(3)