[t] Refactor some namespace pmc tests to use throws_like
[parrot.git] / compilers / pge / P6Rule.grammar
blobc3ded6978ee5301a6d5185aa61498cb19f9a1da1
1 =pod
3 PGE::P6Rule Grammar
5 =head1 DESCRIPTION
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.
17 =cut
19 grammar PGE::P6Rule;
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.
44 rule 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>
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 { <[ \\<>{}[]()@#$%^&|]> }
98 rule literal { 
99    [ <-[ \\%*+?:|.^$@[]()<>{}]>         # actually, should be <-metachar>
100    | <hexadecimal_character>
101    | <named_character>
102    | \\<metachar> 
103    ]+ }
105 rule hexadecimal_character { \\ <[xX]> <xdigit>+ }
107 rule named_character { \\[cC] \[ <-[]]>+ \] }
109 =head1 AUTHOR
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).
115 =cut