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

Capture reference doesn't work in lookahead assertions #2303

Closed
p6rt opened this issue Dec 22, 2010 · 6 comments
Closed

Capture reference doesn't work in lookahead assertions #2303

p6rt opened this issue Dec 22, 2010 · 6 comments
Labels
regex Regular expressions, pattern matching, user-defined grammars, tokens and rules testneeded

Comments

@p6rt
Copy link

p6rt commented Dec 22, 2010

Migrated from rt.perl.org#81136 (status was 'resolved')

Searchable as RT81136$

@p6rt
Copy link
Author

p6rt commented Dec 22, 2010

From info@syntax-k.de

This example program explains it all​:

grammar test {
  token a { a };
  token b { b };
  token TOP { <a><b><before $<a>> };
};

if (test.parse("abc")) {
  say "bug!"
} else {
  say "correct."
}

grammar test2 is test {
  token TOP { <a><b><before $&lt;a&gt;&gt;$&lt;a> };
}

if (test2.parse("abc")) {
  say "bug!"
} else {
  say "correct."
}

grammar test3 is test {
  token TOP { <a><b><before {say 'have '~$<a>}$<a>> };
}

test3.parse("abc");

On rakudo star 2010.11, it prints
bug!
correct
have

Modifying the grammars to use positional captures yields the same results.

--
Mit freundlichen Grüßen,

  Jörg Walter

@p6rt
Copy link
Author

p6rt commented Aug 7, 2015

From @ShimmerFairy

Running the given script now gives as output​:

  correct.
  correct.
  Use of Nil in string context in block at t.p6​:24
  have

Note that moving the code block out of the before assertion, like so​:

  token TOP { <a><b> { say "have " ~ $&lt;a&gt; } &lt;before $&lt;a>> };

Gives the expected output for the third test​:

  have a

I suspect the issue is that the block, along with the rest of the regex passed to .before, gets evaluated in a context without access to $<a>, which I don't think is related to the reported bug (if it even is a bug).

So, this bug could be closed with tests, if necessary.

@p6rt
Copy link
Author

p6rt commented Aug 7, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Apr 7, 2016

From @diakopter

seems fixed to me

12​:12 <diakopter> m​: grammar test { token a { a }; token b { b }; token TOP {
  <a><b><before $<a>> };}; test.parse("abc").say
12​:12 <camelia> rakudo-moar 61d231​: OUTPUT«Nil␤»

@p6rt
Copy link
Author

p6rt commented Sep 10, 2016

From @zoffixznet

Tests added in Raku/roast@0b80402678

@p6rt
Copy link
Author

p6rt commented Sep 10, 2016

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Sep 10, 2016
@p6rt p6rt added regex Regular expressions, pattern matching, user-defined grammars, tokens and rules testneeded labels Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regex Regular expressions, pattern matching, user-defined grammars, tokens and rules testneeded
Projects
None yet
Development

No branches or pull requests

1 participant