Skip Menu |
Report information
Id: 111518
Status: open
Priority: 0/
Queue: perl6

Owner: pmichaud <pmichaud [at] pobox.com>
Requestors: masak <cmasak [at] gmail.com>
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] Regex engine doesn't publish match variables early enough in some cases in Rakudo
Date: Sat, 3 Mar 2012 18:28:54 +0100
To: rakudobug [...] perl.org
From: Carl Mäsak <cmasak [...] gmail.com>
Download (untitled) / with headers
text/plain 587b
<masak> nom: grammar G { regex TOP { (foo) <.panic: "!$0!"> }; method panic($m) { die $m } }; G.parse("foo") <p6eval> nom efad32: OUTPUT«!!␤ in method panic [...] <masak> why doesn't this output '!foo!'? <jnthn> hm <masak> also, is there a workaround? :) <moritz> yes, a block <moritz> the problem is basically that the regex engine doesn't publish match variables unless it is deemed necessary <moritz> and when parsing argument strings, that doesn't happen (but it should) <jnthn> moritz: Yeah, it's that. <jnthn> moritz: Just hit on the same conclusion. * masak submits rakudobug
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.9k
<TimToady> rn: say 1001110011 ~~ /^ (.+) $0+ @([\~] $0.comb)? $ / <camelia> niecza v24-48-g1d127e4: OUTPUT«「1001110011」␤ 0 => 「10011」␤␤» <camelia> ..rakudo bfd850: OUTPUT«No such method 'comb' for invocant of type 'Any'␤ in regex at /tmp/OHj0MG5jaw:1␤ in method ACCEPTS at src/gen/CORE.setting:10370␤ in method ACCEPTS at src/gen/CORE.setting:683␤ in block at /tmp/OHj0MG5jaw:1␤␤» * TimToady thinks rakudo is running the innards of @() too soon * masak submits TimToady's rakudobug <jnthn> TimToady, masak: I doubt it's about "too early" so much as $/ not being up to date enough. <TimToady> (btw, that's a short implementatoin of <*$0> there...) <TimToady> probably not very speedy, but still <jnthn> To test that hypothesis, but a {} before the @(...) <TimToady> rn: say 1110111011 ~~ /^ (.+) $0+ {} @([\~] $0.comb)? $ / <camelia> rakudo bfd850, niecza v24-48-g1d127e4: OUTPUT«「1110111011」␤ 0 => 「1110」␤␤» <jnthn> Yup, it's that. <TimToady> huh <jnthn> masak: There's already an RT ticket about $/ stuff. <jnthn> masak: So may want to add it (or ref it) <jnthn> TimToady: I think it's just that @foo only used to interpolate and not have the chance to run code. <masak> jnthn: ok, gotcha. <jnthn> TimToady: In Rakudo, Match is constructed from the stack of captures Cursor collects. <TimToady> then how does the first $0 work, if $/ is delayed? <jnthn> TimToady: iirc, $0 is parsed explicitly as a back-reference and handled separately. <masak> jnthn: can't find such an RT ticket. <jnthn> masak: I think the title of the ticked used the word "published" and "match variables", maybe not $/ <TimToady> well, the main point of reversing the meaning of $foo in regex was so that $0 could be treated like a normal variable, and vice versa... <jnthn> TimToady: May still be performant to treat them separately. <jnthn> TimToady: Certainly is in the Rakudo engine, anyway. <TimToady> :) <masak> found the RT ticket. jnthn++ :) * masak adds today's musings
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 562b
As a status update: The example from the original post still does not work: $ perl6-m -e 'grammar G { regex TOP { (foo) <.panic: "!$0!"> }; method panic($m) { die $m } }; G.parse("foo")' Use of Nil in string context in regex TOP at -e:1 !! in method panic at -e:1 in regex TOP at -e:1 in block <unit> at -e:1 The first example from the added irclog gives the expected result now (the same, niecza gave): $ perl6-m -e 'say 1001110011 ~~ /^ (.+) $0+ @([\~] $0.comb)? $ /' Use of Nil in string context in regex at -e:1 「1001110011」 0 => 「10011」
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 385b
On Thu Nov 12 11:49:18 2015, bartolin@gmx.de wrote: Show quoted text
> The first example from the added irclog gives the expected result now > (the same, niecza gave): > > $ perl6-m -e 'say 1001110011 ~~ /^ (.+) $0+ @([\~] $0.comb)? $ /' > Use of Nil in string context in regex at -e:1 > 「1001110011」 > 0 => 「10011」
Oops, I overlooked the warning! So, the problem seems to be still there.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org