ipprint 0.1 → 0.2
raw patch · 2 files changed
+25/−4 lines, 2 filesnew-uploaderPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- IPPrint.hs +13/−3
- ipprint.cabal +12/−1
IPPrint.hs view
@@ -2,9 +2,19 @@ import Language.Haskell.Parser import Language.Haskell.Pretty +import Text.Read pprint :: Show a => a -> IO () pprint v = putStrLn $ - case parseModule ("value = "++show v) of - ParseOk m -> dropWhile (/='\n') $ prettyPrint m - ParseFailed pos err -> show pos ++ ": " ++ err + case parseModule ("value = "++s) of + ParseOk m -> tidy $ prettyPrint m + ParseFailed _ _ -> s + where s = show v + tidy x = case readPrec_to_S skipBoring 0 x of + [((), tail)] -> " " ++ tail + _ -> s + +skipBoring :: ReadPrec () +skipBoring = + do { Ident "value" <- lexP; Punc "=" <- lexP; return () } <++ + do { lexP; skipBoring }
ipprint.cabal view
@@ -1,6 +1,6 @@ Name: ipprint Category: Text-Version: 0.1+Version: 0.2 License: BSD3 License-file: LICENSE Author: Gleb Alexeyev@@ -8,5 +8,16 @@ Build-Depends: base, haskell-src Synopsis: Tiny helper for pretty-printing values in ghci console Description: Tiny helper for pretty-printing values in ghci console+ .+ Usage example:+ . + >Prelude> let e = replicate 5 [1..14] -- value we want to print + >Prelude> :m + IPPrint + >Prelude IPPrint> pprint e + > [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], + > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], + > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], + > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], + > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]] Exposed-modules: IPPrint