Permalink
Browse files

first cut at \!INTERPOLATE and \!INTERPOLATE_REGEX. strange number co…

…nversion workarounds and errors for jnthn++ to debug.
  • Loading branch information...
diakopter committed Nov 22, 2011
1 parent 734d9f3 commit 137dd0611604ea5161052296b1298e8d1c70a1b8
Showing with 61 additions and 3 deletions.
  1. +3 −3 src/NQPQ/Actions.pm
  2. +58 −0 src/QRegex/Cursor.nqp
View
6 src/NQPQ/Actions.pm 100644 → 100755
@@ -1505,12 +1505,12 @@ class NQP::RegexActions is QRegex::P6Regex::Actions {
}
method metachar:sym<nqpvar>($/) {
make QAST::Regex.new( '!INTERPOLATE', $<var>.ast,
make QAST::Regex.new( PAST::Node.new('!INTERPOLATE', $<var>.ast),
:rxtype<subrule>, :subtype<method>, :node($/));
}
method assertion:sym<{ }>($/) {
make QAST::Regex.new( '!INTERPOLATE_REGEX', $<codeblock>.ast,
make QAST::Regex.new( PAST::Node.new('!INTERPOLATE_REGEX', $<codeblock>.ast),
:rxtype<subrule>, :subtype<method>, :node($/));
}
@@ -1521,7 +1521,7 @@ class NQP::RegexActions is QRegex::P6Regex::Actions {
}
method assertion:sym<var>($/) {
make QAST::Regex.new( '!INTERPOLATE_REGEX', $<var>.ast,
make QAST::Regex.new( PAST::Node.new('!INTERPOLATE_REGEX', $<var>.ast),
:rxtype<subrule>, :subtype<method>, :node($/));
}
View
58 src/QRegex/Cursor.nqp 100644 → 100755
@@ -416,6 +416,64 @@ class NQPCursor does NQPCursorRole {
$rule($cur).MATCH() !!
pir::find_method__PPs($cur, $rule)($cur).MATCH()
}
method !INTERPOLATE($var) {
if pir::does($var, 'array') {
my $maxlen := -1.0;
my $cur := self.'!cursor_start'();
my $pos := +$cur.from;
my $tgt := $cur.target;
my $eos := +pir::length($tgt);
for $var {
if pir::is_invokable__IP($_) {
my $res := $_(self);
if $res {
my $adv := +$res.pos;
$adv := $adv - $pos;
$maxlen := $adv if $adv > $maxlen;
}
}
else {
my $len := pir::length($_);
$maxlen := $len if $len > $maxlen && $pos + $len <= $eos
&& pir::substr($tgt, $pos, $len) eq $_;
}
}
return $cur if $maxlen < 0;
return $cur.'!cursor_pass'($pos + $maxlen, '');
}
else {
return $var(self) if pir::is_invokable__IP($var);
my $cur := self.'!cursor_start'();
my $pos := +$cur.from;
my $tgt := $cur.target;
my $len := +pir::length($var);
my $adv := $pos + $len;
return $cur if $adv > pir::length($tgt)
|| pir::substr($tgt, $pos, $len) ne $var;
$cur.'!cursor_pass'($adv, '');
return $cur;
}
}
method !INTERPOLATE_REGEX($var) {
unless pir::is_invokable__IP($var) {
my $rxcompiler := pir::compreg__Ps('QRegex::P6Regex');
if pir::does($var, 'array') {
my $res := [];
for $var {
my $elem := $_;
$elem := $rxcompiler.compile($elem) unless pir::is_invokable__IP($elem);
nqp::push($res, $elem);
}
$var := $res;
}
else {
$var := $rxcompiler.compile($var);
}
}
return self.'!INTERPOLATE'($var);
}
}
class NQPRegexMethod {

0 comments on commit 137dd06

Please sign in to comment.