Skip to content

Fix showPattern to round-trip #47

Open
@andreasabel

Description

@andreasabel

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'

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions