Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex engine doesn't publish match variables early enough in some cases in Rakudo #2662

Open
p6rt opened this issue Mar 3, 2012 · 7 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 3, 2012

Migrated from rt.perl.org#111518 (status was 'open')

Searchable as RT111518$

@p6rt
Copy link
Author

p6rt commented Mar 3, 2012

From @masak

<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

@p6rt
Copy link
Author

p6rt commented May 10, 2013

From @masak

<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

@p6rt
Copy link
Author

p6rt commented May 10, 2013

@masak - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Nov 12, 2015

From @usev6

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」

1 similar comment
@p6rt
Copy link
Author

p6rt commented Nov 12, 2015

From @usev6

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」

@p6rt
Copy link
Author

p6rt commented Nov 12, 2015

From @usev6

On Thu Nov 12 11​:49​:18 2015, bartolin@​gmx.de wrote​:

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.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Nov 12, 2015

From @usev6

On Thu Nov 12 11​:49​:18 2015, bartolin@​gmx.de wrote​:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant