develooper Front page | perl.perl6.compiler | Postings from December 2011

[perl #107306] regex fails unless alternates are sorted by length

From:
Timothy Smith
Date:
December 30, 2011 10:55
Subject:
[perl #107306] regex fails unless alternates are sorted by length
Message ID:
rt-3.6.HEAD-14510-1325229813-1302.107306-82-0@perl.org
# New Ticket Created by  Timothy Smith 
# Please include the string:  [perl #107306]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=107306 >


Here is a test case where nom (and b, too) fails to parse unless the
words are sorted longest-first. Niecza handles this OK.


my @words = <north northeast>;

print "unsorted (fails): ";
say 'northeast' ~~ / ^ <{join '|', @words }> $ / ?? "parsed $/" !! 'no parse';
print "sorted (passes): ";
say 'northeast' ~~ / ^ <{join '|', @words.sort({ $^b.chars cmp
$^a.chars }) }> $ / ?? "parsed $/" !! 'no parse';



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About