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

Quantified capture group breaks `$/.list` #5680

Open
p6rt opened this issue Sep 18, 2016 · 10 comments
Open

Quantified capture group breaks `$/.list` #5680

p6rt opened this issue Sep 18, 2016 · 10 comments
Labels

Comments

@p6rt
Copy link

@p6rt p6rt commented Sep 18, 2016

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

Searchable as RT129299$

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 18, 2016

From @smls

When a quantified capture group matched zero times but the overall regex matches, then the List returned from `$/.list` stops iterating before the corresponding element​:

  "ac" ~~ / (a) (b)? (c) /;
  say ($0, $1, $2); # (「a」 Nil 「c」)
  say $/.list; # (「a」)
  say $/.list.map({1}); # (1)
  say $/.list.elems; # 3
  say $/.list[0, 1, 2, 3]; # (「a」 (Mu) 「c」 Nil

Expected behavior would be for `$/.list;` to return `(「a」 Nil 「c」)`.

mst++ suggested that maybe an InterationEnd is ending up where it shouldn't be.

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 18, 2016

From @lizmat

I’m looking into this. This appears to be an artefact of .gist on the list, caused by the say. Which also happens for .perl on the list.

say $/.list.Str; # a c

Suspecting the gistseen/perlseen machinery now. Investigating...

On 18 Sep 2016, at 19​:30, Sam S. (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Sam S.
# Please include the string​: [perl #​129299]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=129299 >

When a quantified capture group matched zero times but the overall regex matches, then the List returned from `$/.list` stops iterating before the corresponding element​:

"ac" ~~ / (a) (b)? (c) /;
say ($0, $1, $2); # (「a」 Nil 「c」)
say $/.list; # (「a」)
say $/.list.map({1}); # (1)
say $/.list.elems; # 3
say $/.list[0, 1, 2, 3]; # (「a」 (Mu) 「c」 Nil

Expected behavior would be for `$/.list;` to return `(「a」 Nil 「c」)`.

mst++ suggested that maybe an InterationEnd is ending up where it shouldn't be.

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 18, 2016

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

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 18, 2016

From @lizmat

Ah, found it​:

The List iterator assumes that a List cannot have “holes” in it. Apparently it can :-(

Going to sleep on how to fix this.

On 18 Sep 2016, at 19​:30, Sam S. (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Sam S.
# Please include the string​: [perl #​129299]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=129299 >

When a quantified capture group matched zero times but the overall regex matches, then the List returned from `$/.list` stops iterating before the corresponding element​:

"ac" ~~ / (a) (b)? (c) /;
say ($0, $1, $2); # (「a」 Nil 「c」)
say $/.list; # (「a」)
say $/.list.map({1}); # (1)
say $/.list.elems; # 3
say $/.list[0, 1, 2, 3]; # (「a」 (Mu) 「c」 Nil

Expected behavior would be for `$/.list;` to return `(「a」 Nil 「c」)`.

mst++ suggested that maybe an InterationEnd is ending up where it shouldn't be.

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 18, 2016

From @lizmat

Fixed (for now at least) with 9b6f2eb5434e71f07bc649 . Tests still needed.

On 18 Sep 2016, at 19​:30, Sam S. (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Sam S.
# Please include the string​: [perl #​129299]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=129299 >

When a quantified capture group matched zero times but the overall regex matches, then the List returned from `$/.list` stops iterating before the corresponding element​:

"ac" ~~ / (a) (b)? (c) /;
say ($0, $1, $2); # (「a」 Nil 「c」)
say $/.list; # (「a」)
say $/.list.map({1}); # (1)
say $/.list.elems; # 3
say $/.list[0, 1, 2, 3]; # (「a」 (Mu) 「c」 Nil

Expected behavior would be for `$/.list;` to return `(「a」 Nil 「c」)`.

mst++ suggested that maybe an InterationEnd is ending up where it shouldn't be.

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 19, 2016

From @zoffixznet

Tests added in Raku/roast@581b553

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 19, 2016

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

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 19, 2016

From @smls

Should it really return `(「a」 (Mu) 「c」)` and not `(「a」 Nil 「c」)`, seeing as $1 is also Nil?

liz made it work on the List.iterator end by allowing it to iterate over holes in the list, but maybe Match.list should not produce a list with holes at all, but rather a list with Nil in place of missing captures?
(Maybe that's what the "for now at least" refers to.)

If so, then the `is $two.^name, 'Mu'` test added by zoffix is LTA.
Maybe it should just test `nok $two.defined` for now, until it is cleared up what type exactly it should be...

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 19, 2016

From @AlexDaniel

Should we reopen this then?

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 19, 2016

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

@p6rt p6rt added the regex label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.