.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Pegex::Grammar 3pm" .TH Pegex::Grammar 3pm "2020-02-22" "perl v5.30.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Pegex::Grammar \- Pegex Grammar Base Class .SH "SYNOPSIS" .IX Header "SYNOPSIS" Define a Pegex grammar (for the Foo syntax): .PP .Vb 3 \& package Pegex::Foo::Grammar; \& use base \*(AqPegex::Base\*(Aq; \& extends \*(AqPegex::Grammar\*(Aq; \& \& has text => q{ \& foo: bar baz \& ... rest of Foo grammar ... \& }; .Ve .PP then use it to parse some Foo: .PP .Vb 5 \& use Pegex::Parser; \& my $parse_tree = Pegex::Parser\->new( \& grammar => \*(AqPegex::Foo::Grammar\*(Aq, \& receiver => \*(AqPegex::Tree\*(Aq, \& )\->parse(\*(Aqmy/file.foo\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Pegex::Grammar is a base class for defining your own Pegex grammar classes. You just need to provide the grammar view the \f(CW\*(C`text\*(C'\fR or the \f(CW\*(C`file\*(C'\fR attributes. .PP When Pegex::Parser uses your grammar, it will want it in the tree (compiled) form, so Pegex::Grammar provides automatic compilation support. .SH "PROPERTIES AND METHODS" .IX Header "PROPERTIES AND METHODS" .IP "tree" 4 .IX Item "tree" This is the data structure containing the compiled grammar for your syntax. It is usually produced by \f(CW\*(C`Pegex::Compiler\*(C'\fR. You can inline it in the \f(CW\*(C`tree\*(C'\fR method, or else the \f(CW\*(C`make_tree\*(C'\fR method will be called to produce it. .Sp The \f(CW\*(C`make_tree\*(C'\fR method will call on Pegex::Compiler to compile the \f(CW\*(C`text\*(C'\fR property by default. You can define your own \f(CW\*(C`make_tree\*(C'\fR method to do override this behavior. .Sp 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. .Sp See and . .IP "text" 4 .IX Item "text" This is simply the text of your grammar, if you define this, you should (probably) not define the \f(CW\*(C`tree\*(C'\fR property. This grammar text will be automatically compiled when the \f(CW\*(C`tree\*(C'\fR is required. .IP "file" 4 .IX Item "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. .IP "make_tree" 4 .IX Item "make_tree" This method is called when the grammar needs the compiled version. .SH "AUTHOR" .IX Header "AUTHOR" Ingy döt Net .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright 2010\-2020. Ingy döt Net. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP See