Author: masak
Date: 2009-12-06 03:53:21 +0100 (Sun, 06 Dec 2009)
New Revision: 29267
Modified:
docs/Perl6/Spec/S05-regex.pod
Log:
[S05] further improvements to :actions example
Suggested by uasi++ on Twitter
Modified: docs/Perl6/Spec/S05-regex.pod
===================================================================
--- docs/Perl6/Spec/S05-regex.pod 2009-12-06 02:39:02 UTC (rev 29266)
+++ docs/Perl6/Spec/S05-regex.pod 2009-12-06 02:53:21 UTC (rev 29267)
@@ -17,7 +17,7 @@
Created: 24 Jun 2002
Last Modified: 6 Dec 2009
- Version: 112
+ Version: 113
This document summarizes Apocalypse 5, which is about the new regex
syntax. We now try to call them I<regex> rather than "regular
@@ -3799,15 +3799,12 @@
}
class Twice {
multi method TOP($/, $tag) {
- my $text = ~$/;
- $text = :2($text) if $tag eq 'binary';
+ my $text = $tag eq 'binary' ?? :2($0) !! ~$/;
make $text;
}
- multi method TOP($/) {
- make 2 * $/.ast;
- }
}
- Integer.parse('21', :actions(Twice.new)).ast # 42
+ say Integer.parse('21', :actions(Twice.new)).ast; # 42
+ say Integer.parse('0b10101', :actions(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