Skip to content

Instantly share code, notes, and snippets.

/patch.diff Secret

Created February 16, 2013 18:56
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/56528571cbfe83f76cba to your computer and use it in GitHub Desktop.
Save anonymous/56528571cbfe83f76cba to your computer and use it in GitHub Desktop.
\o/ Next: add LTM for arrays in regexes
diff --git a/src/core/Cursor.pm b/src/core/Cursor.pm
index 537b182..a9775ea 100644
--- a/src/core/Cursor.pm
+++ b/src/core/Cursor.pm
@@ -46,9 +46,36 @@ my class Cursor does NQPCursorRole {
}
method INTERPOLATE($var, $i = 0) {
- nqp::isconcrete($var) ??
- ($var ~~ Callable ?? $var(self) !! self."!LITERAL"(nqp::unbox_s($var.Str), $i)) !!
- self."!cursor_start_cur"()
+ if nqp::istype($var, Positional) {
+ my $maxlen := -1;
+ my $cur := self.'!cursor_start_cur'();
+ my $pos := nqp::getattr_i($cur, $?CLASS, '$!from');
+ my $tgt := $cur.target;
+ my $eos := nqp::chars($tgt);
+ for $var.list {
+ if nqp::isconcrete($_) {
+ if $_ ~~ Callable {
+ # $_(self)
+ }
+ else {
+ # self."!LITERAL"(nqp::unbox_s($_.Str), $i)
+ my $len := nqp::chars($_);
+ $maxlen := $len if $len > $maxlen && $pos + $len <= $eos
+ && nqp::substr($tgt, $pos, $len) eq $_;
+ }
+ }
+ else {
+ # $cur ?
+ }
+ }
+ $cur.'!cursor_pass'($pos + $maxlen, '') if $maxlen >= 0;
+ return $cur;
+ }
+ else {
+ nqp::isconcrete($var) ??
+ ($var ~~ Callable ?? $var(self) !! self."!LITERAL"(nqp::unbox_s($var.Str), $i)) !!
+ self."!cursor_start_cur"()
+ }
}
method OTHERGRAMMAR($grammar, $name, |) {
Test Summary Report
-------------------
t/spec/S05-interpolation/regex-in-variable.rakudo (Wstat: 0 Tests: 33 Failed: 0)
TODO passed: 24
t/spec/S05-metasyntax/litvar.rakudo (Wstat: 0 Tests: 34 Failed: 0)
TODO passed: 24-26, 28-29
t/spec/S05-metasyntax/sequential-alternation.rakudo (Wstat: 0 Tests: 10 Failed: 0)
TODO passed: 7, 9
Files=723, Tests=26812, 709 wallclock secs ( 9.25 usr 1.44 sys + 2147.13 cusr 143.94 csys = 2301.76 CPU)
Result: PASS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment