Skip to content

Commit

Permalink
Make NQPCursor.parse able to handle being passed an invokable rule. S…
Browse files Browse the repository at this point in the history
…ketch in NQPRegexMethod and NQPRegex classes, as QRegexy replacements for Regex::Method and Regex::Regex.
  • Loading branch information
jnthn committed Nov 15, 2011
1 parent 6efeb3c commit 3611d39
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/QRegex/Cursor.nqp
Expand Up @@ -388,10 +388,30 @@ class NQPCursor does NQPCursorRole {
method parse($target, :$rule = 'TOP', :$actions, *%options) {
my $*ACTIONS := $actions;
my $cur := self.'!cursor_init'($target, |%options);
pir::find_method__PPs($cur, $rule)($cur).MATCH()
pir::is_invokable__IP($rule) ??
$rule($cur).MATCH() !!
pir::find_method__PPs($cur, $rule)($cur).MATCH()
}
}

class NQPRegexMethod {
has $!code is parrot_vtable_handler('invoke');
method new($code) {
self.bless(:code($code));
}
method ACCEPTS($target) {
NQPCursor.parse($target, :rule(self))
}
method Str() is parrot_vtable('get_string') {
~$!code
}
}

class NQPRegex is NQPRegexMethod {
method ACCEPTS($target) {
NQPCursor.parse($target, :rule(self), :c(0))
}
}

my module EXPORT {
our module DEFAULT {
Expand Down

0 comments on commit 3611d39

Please sign in to comment.