Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement Capture.WHICH
  • Loading branch information
lizmat committed Apr 13, 2014
1 parent 91f41bd commit c855a0f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core/Capture.pm
Expand Up @@ -11,6 +11,22 @@ my class Capture { # declared in BOOTSTRAP
nqp::bindattr(self, Capture, '$!hash', nqp::ishash($hs) ?? $hs !! nqp::hash());
1;
}
submethod WHICH {
my $WHICH = self.^name;
if self.defined {
if $!list {
$WHICH ~= '|';
$WHICH ~= ( '(' ~ $_.WHICH ~ ')' )
for $!list;
}
if $!hash {
$WHICH ~= '|';
$WHICH ~= ( $_ ~ '(' ~ $!hash{$_}.WHICH ~ ')' )
for $!hash.keys.sort;
}
}
$WHICH;
}

method at_key(Capture:D: $key is copy) {
$key = $key.Str;
Expand Down
10 changes: 10 additions & 0 deletions src/core/core_epilogue.pm
Expand Up @@ -14,6 +14,16 @@ BEGIN {
Perl6::Metamodel::GrammarHOW.HOW.compose(Perl6::Metamodel::GrammarHOW);
}

multi sub trait_mod:<is>(Routine $r, :$cached!) {
my %cache;
$r.wrap(-> |c {
my $WHICH := c.WHICH;
%cache{$WHICH}:exists
?? %cache{$WHICH}
!! (%cache{$WHICH} = callsame);
});
}

{YOU_ARE_HERE}

# vim: ft=perl6 expandtab sw=4

0 comments on commit c855a0f

Please sign in to comment.