Author: moritz
Date: 2009-05-27 09:47:44 +0200 (Wed, 27 May 2009)
New Revision: 26941
Modified:
docs/Perl6/Spec/S05-regex.pod
Log:
[S05] document action stubs
Modified: docs/Perl6/Spec/S05-regex.pod
===================================================================
--- docs/Perl6/Spec/S05-regex.pod 2009-05-26 23:59:45 UTC (rev 26940)
+++ docs/Perl6/Spec/S05-regex.pod 2009-05-27 07:47:44 UTC (rev 26941)
@@ -3714,6 +3714,30 @@
token funnylang { '{' [ :lang($funnylang.unbalanced('}')) <expr> ] '}' }
+=item *
+
+A string can be matched against a grammar by calling C<.parse> on the grammar,
+and optionally pass an I<action> object to that grammar:
+
+ MyGrammar.parse($str, :action($action-object))
+
+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.
+
+ grammar Integer {
+ token TOP {
+ \d+ {*}
+ }
+ }
+ class Twice {
+ method TOP($/) {
+ make 2 * $/;
+ }
+ }
+ Integer.parse('21', :action(Twice.new)).ast # 42
+
=back
=head1 Syntactic categories