Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add method Label.gist, .redo and .next
Label.gist looks like this (with colors):
perl6-m -e 'my $x; my $y; BAR: while $x++ < 2 { }; say BAR'
Label<BAR>(at -e:1, 'my $x; my $y; ⏏BAR:while $x++ < 2 { };')
  • Loading branch information
FROGGS committed Apr 28, 2014
1 parent ed78569 commit a08ae07
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Perl6/Grammar.nqp
Expand Up @@ -1105,7 +1105,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
<identifier> ':' <?[\s]> <.ws>
{
$*LABEL := ~$<identifier>;
my $label := $*W.find_symbol(['Label']).new($*LABEL);
my $label := $*W.find_symbol(['Label']).new( :name($*LABEL), :match($/) );
$*W.add_object($label);
$*W.install_lexical_symbol($*W.cur_lexpad(), $*LABEL, $label);
}
Expand Down
42 changes: 37 additions & 5 deletions src/core/PseudoStash.pm
Expand Up @@ -3,21 +3,53 @@ my class X::Caller::NotDynamic { ... }

my class Label {
has Str $!name;
method new($name) {
has Mu $!match;
method new(:$name, Mu :$match) {
# XXX register in &?BLOCK.labels
my $obj := nqp::create(self);
nqp::bindattr($obj, Label, '$!name', $name);
nqp::bindattr($obj, Label, '$!name', $name);
nqp::bindattr($obj, Label, '$!match', $match);
$obj
}
method name() {
$!name
}
method match() {
$!match
}
# XXX method leave(@args)
# XXX method goto
# XXX method next
method gist() {
my $file = nqp::getlexdyn('$?FILES');
$file = nqp::box_s((nqp::isnull($file) ?? '<unknown file>' !! $file), Str);
my $line = HLL::Compiler.lineof($!match.orig, $!match.from);
my $left = nqp::substr($!match.orig, 0, $!match.from);
my $right = nqp::substr($!match.orig, $!match.to, $!match.orig.chars - $!match.to);
$left = $left.match(/ \N ** 0..20 $/).Str.trim-leading;
$right = $right.match(/^ \N ** 0..20 /).Str.trim-trailing;

my $color = %*ENV<RAKUDO_ERROR_COLOR> // $*OS ne 'MSWin32';
my ($red, $green, $yellow, $clear) = $color
?? ("\e[31m", "\e[32m", "\e[33m", "\e[0m")
!! ("", "", "", "");
my $eject = $*OS eq 'MSWin32' ?? "<HERE>" !! "\x[23CF]";

"Label<$!name>(at $file:$line, '$green$left$yellow$eject$red$!name:$green$right$clear')"
}
method next() {
my Mu $ex := nqp::newexception();
nqp::setpayload($ex, self);
nqp::setextype($ex, nqp::const::CONTROL_NEXT + nqp::const::CONTROL_LABELED);
nqp::throw($ex);
}
method redo() {
my Mu $ex := nqp::newexception();
nqp::setpayload($ex, self);
nqp::setextype($ex, nqp::const::CONTROL_REDO + nqp::const::CONTROL_LABELED);
nqp::throw($ex);
}
method last() {
say $!name ~ '.last called';
my Mu $ex := nqp::newexception();
my Mu $ex := nqp::newexception();
nqp::setpayload($ex, self);
nqp::setextype($ex, nqp::const::CONTROL_LAST + nqp::const::CONTROL_LABELED);
nqp::throw($ex);
Expand Down

0 comments on commit a08ae07

Please sign in to comment.