1Pegex::Grammar(3)     User Contributed Perl Documentation    Pegex::Grammar(3)
2
3
4

NAME

6       Pegex::Grammar - Pegex Grammar Base Class
7

SYNOPSIS

9       Define a Pegex grammar (for the Foo syntax):
10
11           package Pegex::Foo::Grammar;
12           use base 'Pegex::Base';
13           extends 'Pegex::Grammar';
14
15           has text => q{
16           foo: bar baz
17           ... rest of Foo grammar ...
18           };
19
20       then use it to parse some Foo:
21
22           use Pegex::Parser;
23           my $parse_tree = Pegex::Parser->new(
24               grammar => 'Pegex::Foo::Grammar',
25               receiver => 'Pegex::Tree',
26           )->parse('my/file.foo');
27

DESCRIPTION

29       Pegex::Grammar is a base class for defining your own Pegex grammar
30       classes.  You just need to provide the grammar view the "text" or the
31       "file" attributes.
32
33       When Pegex::Parser uses your grammar, it will want it in the tree
34       (compiled) form, so Pegex::Grammar provides automatic compilation
35       support.
36

PROPERTIES AND METHODS

38       tree
39           This is the data structure containing the compiled grammar for your
40           syntax. It is usually produced by "Pegex::Compiler". You can inline
41           it in the "tree" method, or else the "make_tree" method will be
42           called to produce it.
43
44           The "make_tree" method will call on Pegex::Compiler to compile the
45           "text" property by default. You can define your own "make_tree"
46           method to do override this behavior.
47
48           Often times you will want to generate your own Pegex::Grammar
49           subclasses in an automated fashion. The Pegex and TestML modules do
50           this to be performant. This also allows you to keep your grammar
51           text in a separate file, and often in a separate repository, so it
52           can be shared by multiple programming language's module
53           implementations.
54
55           See <https://github.com/ingydotnet/pegex-pgx> and
56           <https://github.com/ingydotnet/pegex-pm/blob/master/lib/Pegex/Pegex/Grammar.pm>.
57
58       text
59           This is simply the text of your grammar, if you define this, you
60           should (probably) not define the "tree" property. This grammar text
61           will be automatically compiled when the "tree" is required.
62
63       file
64           This is the file where your Pegex grammar lives. It is usually used
65           when you are making a Pegex module. The path is relative to your
66           top level module directory.
67
68       make_tree
69           This method is called when the grammar needs the compiled version.
70

AUTHOR

72       Ingy döt Net <ingy@cpan.org>
73
75       Copyright 2010-2018. Ingy döt Net.
76
77       This program is free software; you can redistribute it and/or modify it
78       under the same terms as Perl itself.
79
80       See <http://www.perl.com/perl/misc/Artistic.html>
81
82
83
84perl v5.28.1                      2018-11-12                 Pegex::Grammar(3)
Impressum