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

Captures from interpolated variables do not capture #5672

Closed
p6rt opened this issue Sep 15, 2016 · 5 comments
Closed

Captures from interpolated variables do not capture #5672

p6rt opened this issue Sep 15, 2016 · 5 comments
Labels
regex Regular expressions, pattern matching, user-defined grammars, tokens and rules

Comments

@p6rt
Copy link

p6rt commented Sep 15, 2016

Migrated from rt.perl.org#129271 (status was 'rejected')

Searchable as RT129271$

@p6rt
Copy link
Author

p6rt commented Sep 15, 2016

From @zoffixznet

<Zoffix> m​: my $m = 'a 123' ~~ /(\d\d\d)/; dd [$m.list];
<camelia> rakudo-moar 2c95f7​: OUTPUT«[Match.new(ast => Any, list => (), hash => Map.new(()), orig => "a 123", to => 5, from => 2)]␤»
<Zoffix> m​: my $input = '(\d\d\d)'; my $m = 'a 123' ~~ /<$input>/; dd [$m.list];
<camelia> rakudo-moar 2c95f7​: OUTPUT«[]␤»

Expected results​: output is the same, as the $input contains a capture that should capture stuff when interpolated.

@p6rt
Copy link
Author

p6rt commented Sep 15, 2016

From @zoffixznet

<ugexe> m​: my $input = q|(\d\d\d)|; my $rx = rx/<$input>/; my $m = "a 123 456" ~~ m​:g/$rx/; dd [$m.list>>.Str];
<camelia> rakudo-moar 2c95f7​: OUTPUT«["123", "456"]␤»

@p6rt
Copy link
Author

p6rt commented Sep 15, 2016

From @pmichaud

On Wed, Sep 14, 2016 at 05​:10​:55PM -0700, Zoffix Znet wrote​:

<Zoffix> m​: my $input = '(\d\d\d)'; my $m = 'a 123' ~~ /<$input>/; dd [$m.list];
<camelia> rakudo-moar 2c95f7​: OUTPUT«[]␤»

Expected results​: output is the same, as the $input contains a capture that should capture stuff when interpolated.

<$input> is non-capturing, so even though it contains a $0 capture, its result
won't be held by the outermost Match object.

Rewrite to <input=$input> or $0=<$input> and you'll see the resulting capture.

  <pmichaud> m​: my $input = '(\d\d\d)'; my $m = 'a 123' ~~ /<input=$input>/; say $m
  <camelia> rakudo-moar 2c95f7​: OUTPUT«「123」␤ input => 「123」␤ 0 => 「123」␤»
  <pmichaud> m​: my $input = '(\d\d\d)'; my $m = 'a 123' ~~ /$0=<$input>/; say $m
  <camelia> rakudo-moar 2c95f7​: OUTPUT«「123」␤ 0 => 「123」␤ 0 => 「123」␤»

As far as I know, there's not a way to have a "top-level" capturing
interpolation except by using some form of the <foo=...> or $0=<...>
syntax. It's always consider a sub-rule capture.

Rejecting ticket as not-a-bug.

Pm

@p6rt
Copy link
Author

p6rt commented Sep 15, 2016

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

@p6rt
Copy link
Author

p6rt commented Sep 15, 2016

@pmichaud - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed Sep 15, 2016
@p6rt p6rt added the regex Regular expressions, pattern matching, user-defined grammars, tokens and rules label 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
Projects
None yet
Development

No branches or pull requests

1 participant