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

Fix showPattern to round-trip #47

Open
andreasabel opened this issue Jul 18, 2022 · 0 comments
Open

Fix showPattern to round-trip #47

andreasabel opened this issue Jul 18, 2022 · 0 comments
Assignees
Milestone

Comments

@andreasabel
Copy link
Member

andreasabel commented Jul 18, 2022

Better docs for Pattern module (fixed in 1.3.2), fix showPattern to round-trip.

It is claimed that showPattern round-trips, but does not:

>>> getAllTextMatches ("a \" \\" =~ "[a]") :: [String]
["a"]

>>> let parse = either (error . show) fst . parseRegex
>>> let pp' = showPattern . parse
>>> getAllTextMatches ("a \" \\" =~ pp' "[a]") :: [String]
["a","\""]

It uses Show PatternSet which adds " coming from empty components of PatternSet:

showsPrec i (PatternSet s scc sce sec) =
let (special,normal) = maybe ("","") ((partition (`elem` "]-")) . Set.toAscList) s
charSpec = (if ']' `elem` special then (']':) else id) (byRange normal)
scc' = maybe "" ((concatMap show) . Set.toList) scc
sce' = maybe "" ((concatMap show) . Set.toList) sce
sec' = maybe "" ((concatMap show) . Set.toList) sec
in shows charSpec
. showsPrec i scc' . showsPrec i sce' . showsPrec i sec'

@andreasabel andreasabel added this to the 1.3.2 milestone Jul 18, 2022
@andreasabel andreasabel self-assigned this Jul 18, 2022
@andreasabel andreasabel changed the title Better docs for Pattern module, fix showPattern to round-trip Fix showPattern to round-trip Jul 18, 2022
@andreasabel andreasabel modified the milestones: 1.3.2, 1.4 Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant