Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Match, Cursor, and Capture objects. Indexed access to
match objects now works.
- Loading branch information
Showing
4 changed files
with
52 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) !! ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2011.06-116-g69cc5ac | ||
2011.06-118-g985fd7d |