Skip to content

Instantly share code, notes, and snippets.

Created July 13, 2011 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1081042 to your computer and use it in GitHub Desktop.
Save anonymous/1081042 to your computer and use it in GitHub Desktop.
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