Git Product home page Git Product logo

pegex-pm's Introduction

Name

Pegex - Acmeist PEG Parser Framework

Version

This document describes Pegex version 0.66.

Synopsis

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

or with options:

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

or more explicitly:

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:

{
    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 allows you to easily create parsers that will work equivalently in lots of programming languages! The inspiration for Pegex comes from the parsing engine upon which the postmodern programming language Perl 6 is based on. Pegex brings this beauty to the other justmodern languages that have a normal regular expression engine available.

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

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. This means that Pegex can be quite fast and powerful.

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 also great for writing parsers/compilers that only need to work in one language.

Usage

The Pegex.pm module itself (this module) is just a trivial way to use the Pegex framework. It is only intended for the simplest of uses.

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.

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.

See Also

Author

Ingy döt Net <[email protected]>

Copyright and License

Copyright 2010-2018. 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

pegex-pm's People

Contributors

agentzh avatar ingydotnet avatar mohawk2 avatar nikolawannabe avatar pdl avatar perlpunk avatar rking avatar shlomif avatar sineswiper avatar vikasnkumar avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.