Author: lwall Date: 2009-05-28 18:55:52 +0200 (Thu, 28 May 2009) New Revision: 26953
Modified: docs/Perl6/Spec/S05-regex.pod Log: [S05] document use of #= tags in {*} actions Modified: docs/Perl6/Spec/S05-regex.pod =================================================================== --- docs/Perl6/Spec/S05-regex.pod 2009-05-28 07:40:29 UTC (rev 26952) +++ docs/Perl6/Spec/S05-regex.pod 2009-05-28 16:55:52 UTC (rev 26953) @@ -3723,21 +3723,33 @@ Whenever a closure within the grammar returns a C<Whatever> object, the grammar engine tries to call a method of the same name as the name of the -current regex on the action object, passing along the current Match object as -the first positional argument. +current regex on the action object, passing along the current C<Match> object as +the first positional argument, and the tag of the reduction (if any) as the second +argument. The tag is supplied via a C<#=> comment on the same line as the C<{*}>. grammar Integer { token TOP { - \d+ {*} + | 0b<[01]>+ {*} #= binary + | \d+ {*} #= decimal } } class Twice { - method TOP($/) { - make 2 * $/; + multi method TOP($match, $tag) { + my $text = ~$match; + $text = :2($text) if $tag eq 'binary' + make $text; } + multi method TOP($match) { + make 2 * $match.ast; + } } Integer.parse('21', :action(Twice.new)).ast # 42 +A C<{*}> is assumed at the end of every rule, and the method is +called with no tag argument. Note that the implicit C<{*}> is +I<outside> the alternation in the C<TOP> rule above, despite +the fact that no explicit square brackets were used. + =back =head1 Syntactic categories