show-prettyprint: Robust prettyprinter for output of auto-generated Show instances

[ bsd3, library, text, user-interfaces ] [ Propose Tags ] [ Report a vulnerability ]

See README.md


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.2, 0.1.2.1, 0.2, 0.2.0.1, 0.2.0.2, 0.2.1, 0.2.2, 0.2.3, 0.3, 0.3.0.1
Change log CHANGELOG.md
Dependencies ansi-wl-pprint, base (>=4.8 && <5), prettyprinter (>=1.2), trifecta (>=1.6 && <1.8) [details]
License BSD-3-Clause
Copyright David Luposchainsky, 2016
Author David Luposchainsky <dluposchainsky (λ) google>
Maintainer David Luposchainsky <dluposchainsky (λ) google>
Revised Revision 1 made by phadej at 2020-04-14T12:52:41Z
Category User Interfaces, Text
Home page https://github.com/quchen/show-prettyprint#readme
Source repo head: git clone https://github.com/quchen/show-prettyprint
Uploaded by quchen at 2019-07-08T07:27:15Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 7635 total (44 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-07-08 [all 1 reports]

Readme for show-prettyprint-0.3.0.1

[back to package description]

Prettyprint Show output

Output of nested data structures by Show instances is often very hard to read. This package offers a simple function to insert line breaks and indentation into that ouput so that the semantics are unchanged, but makes it much easier to read.

The package does not rely on a parser for actual Haskell; instead, it merely reacts on parentheses, commas and the like. This makes it fairly robust even in the face of invalid Show instances, that may not produce valid Haskell code.

Examples

Artificial

Hello Foo ("(Bar", Haha) (Baz (A { foo = C, bar = D, qux = (E,"He)llo World!",G,
    H,[A,B,c,d,e,Fghi]) } ) (B,C) [Baz A1 B2, (Baz A3 (B4)), (Baz A5 (B6)), (Baz
    (A7) B8)]) (Foo) (Bar) (Baz (A) (B))

==>

Hello Foo ("(Bar",Haha)
          (Baz (A {foo = C
                  ,bar = D
                  ,qux = (E
                         ,"He)llo World!"
                         ,G
                         ,H
                         ,[A,B,c,d,e,Fghi])})
               (B,C)
               [Baz A1 B2
               ,(Baz A3 (B4))
               ,(Baz A5 (B6))
               ,(Baz (A7) B8)])
          (Foo)
          (Bar)
          (Baz (A) (B))

Inspired by a real AST

Set  (fromList [(Name "A string with (parenthesis",Ann  (Entry (Quality 1 1)
    (Ann  False) (Ann  (Map [Ann  (Bound (Ann  (Id "lorem"))),Ann  (Variable
    (Ann  (Id "ipsum")))])))),(Name "string",Ann  (Entry (Quality 1 1) (Ann
    True) (Ann  (Internal (Ann  (Reduce (Ann  (Id "dolor")) (Ann  (Id "sit")))))
    ))),(Name "Another } here",Ann  (Entry (Quality 1 1) (Ann  (Or [Ann  (Not
    (Ann  (Is (Ann  Flagged) (Ann  Type) (Ann  (Multi [Ann  (Literal (Ann  One))
    ]))))),Ann  (Is (Ann  Flagged) (Ann  Type) (Ann  (Multi [Ann  (Literal (Ann
    Three))]))),Ann  (Is (Ann  Flagged) (Ann  Type) (Ann  (Multi [Ann  (Literal
    (Ann  Two))])))])) (Ann  (Internal (Ann  (Concat (Ann  (Id "amet"))))))))])

==>

Set (fromList [(Name "A string with (parenthesis"
               ,Ann (Entry (Quality 1 1)
                           (Ann False)
                           (Ann (Map [Ann (Bound (Ann (Id "lorem")))
                                     ,Ann (Variable (Ann (Id "ipsum")))]))))
              ,(Name "string"
               ,Ann (Entry (Quality 1 1)
                           (Ann True)
                           (Ann (Internal (Ann (Reduce (Ann (Id "dolor"))
                                                       (Ann (Id "sit"))))))))
              ,(Name "Another } here"
               ,Ann (Entry (Quality 1 1)
                           (Ann (Or [Ann (Not (Ann (Is (Ann Flagged)
                                                       (Ann Type)
                                                       (Ann (Multi [Ann (Literal (Ann One))])))))
                                    ,Ann (Is (Ann Flagged)
                                             (Ann Type)
                                             (Ann (Multi [Ann (Literal (Ann Three))])))
                                    ,Ann (Is (Ann Flagged)
                                             (Ann Type)
                                             (Ann (Multi [Ann (Literal (Ann Two))])))]))
                           (Ann (Internal (Ann (Concat (Ann (Id "amet"))))))))])