The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
=pod

=for comment
DO NOT EDIT. This Pod was generated by Swim v0.1.45.
See http://github.com/ingydotnet/swim-pm#readme

=encoding utf8

=head1 What is Pegex?

Pegex is a Friendly, Acmeist, PEG Parser framework. Friendly means that it is
simple to create, understand, modify and maintain Pegex parsers. Acmeist means
that the parsers will work automatically in many programming languages (as
long as they have some kind of traditional "regex" support). PEG (Parser
Expression Grammars) is the new style of Recursive-Descent/BNF style grammar
definition syntax.

The name "Pegex" comes from PEG + Regex. With Pegex you define top down
grammars that eventually break down to regex fragments. ie The low level
parsing matches are always done with regexes against the current position in
the input stream.

=head1 What is Parsing?

It may seem like a silly question, but it's important to have an understanding
of what parsing is and what a parser can do for you. At the the most basic
level "parsing" is the act of reading through an input, making sense of it,
and possibly doing something with what is found.

Usually a parser gets its instructions of what means what from something
called a grammar. A grammar is a set of rules that defines how the input must
be structured. In many parsing methodologies, input is preprocessed (possibly
into tokesn) before the parser/grammar get to look at it. Although this is a
common method, it is not the only approach.

=head1 How Pegex Works

Pegex parsing consists of 4 distinct parts or objects:

=over

=item Parser

The Pegex parsing engine

=item Grammar

The rules of a particular syntax

=item Receiver

The logic for processing matches

=item Input

Text conforming to the grammar rules


=back

Quite simply, a parser object is created with a grammar object and a receiver
object. Then the parser object's C<parse()> method is called on an input
object. The parser applies the rules of the grammar to the input and invokes
methods of the receiver as the rules match. The parse is either successful or
results in an error. The result is whatever the receiver object decides it
should be.

For example consider a parser that turns the Markdown text language into HTML.
The Pegex code to use this might look like this:

In the simplest terms, Pegex works like this (pseudocode):

    parser = new Pegex.Parser(
        grammar: new Markdown.Grammar
        receiver: new Markdown.Receiver.HTML
    )
    html = parser.parse(markdown)

=head1 See Also

=over

=item * L<Pegex::API>

=item * L<Pegex::Syntax>

=item * L<Pegex::Tutorial>

=back

=cut