Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implement integer case of :60[...]
  • Loading branch information
moritz committed Sep 29, 2012
1 parent d14be4f commit 8365f1b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Perl6/Actions.pm
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Grammar.pm
Expand Up @@ -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'>
]
Expand Down
8 changes: 8 additions & 0 deletions src/core/Str.pm
Expand Up @@ -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('');
Expand Down

0 comments on commit 8365f1b

Please sign in to comment.