Skip to content

Commit

Permalink
Update Match, Cursor, and Capture objects. Indexed access to
Browse files Browse the repository at this point in the history
match objects now works.
  • Loading branch information
pmichaud committed Jul 14, 2011
1 parent 5aecd55 commit d5a8c7e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 20 deletions.
31 changes: 30 additions & 1 deletion src/core/Capture.pm
@@ -1 +1,30 @@
my class Capture { }
my class Capture {
has Mu $!list;
has Mu $!hash;

submethod BUILD(:$!list, :$!hash) { }

method at_key($key is copy) {
$key = $key.Str;
nqp::existskey($!hash, nqp::unbox_s($key))
?? nqp::atkey($!hash, nqp::unbox_s($key))
!! Any
}

method at_pos($pos is copy) {
$pos = $pos.Int;
nqp::existspos($!list, nqp::unbox_i($pos))
?? nqp::atpos($!list, nqp::unbox_i($pos))
!! Any
}

method hash() {
my $enum := new::create(EnumMap);
nqp::bindattr($enum, EnumMap, '$!storage', $!hash);
$enum;
}

method list() {
nqp::p6list($!list, List, Mu);
}
}
31 changes: 17 additions & 14 deletions src/core/Cursor.pm
@@ -1,24 +1,27 @@
my class Cursor does NQPCursorRole {
method MATCHBUILD(|$) {
my Mu $args := pir::perl6_current_args_rpa__P();
nqp::shift($args);
my Mu $orig := nqp::shift($args);
my Mu $from := nqp::shift($args);
my Mu $to := nqp::shift($args);
my Mu $capsiter := nqp::iterator(nqp::shift($args));
method MATCH() {
my Mu $list := nqp::list();
my Mu $hash := nqp::hash();
while $capsiter {
my Mu $pair := nqp::shift($capsiter);
my Mu $key := $pair.key;
my Mu $caphash := pir::find_method__PPs(Cursor, 'CAPHASH')(self);
my Mu $capiter := nqp::iterator($caphash);
while $capiter {
my Mu $pair := nqp::shift($capiter);
my str $key = $pair.key;
my Mu $value := $pair.value;
$value := nqp::p6list($value, List, Bool::True)
$value := nqp::p6list($value, List, Mu)
if pir::isa__IPs($value, 'ResizablePMCArray');
nqp::iscclass(pir::const::CCLASS_NUMERIC, $key, 0)
?? nqp::bindpos($list, $key, $value)
!! nqp::bindkey($list, $key, $value);
!! nqp::bindkey($hash, $key, $value);
}
Match.new(:$orig, :$from, :$to,
:list(nqp::p6list($list, List, Mu)))
my $match := Match.new(
orig => nqp::getattr(self, Cursor, '$!orig'),
from => nqp::p6box_i(nqp::getattr_i(self, Cursor, '$!from')),
to => nqp::p6box_i(nqp::getattr_i(self, Cursor, '$!pos')),
);
nqp::bindattr($match, Capture, '$!list', $list);
nqp::bindattr($match, Capture, '$!hash', $hash);
$match;
}
}

8 changes: 4 additions & 4 deletions src/core/Match.pm
@@ -1,10 +1,10 @@
my class Match #`(is Capture) {
my class Match is Capture {
has $.orig;
has $.from;
has $.to;
has $.list;
has $.CURSOR;

multi method Str(Match:D:) {
$!to > $!from ?? $!orig.substr($!from, $!to-$!from) !! '';
multi method Str(Match:D:) {
$!to > $!from ?? $!orig.substr($!from, $!to-$!from) !! '';
}
}
2 changes: 1 addition & 1 deletion tools/build/NQP_REVISION
@@ -1 +1 @@
2011.06-116-g69cc5ac
2011.06-118-g985fd7d

0 comments on commit d5a8c7e

Please sign in to comment.