On Jul 17, 2008, at 9:41 PM, Patrick R. Michaud wrote:

On Thu, Jul 17, 2008 at 02:20:33PM -0500, Chris Fields wrote:
Okay, I'll set it up so "$foo = 'abcd'.match(/<alpha>+/)" returns a
Match object, and $/ would remain unset.  Makes sense to me.

Right now the match object is converted over to a Str; I'll take a
look at the parser grammar/actions to see if that can be fixed.

It is?  That's odd and shouldn't be happening -- something must
be incorrect there.

Pm


The PGE::Match appears to be converted to a Str, regardless of the invoking object type. The following is .match (in any-str.pir, with the builtins). Also, .ACCEPTS now uses .match to retrieve the Match object.

# any-str.pir

.sub 'match' :method :multi(_)
    .param pmc x
    .local pmc match
    match = x(self)
    .return (match)
.end

# Code.pir

.sub 'ACCEPTS' :method
    .param pmc topic
    .local pmc match
    match = topic.'match'(self)
    $P0 = getinterp
    $P1 = $P0['lexpad';1]
    $P1['$/'] = match
    .return (match)
.end

the following is a test p6 script (results in comments):

my $x = '123.456';
my $y = $x.match(/\d+/);
say $x;        # 123.456
say $x.WHAT;   # Str
say $y;        # 123
say $y.WHAT;   # Str <- Should be Match

$x = 123.456;
$y = $x.match(/\d+/);
say $x;        # 123.456
say $x.WHAT;   # Num
say $y;        # 123
say $y.WHAT;   # Str <- Should be Match

say $/;        # Nothing
say $/.WHAT;   # Failure, .match doesn't set $/

$x ~~ /\d+/;
say $/;        # 123
say $/.WHAT;   # Match

As shown above, calling .match from .ACCEPTS (either using smart match or using /\d+/.ACCEPTS($x) ) works fine, but calling .match as a method from p6 doesn't. Makes me think it's a mapping issue.

chris

Reply via email to