Pegex(3pm)

πŸ“¦
version 0.75 Β· 6 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

Pegex β€” the Acmeist PEG Parser Framework πŸ’– (this is the Pegex(3pm) page bestie, come get your parsing glow-up)


🌸 VERSION 🌸

This document describes Pegex version 0.75. yes we're keeping receipts πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

The quickest little taste, like the first sip of a strawberry lemonade:

use Pegex;
my $result = pegex($grammar)->parse($input);

or with options, because sometimes you want a whole look:

use Pegex;
use ReceiverClass;
my $parser = pegex($grammar, 'ReceiverClass');
my $result = $parser->parse($input);

or more explicitly, for when you're feeling very main character:

use Pegex::Parser;
use Pegex::Grammar;
my $pegex_grammar = Pegex::Grammar->new(
    text => $grammar,
);
my $parser = Pegex::Parser->new(
    grammar => $pegex_grammar,
);
my $result = $parser->parse($input);

or customized explicitly, the full custom-fitted fit πŸ”₯:

{
    package MyGrammar;
    use Pegex::Base;
    extends 'Pegex::Grammar';
    has text => "your grammar definition text goes here";
    has receiver => "MyReceiver";
}
{
    package MyReceiver;
    use base 'Pegex::Receiver';
    got_some_rule { ... }
    got_other_rule { ... }
}
use Pegex::Parser;
my $parser = Pegex::Parser->new(
    grammar => MyGrammar->new,
    receiver => MyReceiver->new,
);
$parser->parse($input);
my $result = $parser->receiver->data;

πŸ¦‹ DESCRIPTION πŸ¦‹

Pegex is an Acmeist parser framework. It lets you build parsers that work equivalently in a whole bunch of programming languages, no cap. The inspo for Pegex comes from the parsing engine that the postmodern programming language Perl 6 is based on. Pegex brings that beauty to the other justmodern languages that have a normal regular expression engine available. 🫢

Pegex gets its name by combining Parsing Expression Grammars (PEG) with Regular Expressions (Regex). That's literally what Pegex does, fr fr.

PEG is the cool new way to elegantly specify recursive descent grammars. The Perl 6 language is defined in terms of a self modifying PEG language called Perl 6 Rules. Regexes are familiar to programmers of most modern programming languages. Pegex defines a simple PEG syntax, where all the terminals are regexes. Which means Pegex can be quite fast and powerful β€” ate and left no crumbs. πŸ‘‘

Pegex attempts to be the simplest way to define new (or old) Domain Specific Languages (DSLs) that need to be used in several programming languages and environments. Things like JSON, YAML, Markdown etc. It's also great for writing parsers/compilers that only need to work in one language. Versatile queen energy. πŸ’…


🌈 USAGE 🌈

The Pegex.pm module itself (this module, hi it's me) is just a trivial way to use the Pegex framework. It is only intended for the simplest of uses. Think of it as the cute little starter kit. πŸŽ€

This module exports a single function, pegex, which takes a Pegex grammar string as input. You may also pass a receiver class name after the grammar. Slay.

my $parser = pegex($grammar, 'MyReceiver');

The pegex function returns a Pegex::Parser object, on which you would typically call the parse() method, which (on success) will return a data structure of the parsed data. πŸ“

See Pegex::API for more details.


πŸ’œ PEGEX DEBUGGING πŸ’œ

Pegex (Pegex::Parser) has many easy to use methods of debugging. See the "Debugging" section of Pegex::Parser for details. Go peek, iykyk. πŸ™ˆ


⭐ SEE ALSO ⭐


πŸ‘‘ AUTHOR πŸ‘‘

Ingy dΓΆt Net <ingy@cpan.org>


Copyright 2010-2020. Ingy dΓΆt 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>


and that's the whole page bestie!! brought to you by perl v5.36.0, dated 2022-11-19, living its Pegex(3pm) truth πŸ’–βœ¨ go parse something iconic 🌸

πŸ“¦ where this page comes from