Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'nom' of github.com:rakudo/rakudo into nom
  • Loading branch information
pmichaud committed Mar 25, 2012
2 parents b1acd74 + 34c3e35 commit 57a6818
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
20 changes: 20 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -508,4 +508,24 @@ my class X::Phaser::PrePost is Exception {
}
}

my class X::Str::Numeric is Exception {
has $.source;
has $.pos;
has $.reason;
method source-indicator {
constant marker = chr(0x23CF);
join '', "in '",
$.source.substr(0, $.pos),
marker,
$.source.substr($.pos),
"' (indicated by the ",
marker,
" symbol)",
;
}
method message() {
"Cannot convert string to number: $.reason $.source-indicator";
}
}

# vim: ft=perl6
26 changes: 9 additions & 17 deletions src/core/Failure.pm
Expand Up @@ -23,34 +23,26 @@ my class Failure {
}
multi method Bool(Failure:D:) { $!handled = 1; Bool::False; }

method Int(Failure:D:) { $!handled ?? 0 !! $!exception.throw; }
method Num(Failure:D:) { $!handled ?? 0e0 !! $!exception.throw; }
multi method Str(Failure:D:) { $!handled ?? '' !! $!exception.throw; }
method Int(Failure:D:) { $!handled ?? 0 !! $!exception.throw; }
method Num(Failure:D:) { $!handled ?? 0e0 !! $!exception.throw; }
method Numeric(Failure:D:) { $!handled ?? 0e0 !! $!exception.throw; }
multi method Str(Failure:D:) { $!handled ?? '' !! $!exception.throw; }
multi method gist(Failure:D:) { $!handled ?? $.perl !! $!exception.throw; }

Failure.^add_fallback(
-> $, $ { True },
method ($name) {
die $!exception;
$!exception.throw;
}
);
}


my &fail := -> *@msg {
my $value = @msg.join('');
my $value = @msg == 1 ?? @msg[0] !! @msg.join('');
die $value if $*FATAL;
my Mu $ex := Q:PIR {
# throw and immediately catch an exception, to capture
# the location at the point of the fail()
push_eh catch
$P0 = find_lex '$value'
$S0 = $P0
die $S0
catch:
.get_results (%r)
pop_eh
};
my $fail := Failure.new(EXCEPTION($ex));
try die $value;
my $fail := Failure.new($!);
my Mu $return := pir::find_caller_lex__Ps('RETURN');
$return($fail) unless nqp::isnull($return);
$fail
Expand Down
9 changes: 6 additions & 3 deletions src/core/Str.pm
Expand Up @@ -2,6 +2,7 @@ my class Cursor {... }
my class Range {... }
my class Match {... }
my class Buf {... }
my class X::Str::Numeric { ... }

sub PARROT_ENCODING(Str:D $s) {
my %map = (
Expand Down Expand Up @@ -161,14 +162,16 @@ my class Str does Stringy {
my int $pos = pir::find_not_cclass__Iisii(pir::const::CCLASS_WHITESPACE, $str, 0, $eos);

my $tailfail =
-> { fail "trailing characters after number in conversion"
if nqp::islt_i(
-> { fail(X::Str::Numeric.new(
source => self,
:$pos,
reason => 'trailing characters after number',
)) if nqp::islt_i(
pir::find_not_cclass__Iisii(pir::const::CCLASS_WHITESPACE,
$str, $pos, $eos),
$eos);
0;
};

# objects for managing the parse and results
my Mu $parse;
my $result;
Expand Down

0 comments on commit 57a6818

Please sign in to comment.