Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Captureless Matches generically get pseudo [0]
  • Loading branch information
sorear committed Feb 25, 2011
1 parent 891071d commit c7b4852
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/Cursor.cs
Expand Up @@ -585,11 +585,15 @@ public Cursor(IP6 proto, string text, IP6 actions)
it = it.prev;
}

if (str == "0" && caps.Count() == 0)
caps.Unshift(Kernel.NewROScalar(this));

return FixupList(caps);
}

public void UnpackCaps(IP6 into) {
List<VarDeque> posr = new List<VarDeque>();
posr.Add(new VarDeque());
Dictionary<string,VarDeque> namr = new Dictionary<string,VarDeque>();
CapInfo it = captures;

Expand All @@ -609,6 +613,9 @@ public Cursor(IP6 proto, string text, IP6 actions)
it = it.prev;
}

if (posr[0].Count() == 0)
posr[0].Unshift(Kernel.NewROScalar(this));

VarHash nam = new VarHash();
Variable[] pos = new Variable[posr.Count];

Expand Down
4 changes: 1 addition & 3 deletions lib/SAFE.setting
Expand Up @@ -1024,9 +1024,7 @@ my class Regex is Sub {
(ternary (iter_hasflat (l iter))
(letn val (vvarlist_shift (l iter))
(set_status (s $*/) (l val))
(return (ternary
(obj_getdef (obj_at_key (l val) {"0"}))
(newrwlistvar (@ (l val))) (l val))))
(return (newrwlistvar (@ (l val))) (l val)))
(prog))))
(set_status (s $*/) {Match})
{Any})
Expand Down
5 changes: 5 additions & 0 deletions test2.pl
Expand Up @@ -2,6 +2,11 @@
use Test;
use MONKEY_TYPING;

{
"foo" ~~ /\w+/;
is $0, "foo", 'Match[0] returns whole match if no parens';
}

#is $?FILE, 'test.pl', '$?FILE works';
#is $?ORIG.substr(0,5), '# vim', '$?ORIG works';

Expand Down

0 comments on commit c7b4852

Please sign in to comment.