-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
83 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
Pegex::Grammar | ||
============== | ||
|
||
Pegex Grammar Base Class | ||
|
||
= Synopsis | ||
|
||
Define a Pegex grammar (for the Foo syntax): | ||
|
||
package Pegex::Foo::Grammar; | ||
use base 'Pegex::Base'; | ||
extends 'Pegex::Grammar'; | ||
|
||
has text => q{ | ||
foo: bar baz | ||
... rest of Foo grammar ... | ||
}; | ||
|
||
then use it to parse some Foo: | ||
|
||
use Pegex::Parser; | ||
my $parse_tree = Pegex::Parser->new( | ||
grammar => 'Pegex::Foo::Grammar', | ||
receiver => 'Pegex::Tree', | ||
)->parse('my/file.foo'); | ||
|
||
= Description | ||
|
||
Pegex::Grammar is a base class for defining your own Pegex grammar classes. | ||
You just need to provide the grammar view the `text` or the `file` attributes. | ||
|
||
When [Pegex::Parser] uses your grammar, it will want it in the tree (compiled) | ||
form, so [Pegex::Grammar] provides automatic compilation support. | ||
|
||
= Properties and Methods | ||
|
||
- tree | ||
|
||
This is the data structure containing the compiled grammar for your syntax. | ||
It is usually produced by `Pegex::Compiler`. You can inline it in the `tree` | ||
method, or else the `make_tree` method will be called to produce it. | ||
|
||
The `make_tree` method will call on Pegex::Compiler to compile the `text` | ||
property by default. You can define your own `make_tree` method to do | ||
override this behavior. | ||
|
||
Often times you will want to generate your own Pegex::Grammar subclasses in | ||
an automated fashion. The Pegex and TestML modules do this to be performant. | ||
This also allows you to keep your grammar text in a separate file, and often | ||
in a separate repository, so it can be shared by multiple programming | ||
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>. | ||
|
||
- text | ||
|
||
This is simply the text of your grammar, if you define this, you should | ||
(probably) not define the `tree` property. This grammar text will be | ||
automatically compiled when the `tree` is required. | ||
|
||
- file | ||
|
||
This is the file where your Pegex grammar lives. It is usually used when you | ||
are making a Pegex module. The path is relative to your top level module | ||
directory. | ||
|
||
- make_tree | ||
|
||
This method is called when the grammar needs the compiled version. | ||
|
||
= Author | ||
|
||
Ingy döt Net <ingy@cpan.org> | ||
|
||
= 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. | ||
|
||
See http://www.perl.com/perl/misc/Artistic.html |
This file was deleted.
Oops, something went wrong.