show-prettyprint 0.2.2 → 0.2.3
raw patch · 3 files changed
+21/−6 lines, 3 files
Files
- CHANGELOG.md +5/−0
- show-prettyprint.cabal +1/−1
- src/Text/Show/Prettyprint/Internal.hs +15/−5
CHANGELOG.md view
@@ -1,3 +1,8 @@+# 0.2.3++- Fix escaping of backslashes (#5)+- Fix a bug with ambiguous types on newer cabal new-repl runs (#4)+ # 0.2.{1,2} Add functions to prettify to `Doc` instead of just supporting `String`,
show-prettyprint.cabal view
@@ -1,5 +1,5 @@ name: show-prettyprint-version: 0.2.2+version: 0.2.3 synopsis: Robust prettyprinter for output of auto-generated Show instances description: See README.md
src/Text/Show/Prettyprint/Internal.hs view
@@ -80,21 +80,31 @@ Right d -> pure (pretty d) -- |--- >>> testParse stringLitP "\"Hello world!\""--- "Hello world!"+-- >>> testParse stringLitP "\"Hello\\\\ world!\""+-- "Hello\\ world!" stringLitP :: Parser (Doc ann) stringLitP = token (p <?> "string literal") where- p = fmap (dquotes . pretty) (stringLiteral :: Parser String)+ p = fmap (dquotes . pretty . concatMap escapeBackslashes)+ (stringLiteral :: Parser String) +escapeBackslashes :: Char -> String+escapeBackslashes '\\' = "\\\\"+escapeBackslashes x = [x]+ -- | -- >>> testParse charLitP "'c'" -- 'c' charLitP :: Parser (Doc ann) charLitP = token (p <?> "char literal") where- p = fmap (squotes . pretty) Tri.charLiteral+ p = fmap (squotes . pretty . escapeBackslashes) Tri.charLiteral +-- $+-- Correct backslash handling+-- >>> testParse charLitP "'\\\\'"+-- '\\'+ -- | Anything that could be considered an argument to something else. -- -- >>> testParse argP "()"@@ -148,4 +158,4 @@ lhs <- token identifierP _ <- token (Tri.char '=') rhs <- argP- pure (lhs <+> pretty "=" <+> rhs)+ pure (lhs <+> pretty '=' <+> rhs)