1=pod 2 3PGE::P6Rule Grammar 4 5=head1 DESCRIPTION 6 7This file contains a "reference grammar" that closely describes the syntax 8for perl 6 rules. It closely models the parser used by PGE's 9"p6rule" compiler function, which is presently a recursive descent 10parser. Eventually the parser is likely to be replaced by a table-based 11(shift/reduce) parser, so that some of the rules below will disappear. 12 13Still, this grammar may be useful for testing and for understanding 14the syntax of Perl 6 grammars. Patches, discussion, and comments 15welcome on the perl6-compiler mailing list. 16 17=cut 18 19grammar PGE::P6Rule; 20 21rule pattern { <flag>* <alternation> } 22 23# XXX: PGE understands :flag, but it doesn't yet 24# understand :flag() or :flag[] 25rule flag { \:<ident> [ \( <code> \) | \[ <code> \] ]? } 26 27rule alternation { <conjunction> [ \| <alternation> ]? } 28rule conjunction { <concatenation> [ \& <conjunction> ]? } 29rule concatenation { <quantified_term>* } 30rule quantified_term { <term> \s* <quantifier> \s* <singlecut> } 31 32# rule quantifier { \*\* \{ <code> \} | <[?*+]> \?? } 33rule quantifier { \*\* \{ \d+ [ \.\. [\d+ | \.]]? \} | <[?*+]> \?? } 34 35# XXX: PGE doesn't understand <!':'> yet 36rule singlecut { \: <!':'> } 37 38# Internally PGE currently handles terms using a p6meta token hash, 39# i.e., it does the equivalent of 40# rule term { %p6meta } 41# and then the entries in %p6meta take care of routing us to the 42# correct rule. However, for descriptive and test-parsing 43# purposes we'll go ahead and write it out here. 44rule term { 45 <whitemeta> 46 | <subpattern> 47 | <subrule> 48 | <charclass> 49 | <string_assertion> 50 | <indirect_rule> 51 | <symbolic_indirect_rule> 52 | <closure_rule> 53 | <match_alias> 54 | <interpolate_alias> 55 | <closure> 56 | <simple_assertions> 57 | <rxmodinternal> 58 | <dot> 59 | \:\:?\:? 60 | <literal> 61} 62 63rule whitemeta { \s+ | [ \# \N* \n \s* ]+ } 64 65rule subpattern { \( <pattern> \) | \[ <pattern> \] } 66 67rule subrule { \< <[!?]>? <name> [\s <pattern> ]? \> } 68 69rule enumerated_class { \<-\[ .*? <-[\\]> \]\> } 70rule charclass { \<[<[+\-]> [ <name> | \[ [ \\. | <-[]]> ]+ \] ]+ \> } 71 72rule string_assertion { \<' .*? <-[\\]>'\> | <" .*? <-[\\]>"\> } 73 74rule indirect_rule { \< <[$@%]> <name> \> } 75 76rule symbolic_indirect_rule { \<\:\:\( \$<name> \)\> } 77 78rule closure_rule { \<\{ <code> \}\> } 79 80rule match_alias { <[$@%]> [ \< <ident> \> | \d+ ] [ \s* \:= <term> ]? } 81 82rule interpolate_alias { <[$@%]> <name> [ \s* \:= <term> ]? } 83 84rule closure { \{ <code> \} } 85 86rule assertions { \^\^? | \$\$? } 87 88# XXX: This rule will eventually be managed by the %p6meta hash 89# in conjunction with the rxmodinternal: syntax category. 90# In the meantime, we'll explicitly list the backslash-metas 91# that PGE knows about or will know about soon. 92rule rxmodinternal { \\ <[bBdDeEfFhHnNrRsStTvVwW]> } 93 94# XXX: PGE doesn't know how to handle \s in enumerated character 95# classes yet, so we'll explicitly list a space below. 96rule metachar { <[ \\<>{}[]()@#$%^&|]> } 97 98rule literal { 99 [ <-[ \\%*+?:|.^$@[]()<>{}]> # actually, should be <-metachar> 100 | <hexadecimal_character> 101 | <named_character> 102 | \\<metachar> 103 ]+ } 104 105rule hexadecimal_character { \\ <[xX]> <xdigit>+ } 106 107rule named_character { \\[cC] \[ <-[]]>+ \] } 108 109=head1 AUTHOR 110 111Patrick Michaud (pmichaud@pobox.com) is the author and maintainer. 112Patches and suggestions are welcome on the Perl 6 compiler list 113(perl6-compiler@perl.org). 114 115=cut 116