Created
July 13, 2011 19:01
-
-
Save anonymous/1081042 to your computer and use it in GitHub Desktop.
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
pmichaud@kiwi:~/nom$ cat z | |
my class MyCursor 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)); | |
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 $value := $pair.value; | |
$value := nqp::p6list($value, List, Bool::True) | |
if pir::isa__IPs($value, 'ResizablePMCArray'); | |
nqp::iscclass(pir::const::CCLASS_NUMERIC, $key, 0) | |
?? nqp::bindpos($list, $key, $value) | |
!! nqp::bindkey($list, $key, $value); | |
} | |
Match.new(:$orig, :$from, :$to, | |
:list(nqp::p6list($list, List, Mu))) | |
} | |
} | |
my $cursor := MyCursor."!cursor_init"('hello world'); | |
my $regex := anon regex { (\S+) \s+ (\S+) }; | |
my $m = $cursor.$regex().MATCH; | |
say $m.list[0]; | |
say $m.list[1]; | |
pmichaud@kiwi:~/nom$ ./perl6 z | |
hello | |
world | |
pmichaud@kiwi:~/nom$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment