Permalink
Browse files

implement integer case of :60[...]

  • Loading branch information...
1 parent d14be4f commit 8365f1bc812836161f31469bf3955033bdc338d9 @moritz moritz committed Sep 29, 2012
Showing with 14 additions and 2 deletions.
  1. +5 −1 src/Perl6/Actions.pm
  2. +1 −1 src/Perl6/Grammar.pm
  3. +8 −0 src/core/Str.pm
@@ -4616,7 +4616,11 @@ class Perl6::Actions is HLL::Actions {
method rad_number($/) {
my $radix := +($<radix>.Str);
- if $<circumfix> {
+ if $<bracket> {
+ make QAST::Op.new(:name('&unbase_bracket'), :op('call'),
+ $*W.add_numeric_constant('Int', $radix), $<bracket>.ast);
+ }
+ elsif $<circumfix> {
make QAST::Op.new(:name('&unbase'), :op('call'),
$*W.add_numeric_constant('Int', $radix), $<circumfix>.ast);
} else {
@@ -2151,7 +2151,7 @@ grammar Perl6::Grammar is HLL::Grammar {
$<fracpart> = [ '.' <[ 0..9 a..z A..Z ]>+ [ _ <[ 0..9 a..z A..Z ]>+ ]* ]?
[ '*' <base=.radint> '**' <exp=.radint> ]?
'>'
- # || <?before '['> <circumfix>
+ || <?before '['> <bracket=circumfix>
|| <?before '('> <circumfix>
|| <.malformed: 'radix number'>
]
View
@@ -1082,6 +1082,14 @@ sub unbase(Int:D $base, Str:D $str) returns Numeric:D {
":{$base}<$str>".Numeric;
}
}
+# for :16[1, 2, 3]
+sub unbase_bracket($base, @a) {
+ my $v = 0;
+ for @a {
+ $v = $v * $base + $_;
+ }
+ $v;
+}
sub chrs(*@c) returns Str:D {
@c.map({.chr}).join('');

0 comments on commit 8365f1b

Please sign in to comment.