Author: lwall Date: 2009-09-02 19:09:15 +0200 (Wed, 02 Sep 2009) New Revision: 28169
Modified: docs/Perl6/Spec/S05-regex.pod Log: [S05] document how :my works in regexen Modified: docs/Perl6/Spec/S05-regex.pod =================================================================== --- docs/Perl6/Spec/S05-regex.pod 2009-09-02 16:35:17 UTC (rev 28168) +++ docs/Perl6/Spec/S05-regex.pod 2009-09-02 17:09:15 UTC (rev 28169) @@ -16,8 +16,8 @@ Created: 24 Jun 2002 - Last Modified: 11 Aug 2009 - Version: 101 + Last Modified: 2 Sep 2009 + Version: 102 This document summarizes Apocalypse 5, which is about the new regex syntax. We now try to call them I<regex> rather than "regular @@ -554,6 +554,29 @@ m:fuzzy(fuzzyargs); pattern ; +=item * + +Any grammar regex is really just a kind of method, and you may +declare variables in such a routine using a colon followed by any +scope declarator parsed by the Perl6 grammar, including C<my>, +C<our>, C<state>, and C<constant>. A single statement (up through +a terminating semicolon) is parsed as normal Perl 6 code: + + token prove-nondeterministic-parsing { + :my $threshold = rand; + 'maybe' \s+ <it($threshold)> + } + +Such declarations do not terminate longest-token-matching, +so an otherwise useless declaration may be used as a peg +to hang side effects on without changing how the subsequent +pattern matches: + + rule breaker { + :state $ = say "got here at least once"; + ... + } + =back =head1 Changed metacharacters