git.iko.soy/typeable/attoparsec
on master help sign in
Merge pull request #85 from SeanRBurton/print_IResult

Change the Show instances for Result and IResult

commit64c9707ca62c041fe4b318983995e2dc9180ac69 authorBryan O'Sullivan <bos@serpentine.com> dateTue 17 Feb 2015, 22:48 (12 years ago) parent8134fcced2da37
2 files changed+7−9
Data/Attoparsec/Internal/Types.hs+6−4 Data/Attoparsec/Text/Lazy.hs+1−5
Data/Attoparsec/Internal/Types.hs+6−4
@@ -70,10 +70,12 @@ data IResult i r =
7070 -- not yet been consumed (if any) when the parse succeeded.
7171
7272instance (Show i, Show r) => Show (IResult i r) where
73− show (Fail t stk msg) =
74− unwords [ "Fail", show t, show stk, show msg]
75− show (Partial _) = "Partial _"
76− show (Done t r) = unwords ["Done", show t, show r]
73+ showsPrec d ir = showParen (d > 10) $
74+ case ir of
75+ (Fail t stk msg) -> showString "Fail" . f t . f stk . f msg
76+ (Partial _) -> showString "Partial _"
77+ (Done t r) -> showString "Done" . f t . f r
78+ where f x = showChar ' ' . showsPrec 11 x
7779
7880instance (NFData i, NFData r) => NFData (IResult i r) where
7981 rnf (Fail t stk msg) = rnf t `seq` rnf stk `seq` rnf msg
Data/Attoparsec/Text/Lazy.hs+1−5
@@ -59,11 +59,7 @@ data Result r = Fail Text [String] String
5959 -- ^ The parse succeeded. The 'Text' is the
6060 -- input that had not yet been consumed (if any) when
6161 -- the parse succeeded.
62−
63−instance Show r => Show (Result r) where
64− show (Fail bs stk msg) =
65− "Fail " ++ show bs ++ " " ++ show stk ++ " " ++ show msg
66− show (Done bs r) = "Done " ++ show bs ++ " " ++ show r
62+ deriving (Show)
6763
6864instance NFData r => NFData (Result r) where
6965 rnf (Fail bs ctxs msg) = rnf bs `seq` rnf ctxs `seq` rnf msg