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

Longest Alternation followed by an Alternation fails #6478

Closed
p6rt opened this issue Aug 29, 2017 · 9 comments
Closed

Longest Alternation followed by an Alternation fails #6478

p6rt opened this issue Aug 29, 2017 · 9 comments
Labels
regex Regular expressions, pattern matching, user-defined grammars, tokens and rules

Comments

@p6rt
Copy link

p6rt commented Aug 29, 2017

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

Searchable as RT131991$

@p6rt
Copy link
Author

p6rt commented Aug 29, 2017

From firefish6000@gmail.com

*Description​:*
Longest alternation seems to only evaluate the first nested alternation of
its right side arguments.
That is, if the first regex of an alternation <||> following longest
alternation <|> fails, and the regex preceding the longest alternation
succeeds, the longest alternation uses the preceding/ left side match
rather than evaluating the rest of the right side alternation which could
have a potentially longer match.

*Example 1​:*
'succeed'.match(/ suc | [ fail || succeed ]/).say;

Returns​:
「suc」

Expected​:
「succeed」

*Example 2​:*
grammar TEST {
  regex NestedAlternation { fail || succeed }
  regex LongestAlternation { suc | <NestedAlternation> }
  regex TOP { <LongestAlternation> .* }
}
TEST.parse('succeed').say;

Returns​:
「succeed」
LongestAlternation => 「suc」

Expected​:
「succeed」
LongestAlternation => 「succeed」
  NestedAlternation => 「succeed」

Note if we remove the trailing '.*' in TOP, backtracking forces it to
evaluate the NestedAlternation and return the expected result. However,
backtracking back into the NestedAlternation should not be necessary.

*Example 3​:*
grammar TEST {
  token NestedAlternation { fail || succeed }
  token LongestAlternation { suc | <NestedAlternation> }
  token TOP { <LongestAlternation> }
}
TEST.parse('succeed').say;

Returns​:
Nil

Expected​:
「succeed」
LongestAlternation => 「succeed」
  NestedAlternation => 「succeed」

@p6rt
Copy link
Author

p6rt commented Aug 29, 2017

From @zoffixznet

Adding more content from OP (seems there's some possible delay/issue with RT emails) per https://irclog.perlgeek.de/perl6/2017-08-29#i_15086833


This is Rakudo version 2017.07-155-gc229022cb built on MoarVM version 2017.07-378-g5e94da03
implementing Perl 6.c.

Linux Kataomoi 4.13.0-rc6
CPU E3-1230 V2 @​ 3.30GHz GenuineIntel GNU/Linux
Also tested on IRC with Moar and Star

This is not specific to right side nested alternations.

Example 4​:
'succeed'.match(/ [fail || succeed] | suc /).say;
Result​:
「suc」
Expected​:
「succeed」

@p6rt
Copy link
Author

p6rt commented Aug 29, 2017

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

@p6rt
Copy link
Author

p6rt commented Aug 29, 2017

From @ronaldxs

Looks to me like possible dup of RT 130562 https://rt-archive.perl.org/perl6/Ticket/Display.html?id=130562

See also doc issue​: Raku/doc#1141

@p6rt
Copy link
Author

p6rt commented Aug 30, 2017

From @ronaldxs

Closing on request​: https://irclog.perlgeek.de/perl6/2017-08-29#i_15087239

I have never closed anybody else's ticket before so let me know if I am doing anything wrong.

@p6rt
Copy link
Author

p6rt commented Aug 30, 2017

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

@p6rt p6rt closed this as completed Aug 30, 2017
@p6rt
Copy link
Author

p6rt commented Aug 30, 2017

From @TimToady

Yes, as noted above, this is a dup of rejected ('better docs needed', really) ticket #​130562.

@p6rt
Copy link
Author

p6rt commented Aug 30, 2017

From firefish6000@gmail.com

This is Rakudo version 2017.07-155-gc229022cb built on MoarVM version
2017.07-378-g5e94da03
implementing Perl 6.c.

Linux Kataomoi 4.13.0-rc6
CPU E3-1230 V2 @​ 3.30GHz GenuineIntel GNU/Linux

Also tested on IRC with Moar and Star

On Tue, Aug 29, 2017 at 1​:22 PM, perl6 via RT <perl6-bugs-followup@​perl.org>
wrote​:

Greetings,

This message has been automatically generated in response to the
creation of a trouble ticket regarding​:
"[REGEX] Longest Alternation followed by an Alternation fails",
a summary of which appears below.

There is no need to reply to this message right now. Your ticket has been
assigned an ID of [perl #​131991].

Please include the string​:

     \[perl #&#8203;131991\]

in the subject line of all future correspondence about this issue. To do
so,
you may reply to this message.

                    Thank you,
                    perl6\-bugs\-followup@&#8203;perl\.org

-------------------------------------------------------------------------
*Description​:*
Longest alternation seems to only evaluate the first nested alternation of
its right side arguments.
That is, if the first regex of an alternation <||> following longest
alternation <|> fails, and the regex preceding the longest alternation
succeeds, the longest alternation uses the preceding/ left side match
rather than evaluating the rest of the right side alternation which could
have a potentially longer match.

*Example 1​:*
'succeed'.match(/ suc | [ fail || succeed ]/).say;

Returns​:
「suc」

Expected​:
「succeed」

*Example 2​:*
grammar TEST {
regex NestedAlternation { fail || succeed }
regex LongestAlternation { suc | <NestedAlternation> }
regex TOP { <LongestAlternation> .* }
}
TEST.parse('succeed').say;

Returns​:
「succeed」
LongestAlternation => 「suc」

Expected​:
「succeed」
LongestAlternation => 「succeed」
NestedAlternation => 「succeed」

Note if we remove the trailing '.*' in TOP, backtracking forces it to
evaluate the NestedAlternation and return the expected result. However,
backtracking back into the NestedAlternation should not be necessary.

*Example 3​:*
grammar TEST {
token NestedAlternation { fail || succeed }
token LongestAlternation { suc | <NestedAlternation> }
token TOP { <LongestAlternation> }
}
TEST.parse('succeed').say;

Returns​:
Nil

Expected​:
「succeed」
LongestAlternation => 「succeed」
NestedAlternation => 「succeed」

@p6rt
Copy link
Author

p6rt commented Aug 30, 2017

From firefish6000@gmail.com

This is Rakudo version 2017.07-155-gc229022cb built on MoarVM version
2017.07-378-g5e94da03
implementing Perl 6.c.

Linux Kataomoi 4.13.0-rc6
CPU E3-1230 V2 @​ 3.30GHz GenuineIntel GNU/Linux

Also tested on IRC with Moar and Star
This is not specific to right side nested alternations.

*Example 4​:*
'succeed'.match(/ [fail || succeed] | suc /).say;
Result​:
「suc」
Expected​:
「succeed」

@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