Skip to content

Commit

Permalink
Switch ReadMe from md to pod
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed May 14, 2014
1 parent 0fc94fd commit 3b2bfd9
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 69 deletions.
66 changes: 43 additions & 23 deletions ReadMe.md → ReadMe.pod
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# NAME
=pod

=for comment
DO NOT EDIT. This Pod was generated by Kwim.
See http://github.com/ingydotnet/kwim-pm#readme

=encoding utf8

=head1 NAME

Pegex - Acmeist PEG Parser Framework

# SYNOPSIS
=head1 SYNOPSIS

use Pegex;
my $result = pegex($grammar)->parse($input);
Expand Down Expand Up @@ -49,7 +57,7 @@ or customized explicitly:
$parser->parse($input);
my $result = $parser->receiver->data;

# DESCRIPTION
=head1 DESCRIPTION

Pegex is a Acmeist parser framework. It allows you to easily create parsers
that will work equivalently in lots of programming languages!
Expand All @@ -59,49 +67,61 @@ Regular Expessions (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
B<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.

# USAGE
=head1 USAGE

The `Pegex.pm` module itself (this module) is just a trivial way to use the
The C<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
This module exports a single function, C<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](http://search.cpan.org/perldoc?Pegex::Parser) object, on which you would
typically call the `parse()` method, which (on success) will return a data
The C<pegex> function returns a L<Pegex::Parser> object, on which you would
typically call the C<parse()> method, which (on success) will return a data
structure of the parsed data.

See [Pegex::API](http://search.cpan.org/perldoc?Pegex::API) for more details.
See L<Pegex::API> for more details.

=head1 SEE ALSO

=over

=item * L<Pegex::Overview>

# SEE ALSO
=item * L<Pegex::API>

- [Pegex::Overview](http://search.cpan.org/perldoc?Pegex::Overview)
- [Pegex::API](http://search.cpan.org/perldoc?Pegex::API)
- [Pegex::Syntax](http://search.cpan.org/perldoc?Pegex::Syntax)
- [Pegex::Tutorial](http://search.cpan.org/perldoc?Pegex::Tutorial)
- [Pegex::Resources](http://search.cpan.org/perldoc?Pegex::Resources)
- [http://github.com/ingydotnet/pegex-pm](http://github.com/ingydotnet/pegex-pm)
- [irc.freenode.net\#pegex](http://search.cpan.org/perldoc?irc.freenode.net\#pegex)
=item * L<Pegex::Syntax>

# AUTHOR
=item * L<Pegex::Tutorial>

=item * L<Pegex::Resources>

=item * L<http://github.com/ingydotnet/pegex-pm>

=item * L<irc://freenode.net#pegex>

=back

=head1 AUTHOR

Ingy döt Net <ingy@cpan.org>

# COPYRIGHT AND LICENSE
=head1 COPYRIGHT AND LICENSE

Copyright (c) 2010, 2011, 2012, 2013, 2014. Ingy döt Net.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.

See L<http://www.perl.com/perl/misc/Artistic.html>

See http://www.perl.com/perl/misc/Artistic.html
=cut
81 changes: 37 additions & 44 deletions lib/Pegex/Compiler.pod → doc/Pegex/Compiler.kwim
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
=encoding utf8
Pegex::Compiler
===============

=head1 NAME
Pegex Compiler

Pegex::Compiler - Pegex Compiler
= Synopsis

=head1 SYNOPSIS

use Pegex::Compiler;
my $grammar_text = '... grammar text ...';
my $pegex_compiler = Pegex::Compiler->new();
my $grammar_tree = $pegex_compiler->compile($grammar_text)->tree;
use Pegex::Compiler;
my $grammar_text = '... grammar text ...';
my $pegex_compiler = Pegex::Compiler->new();
my $grammar_tree = $pegex_compiler->compile($grammar_text)->tree;

or:

perl -Ilib -MYourGrammarModule=compile
perl -Ilib -MYourGrammarModule=compile

=head1 DESCRIPTION
= Description

The Pegex::Compiler transforms a Pegex grammar string (or file) into a
compiled form. The compiled form is known as a grammar tree, which is simply a
Expand All @@ -26,36 +25,34 @@ programming language. This makes it extremely portable. Pegex::Grammar has
methods for serializing to all these forms.

NOTE: Unless you are developing Pegex based modules, you can safely ignore this
module. Even if you are you probably won't use it directly. See L<IN PLACE
COMPILATION> below.
module. Even if you are you probably won't use it directly. See [In Place
Compilation] below.

=head1 METHODS
= Methods

The following public methods are available:

=over

=item $compiler = Pegex::Compiler->new();
- `$compiler = Pegex::Compiler->new();`

Return a new Pegex::Compiler object.

=item $grammar_tree = $compiler->compile($grammar_input);
- `$grammar_tree = $compiler->compile($grammar_input);`

Compile a grammar text into a grammar tree that can be used by a
Pegex::Parser. This method is calls the C<parse> and C<combinate> methods and
Pegex::Parser. This method is calls the `parse` and `combinate` methods and
returns the resulting tree.

Input can be a string, a string ref, a file path, a file handle, or a
Pegex::Input object. Return C<$self> so you can chain it to other methods.
Pegex::Input object. Return `$self` so you can chain it to other methods.

=item $compiler->parse($grammar_text)
- `$compiler->parse($grammar_text)`

The first step of a C<compile> is C<parse>. This applies the Pegex language
The first step of a `compile` is `parse`. This applies the Pegex language
grammar to your grammar text and produces an unoptimized tree.

This method returns C<$self> so you can chain it to other methods.
This method returns `$self` so you can chain it to other methods.

=item $compiler->combinate()
- `$compiler->combinate()`

Before a Pegex grammar tree can be used to parse things, it needs to be
combinated. This process turns the regex tokens into real regexes. It also
Expand All @@ -70,60 +67,56 @@ Perl, although this is often sufficient in similar languages like Ruby or
Python (PCRE based regexes). Languages like Java probably need to use their
own combinators.

=item $compiler->tree()
- `$compiler->tree()`

Return the current state of the grammar tree (as a hash ref).

=item $compiler->to_yaml()
- `$compiler->to_yaml()`

Serialize the current grammar tree to YAML.

=item $compiler->to_json()
- `$compiler->to_json()`

Serialize the current grammar tree to JSON.

=item $compiler->to_perl()
- `$compiler->to_perl()`

Serialize the current grammar tree to Perl.

=back

=head1 IN PLACE COMPILATION
= In Place Compilation

When you write a Pegex based module you will want to precompile your grammar
into Perl so that it has no load penalty. Pegex::Grammar provides a special
mechanism for this. Say you have a class like this:

package MyThing::Grammar;
use Pegex::Base;
extends 'Pegex::Grammar';
package MyThing::Grammar;
use Pegex::Base;
extends 'Pegex::Grammar';

use constant file => '../mything-grammar-repo/mything.pgx';
sub make_tree {
}
use constant file => '../mything-grammar-repo/mything.pgx';
sub make_tree {
}

Simply use this command:

perl -Ilib -MMyThing::Grammar=compile
perl -Ilib -MMyThing::Grammar=compile

and Pegex::Grammar will call Pegex::Compile to put your compiled grammar
inside your C<tree> subroutine. It will actually write the text into your
inside your `tree` subroutine. It will actually write the text into your
module. This makes it trivial to update your grammar module after making
changes to the grammar file.

See L<Pegex::JSON> for an example.
See [Pegex::JSON] for an example.

=head1 AUTHOR
= Author

Ingy döt Net <ingy@cpan.org>

=head1 COPYRIGHT AND LICENSE
= Copyright and License

Copyright (c) 2011, 2012, 2013, 2014. 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

=cut
2 changes: 1 addition & 1 deletion doc/Pegex/Grammar.kwim
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ form, so [Pegex::Grammar] provides automatic compilation support.
language's module implementations.

See https://github.com/ingydotnet/pegex-pgx and
<https://github.com/ingydotnet/pegex-pm/blob/master/lib/Pegex/Pegex/Grammar.pm>.
[https://github.com/ingydotnet/pegex-pm/blob/master/lib/Pegex/Pegex/Grammar.pm].

- text

Expand Down
2 changes: 1 addition & 1 deletion doc/Pegex/Tutorial/Calculator.kwim
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ different ways:

Our first example calculator uses what is known as the Operator Precedence
Climbing method. See:
<http://en.wikipedia.org/wiki/Operator-precedence_parser#Precedence_climbing_method>.
[http://en.wikipedia.org/wiki/Operator-precedence_parser#Precedence_climbing_method].

This is basically a clever technique of specifying our grammar rules such that
they imply precedence. Here's the pegex grammar from the code:
Expand Down

0 comments on commit 3b2bfd9

Please sign in to comment.