packages feed

show-prettyprint 0.1.2.1 → 0.2

raw patch · 4 files changed

+35/−27 lines, 4 filesdep +prettyprinterdep ~trifectaPVP ok

version bump matches the API change (PVP)

Dependencies added: prettyprinter

Dependency ranges changed: trifecta

API changes (from Hackage documentation)

- Text.Show.Prettyprint.Internal: argP :: Parser Doc
+ Text.Show.Prettyprint.Internal: argP :: Parser (Doc ann)
- Text.Show.Prettyprint.Internal: charLitP :: Parser Doc
+ Text.Show.Prettyprint.Internal: charLitP :: Parser (Doc ann)
- Text.Show.Prettyprint.Internal: identifierP :: Parser Doc
+ Text.Show.Prettyprint.Internal: identifierP :: Parser (Doc ann)
- Text.Show.Prettyprint.Internal: listP :: Parser Doc
+ Text.Show.Prettyprint.Internal: listP :: Parser (Doc ann)
- Text.Show.Prettyprint.Internal: numberP :: Parser Doc
+ Text.Show.Prettyprint.Internal: numberP :: Parser (Doc ann)
- Text.Show.Prettyprint.Internal: recordP :: Parser Doc
+ Text.Show.Prettyprint.Internal: recordP :: Parser (Doc ann)
- Text.Show.Prettyprint.Internal: shownP :: Parser Doc
+ Text.Show.Prettyprint.Internal: shownP :: Parser (Doc ann)
- Text.Show.Prettyprint.Internal: stringLitP :: Parser Doc
+ Text.Show.Prettyprint.Internal: stringLitP :: Parser (Doc ann)
- Text.Show.Prettyprint.Internal: tupleP :: Parser Doc
+ Text.Show.Prettyprint.Internal: tupleP :: Parser (Doc ann)
- Text.Show.Prettyprint.Internal: unitP :: Parser Doc
+ Text.Show.Prettyprint.Internal: unitP :: Parser (Doc ann)
- Text.Show.Prettyprint.Internal: valueP :: Parser Doc
+ Text.Show.Prettyprint.Internal: valueP :: Parser (Doc ann)

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# 0.2++Prettyprint based on the `prettyprinter` library, instead of `ansi-wl-pprint`.+To support the `Diagnostic` module, the Trifecta-generated `Doc` has to be+rendered still, so we cannot drop the dependency on ansi-wl-pprint just yet.
show-prettyprint.cabal view
@@ -1,5 +1,5 @@ name:                show-prettyprint-version:             0.1.2.1+version:             0.2 synopsis:            Robust prettyprinter for output of auto-generated Show                      instances description:         See README.md@@ -12,6 +12,7 @@ category:            User Interfaces, Text build-type:          Simple extra-source-files:  README.md+                   , CHANGELOG.md                    , .stylish-haskell.yaml cabal-version:       >=1.10 @@ -22,9 +23,9 @@                      , Text.Show.Prettyprint.Internal   build-depends:       base >= 4.7 && < 5                      , trifecta >= 1.6+                     , prettyprinter < 1.1 -                     -- Transitive dependency of Trifecta, so let the-                     -- version be sorted out by that+                     -- Transitive dep of Trifecta, figure it out via that one                      , ansi-wl-pprint   ghc-options:         -Wall   default-language:    Haskell2010
src/Text/Show/Prettyprint/Diagnostic.hs view
@@ -17,9 +17,9 @@   -import Data.Monoid-import Text.PrettyPrint.ANSI.Leijen as Ppr hiding ((<>))-import Text.Trifecta                as Tri+import           Data.Text.Prettyprint.Doc+import qualified Text.PrettyPrint.ANSI.Leijen as OldAnsiPpr+import           Text.Trifecta                as Tri  import Text.Show.Prettyprint.Internal @@ -30,7 +30,7 @@ prettifyShowErr :: String -> String prettifyShowErr s = case parseString shownP mempty s of     Success x -> show x-    Failure ErrInfo{ _errDoc = e } -> "ERROR " <> show (plain e)+    Failure ErrInfo{ _errDoc = e } -> "ERROR " <> show (OldAnsiPpr.plain e)  -- | 'prettifyShowErr' with the 'show' baked in. prettyShowErr :: Show a => a -> String
src/Text/Show/Prettyprint/Internal.hs view
@@ -19,12 +19,14 @@   import Control.Applicative-import Text.PrettyPrint.ANSI.Leijen as Ppr hiding ((<>))-import Text.Trifecta                as Tri+import Data.Text.Prettyprint.Doc as Ppr+import Text.Trifecta             as Tri    -- $setup+--+-- >>> import Text.PrettyPrint.ANSI.Leijen (plain) -- >>> :{ -- let testParse p s = case parseString p mempty s of --         Success x -> print x@@ -34,7 +36,7 @@   -- | Prettyparser for a 'show'-generated string-shownP :: Parser Doc+shownP :: Parser (Doc ann) shownP = valueP <* eof  -- | Prettyparser for a constructor, which is roughly a word applied to@@ -42,7 +44,7 @@ -- -- >>> testParse valueP "Just ('c', Left ())" -- Just ('c',Left ())-valueP :: Parser Doc+valueP :: Parser (Doc ann) valueP = do     thing <- choice [identifierP, numberP, stringLitP, charLitP]     args <- many argP@@ -55,10 +57,10 @@ -- -- >>> testParse identifierP "_foo'bar" -- _foo'bar-identifierP :: Parser Doc+identifierP :: Parser (Doc ann) identifierP = token (p <?> "identifier")   where-    p = fmap Ppr.text (some (alphaNum <|> oneOf "'_"))+    p = fmap Ppr.pretty (some (alphaNum <|> oneOf "'_"))  -- | Number in integer or scientific notation. --@@ -67,28 +69,28 @@ -- -- >>> testParse numberP "-123.4e56" -- -1.234e58-numberP :: Parser Doc+numberP :: Parser (Doc ann) numberP = p <?> "number"   where     p = integerOrDouble >>= \case-        Left i -> pure (Ppr.integer i)-        Right d -> pure (Ppr.double d)+        Left i -> pure (pretty i)+        Right d -> pure (pretty d)  -- | -- >>> testParse stringLitP "\"Hello world!\"" -- "Hello world!"-stringLitP :: Parser Doc+stringLitP :: Parser (Doc ann) stringLitP = token (p <?> "string literal")   where-    p = fmap (dquotes . Ppr.string) stringLiteral+    p = fmap (dquotes . pretty) (stringLiteral :: Parser String)  -- | -- >>> testParse charLitP "'c'" -- 'c'-charLitP :: Parser Doc+charLitP :: Parser (Doc ann) charLitP = token (p <?> "char literal")   where-    p = fmap (squotes . Ppr.char) Tri.charLiteral+    p = fmap (squotes . pretty) Tri.charLiteral  -- | Anything that could be considered an argument to something else. --@@ -97,23 +99,23 @@ -- -- >>> testParse argP "['h', 'e', 'l', 'l', 'o']" -- ['h','e','l','l','o']-argP :: Parser Doc+argP :: Parser (Doc ann) argP = (token . choice) [unitP, tupleP, listP, recordP, valueP]  -- | -- >>> testParse unitP "()" -- ()-unitP :: Parser Doc+unitP :: Parser (Doc ann) unitP = p <?> "unit"   where-    p = fmap Ppr.string (Tri.string "()")+    p = fmap pretty (Tri.string "()")  -- | Prettyparser for tuples from size 1. Since 1-tuples are just parenthesized -- expressions to first order approximation, this parser handles those as well. -- -- >>> testParse tupleP "((), True, 'c')" -- ((),True,'c')-tupleP :: Parser Doc+tupleP :: Parser (Doc ann) tupleP = p <?> "tuple"   where     p = fmap (encloseSep lparen rparen Ppr.comma) (Tri.parens (do@@ -126,7 +128,7 @@ -- -- >>> testParse listP "[\"Hello\", World]" -- ["Hello",World]-listP :: Parser Doc+listP :: Parser (Doc ann) listP = p <?> "list"   where     p = fmap (encloseSep lbracket rbracket Ppr.comma)@@ -135,7 +137,7 @@ -- | -- >>> testParse recordP "{ r1 = (), r2 = Just True }" -- {r1 = (),r2 = Just True}-recordP :: Parser Doc+recordP :: Parser (Doc ann) recordP = p <?> "record"   where     p = fmap (encloseSep lbrace rbrace Ppr.comma) (Tri.braces (sepBy recordEntryP Tri.comma))@@ -143,4 +145,4 @@         lhs <- token identifierP         _ <- token (Tri.char '=')         rhs <- argP-        pure (lhs <+> Ppr.string "=" <+> rhs)+        pure (lhs <+> pretty "=" <+> rhs)