7 This file contains a "reference grammar" that closely describes the syntax
8 for perl 6 rules. It closely models the parser used by PGE's
9 "p6rule" compiler function, which is presently a recursive descent
10 parser. 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.
13 Still, this grammar may be useful for testing and for understanding
14 the syntax of Perl 6 grammars. Patches, discussion, and comments
15 welcome on the perl6-compiler mailing list.
21 rule pattern { <flag>* <alternation> }
23 # XXX: PGE understands :flag, but it doesn't yet
24 # understand :flag() or :flag[]
25 rule flag { \:<ident> [ \( <code> \) | \[ <code> \] ]? }
27 rule alternation { <conjunction> [ \| <alternation> ]? }
28 rule conjunction { <concatenation> [ \& <conjunction> ]? }
29 rule concatenation { <quantified_term>* }
30 rule quantified_term { <term> \s* <quantifier> \s* <singlecut> }
32 # rule quantifier { \*\* \{ <code> \} | <[?*+]> \?? }
33 rule quantifier { \*\* \{ \d+ [ \.\. [\d+ | \.]]? \} | <[?*+]> \?? }
35 # XXX: PGE doesn't understand <!':'> yet
36 rule singlecut { \: <!':'> }
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.
51 | <symbolic_indirect_rule>
63 rule whitemeta { \s+ | [ \# \N* \n \s* ]+ }
65 rule subpattern { \( <pattern> \) | \[ <pattern> \] }
67 rule subrule { \< <[!?]>? <name> [\s <pattern> ]? \> }
69 rule enumerated_class { \<-\[ .*? <-[\\]> \]\> }
70 rule charclass { \<[<[+\-]> [ <name> | \[ [ \\. | <-[]]> ]+ \] ]+ \> }
72 rule string_assertion { \<' .*? <-[\\]>'\> | <" .*? <-[\\]>"\> }
74 rule indirect_rule { \< <[$@%]> <name> \> }
76 rule symbolic_indirect_rule { \<\:\:\( \$<name> \)\> }
78 rule closure_rule { \<\{ <code> \}\> }
80 rule match_alias { <[$@%]> [ \< <ident> \> | \d+ ] [ \s* \:= <term> ]? }
82 rule interpolate_alias { <[$@%]> <name> [ \s* \:= <term> ]? }
84 rule closure { \{ <code> \} }
86 rule assertions { \^\^? | \$\$? }
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.
92 rule rxmodinternal { \\ <[bBdDeEfFhHnNrRsStTvVwW]> }
94 # XXX: PGE doesn't know how to handle \s in enumerated character
95 # classes yet, so we'll explicitly list a space below.
96 rule metachar { <[ \\<>{}[]()@#$%^&|]> }
99 [ <-[ \\%*+?:|.^$@[]()<>{}]> # actually, should be <-metachar>
100 | <hexadecimal_character>
105 rule hexadecimal_character { \\ <[xX]> <xdigit>+ }
107 rule named_character { \\[cC] \[ <-[]]>+ \] }
111 Patrick Michaud (pmichaud@pobox.com) is the author and maintainer.
112 Patches and suggestions are welcome on the Perl 6 compiler list
113 (perl6-compiler@perl.org).