Skip to content

Commit

Permalink
Try reporting what was expected at high watermark.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Dec 8, 2012
1 parent 53daeff commit 4068131
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/Perl6/World.pm
Expand Up @@ -2011,16 +2011,26 @@ class Perl6::World is HLL::World {
# If the highwater is beyond the current position, force the cursor to
# that location.
my $c := $/.CURSOR;
if $c.'!highwater'() > $c.pos() {
my @expected;
if $c.'!highwater'() >= $c.pos() {
my @raw_expected := $c.'!highexpect'();
$c.'!cursor_pos'($c.'!highwater'());
my %seen;
for @raw_expected {
unless %seen{$_} {
nqp::push(@expected, $_);
%seen{$_} := 1;
}
}
}

# Build and throw exception object.
my @locprepost := self.locprepost($c);
%opts<line> := HLL::Compiler.lineof($c.orig, $c.pos);
%opts<modules> := p6ize_recursive(@*MODULES);
%opts<pre> := @locprepost[0];
%opts<post> := @locprepost[1];
my @locprepost := self.locprepost($c);
%opts<line> := HLL::Compiler.lineof($c.orig, $c.pos);
%opts<modules> := p6ize_recursive(@*MODULES);
%opts<pre> := @locprepost[0];
%opts<post> := @locprepost[1];
%opts<expected> := p6ize_recursive(@expected) if @expected;
%opts<is-compile-time> := 1;
for %opts -> $p {
if nqp::islist($p.value) {
Expand Down
7 changes: 7 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -309,6 +309,7 @@ my role X::Comp is Exception {
has $.is-compile-time = False;
has $.pre;
has $.post;
has @.expected;
multi method gist(::?CLASS:D:) {
if $.is-compile-time {
my $color = %*ENV<RAKUDO_ERROR_COLOR> // $*OS ne 'MSWin32';
Expand All @@ -318,6 +319,12 @@ my role X::Comp is Exception {
my $eject = $*OS eq 'MSWin32' ?? "<HERE>" !! "\x[23CF]";
my $r = "$red==={$clear}SORRY!$red===$clear\n$.message\nat $.filename():$.line\n------> ";
$r ~= "$green$.pre$yellow$eject$red$.post$clear" if defined $.pre;
if @.expected {
$r ~= "\n expecting any of:";
for @.expected {
$r ~= "\n $_";
}
}
for @.modules.reverse[1..*] {
$r ~= $_<module>.defined
?? "\n from module $_<module> ($_<filename>:$_<line>)"
Expand Down

0 comments on commit 4068131

Please sign in to comment.