packages feed

show-prettyprint 0.2.3 → 0.3

raw patch · 4 files changed

+48/−4 lines, 4 files

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+# 0.3++- Fix lists not being prettified at the top level (#6)+- Fix lists in nested data structures not being aligned (#6)+ # 0.2.3  - Fix escaping of backslashes (#5)
show-prettyprint.cabal view
@@ -1,5 +1,5 @@ name:                show-prettyprint-version:             0.2.3+version:             0.3 synopsis:            Robust prettyprinter for output of auto-generated Show                      instances description:         See README.md
src/Text/Show/Prettyprint.hs view
@@ -9,7 +9,7 @@ --         , ("!"    , Left  (Pair False ())) ] -- :} ----- Applying 'show' to it results in the fairly dense representation+-- Applying 'show' to the nested example results in the fairly dense representation -- -- >>> print nestedExample -- fromList [("!",Left (Pair False ())),("hello",Left (Pair True ())),("world",Right (Record {r1 = ('c',-1.2e34), r2 = 123}))]@@ -69,3 +69,17 @@ -- | 'prettifyToDoc' with the 'show' baked in. prettyShowDoc :: Show a => a -> Doc ann prettyShowDoc = prettifyToDoc . show++-- $+-- Regression (#6): Top-level lists weren’t prettified+-- >>> :{+-- let listExample =+--         [ ("hello", Left  (Pair True ()))+--         , ("world", Right (Record { r1 = ('c', -1.2e34), r2 = 123 }))+--         , ("!"    , Left  (Pair False ())) ]+-- :}+--+-- >>> prettyPrint listExample+-- [("hello",Left (Pair True ()))+-- ,("world",Right (Record {r1 = ('c',-1.2e34),r2 = 123}))+-- ,("!",Left (Pair False ()))]
src/Text/Show/Prettyprint/Internal.hs view
@@ -35,6 +35,7 @@ -- :}  + parseShowString :: String -> Result (Doc ann) parseShowString = parseString shownP mempty @@ -49,7 +50,7 @@ -- Just ('c',Left ()) valueP :: Parser (Doc ann) valueP = do-    thing <- choice [identifierP, numberP, stringLitP, charLitP]+    thing <- choice [identifierP, numberP, stringLitP, charLitP, listP]     args <- many argP     pure (if null args         then thing@@ -158,4 +159,28 @@         lhs <- token identifierP         _ <- token (Tri.char '=')         rhs <- argP-        pure (lhs <+> pretty '=' <+> rhs)+        pure (lhs <+> pretty '=' <+> align rhs)++-- $+-- Regression (#6): Nested lists were not aligned properly+-- >>> :{+-- testParse valueP (concat+--     ["ApiGroup {name = \"API Key\" ,endpoints = [Endpoint {path = "+--     ,"\"/v1/auth/info\" ,description = \"Retrieve information about the"+--     ," current API key.\" ,needsAPIKey = \"Yes\" ,method = \"GET\" ,"+--     ,"requiredAccess = \"\"} ,Endpoint {path = \"/v1/auth/info\" ,"+--     ,"description = \"Retrieve information about the current API key.\" ,"+--     ,"needsAPIKey = \"Yes\" ,method = \"GET\" ,requiredAccess = \"\"}]}]"+--     ])+-- :}+-- ApiGroup {name = "API Key"+--          ,endpoints = [Endpoint {path = "/v1/auth/info"+--                                 ,description = "Retrieve information about the current API key."+--                                 ,needsAPIKey = "Yes"+--                                 ,method = "GET"+--                                 ,requiredAccess = ""}+--                       ,Endpoint {path = "/v1/auth/info"+--                                 ,description = "Retrieve information about the current API key."+--                                 ,needsAPIKey = "Yes"+--                                 ,method = "GET"+--                                 ,requiredAccess = ""}]}