=pod PGE::P6Rule Grammar =head1 DESCRIPTION This file contains a "reference grammar" that closely describes the syntax for perl 6 rules. It closely models the parser used by PGE's "p6rule" compiler function, which is presently a recursive descent parser. Eventually the parser is likely to be replaced by a table-based (shift/reduce) parser, so that some of the rules below will disappear. Still, this grammar may be useful for testing and for understanding the syntax of Perl 6 grammars. Patches, discussion, and comments welcome on the perl6-compiler mailing list. =cut grammar PGE::P6Rule; rule pattern { * } # XXX: PGE understands :flag, but it doesn't yet # understand :flag() or :flag[] rule flag { \: [ \( \) | \[ \] ]? } rule alternation { [ \| ]? } rule conjunction { [ \& ]? } rule concatenation { * } rule quantified_term { \s* \s* } # rule quantifier { \*\* \{ \} | <[?*+]> \?? } rule quantifier { \*\* \{ \d+ [ \.\. [\d+ | \.]]? \} | <[?*+]> \?? } # XXX: PGE doesn't understand yet rule singlecut { \: } # Internally PGE currently handles terms using a p6meta token hash, # i.e., it does the equivalent of # rule term { %p6meta } # and then the entries in %p6meta take care of routing us to the # correct rule. However, for descriptive and test-parsing # purposes we'll go ahead and write it out here. rule term { | | | | | | | | | | | | | | \:\:?\:? | } rule whitemeta { \s+ | [ \# \N* \n \s* ]+ } rule subpattern { \( \) | \[ \] } rule subrule { \< <[!?]>? [\s ]? \> } rule enumerated_class { \<-\[ .*? <-[\\]> \]\> } rule charclass { \<[<[+\-]> [ | \[ [ \\. | <-[]]> ]+ \] ]+ \> } rule string_assertion { \<' .*? <-[\\]>'\> | <" .*? <-[\\]>"\> } rule indirect_rule { \< <[$@%]> \> } rule symbolic_indirect_rule { \<\:\:\( \$ \)\> } rule closure_rule { \<\{ \}\> } rule match_alias { <[$@%]> [ \< \> | \d+ ] [ \s* \:= ]? } rule interpolate_alias { <[$@%]> [ \s* \:= ]? } rule closure { \{ \} } rule assertions { \^\^? | \$\$? } # XXX: This rule will eventually be managed by the %p6meta hash # in conjunction with the rxmodinternal: syntax category. # In the meantime, we'll explicitly list the backslash-metas # that PGE knows about or will know about soon. rule rxmodinternal { \\ <[bBdDeEfFhHnNrRsStTvVwW]> } # XXX: PGE doesn't know how to handle \s in enumerated character # classes yet, so we'll explicitly list a space below. rule metachar { <[ \\<>{}[]()@#$%^&|]> } rule literal { [ <-[ \\%*+?:|.^$@[]()<>{}]> # actually, should be <-metachar> | | | \\ ]+ } rule hexadecimal_character { \\ <[xX]> + } rule named_character { \\[cC] \[ <-[]]>+ \] } =head1 AUTHOR Patrick Michaud (pmichaud@pobox.com) is the author and maintainer. Patches and suggestions are welcome on the Perl 6 compiler list (perl6-compiler@perl.org). =cut