sjshuck / hs-pcre2

Complete Haskell binding to PCRE2
Apache License 2.0
12 stars 2 forks source link

"Match once" functions return multiple matches if the Alternative is [] #17

Closed sjshuck closed 3 years ago

sjshuck commented 3 years ago
print $ match @[] "\\d+" "123 456"

-- prints:       ["123","456"]
-- should print: ["123"]

This is because Text.Regex.Pcre2.Internal.toAlternativeOf "fills up" the Alternative container.

Short term, deliberately limit the functions to a single match to make the behavior match the docs.

Long term, observe this:

currentBuggyMatch = matchAll

Embrace this accidental behavior and remove matchAll and friends. If the intended match per current docs is really needed—to produce a list that is at most a singleton—it can be recovered by

take 1      . currentBuggyMatchWeShouldEmbrace patt
maybeToList . currentBuggyMatchWeShouldEmbrace patt
sjshuck commented 3 years ago

This issue will be for the short-term solution. For the long-term solution, let's open a new issue.