ModuleBNFC-2.9.5Haskell2010
BNFC.PrettyPrint
Extends 'Text.PrettyPrint'.
- 4 types
- 1 class
- 54 values
- PackageBNFC-2.9.5
- Exports59
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourcePrettyPrint.hs
The abstract type of documents. A Doc represents a set of layouts. A Doc with no occurrences of Union or NoDoc represents just one layout.
Instances10Eq, Show, IsString, Generic, Semigroup, Monoid, …
Eq DocDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJShow DocDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJShow DocDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.PprLibIsString DocDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJGeneric DocDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJSemigroup DocDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJMonoid DocDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJNFData DocDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJFileContent DocDefined in BNFC-2.9.5 · BNFC.Backend.Basetype Rep Doc = D1 ('MetaDataDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJ"Doc"
"Text.PrettyPrint.HughesPJ"
"pretty-1.1.3.6-a72d"
'True) (C1 ('MetaCons"Doc"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ()))))
Rendering mode.
Constructors
PageModeNormal rendering (lineLength and ribbonsPerLine respected').
ZigZagModeWith zig-zag cuts.
LeftModeNo indentation, infinitely long lines (lineLength ignored), but explicit new lines, i.e.,
text "one" $$ text "two", are respected.OneLineModeAll on one line, lineLength ignored and explicit new lines (
$$) are turned into spaces.
Instances4Eq, Show, Generic, Rep
Eq ModeDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJShow ModeDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJGeneric ModeDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJtype Rep Mode = D1 ('MetaDataDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJ"Mode"
"Text.PrettyPrint.Annotated.HughesPJ"
"pretty-1.1.3.6-a72d"
'False) ((C1 ('MetaCons"PageMode"
'PrefixI 'False) U1 :+: C1 ('MetaCons"ZigZagMode"
'PrefixI 'False) U1) :+: (C1 ('MetaCons"LeftMode"
'PrefixI 'False) U1 :+: C1 ('MetaCons"OneLineMode"
'PrefixI 'False) U1))
Render the Doc to a String using the default Style (see style).
Returns True if the document is empty
List version of <>.
List version of $$.
Nest (or indent) a document by a given number of positions (which may also be negative). nest satisfies the laws:
nest 0 x = xnest k (nest k' x) = nest (k+k') xnest k (x <> y) = nest k x <> nest k ynest k (x $$ y) = nest k x $$ nest k ynest k empty = empty
The side condition on the last law is needed because empty is a left identity for <>.
A TextDetails represents a fragment of text that will be output at some
point in a Doc.
Instances5Eq, Show, Generic, NFData, Rep
Eq TextDetailsDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJShow TextDetailsDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJGeneric TextDetailsDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJNFData TextDetailsDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJtype Rep TextDetails = D1 ('MetaDataDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJ"TextDetails"
"Text.PrettyPrint.Annotated.HughesPJ"
"pretty-1.1.3.6-a72d"
'False) (C1 ('MetaCons"Chr"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'SourceUnpack 'SourceStrict 'DecidedUnpack) (Rec0 Char)) :+: (C1 ('MetaCons"Str"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)) :+: C1 ('MetaCons"PStr"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String))))
A rendering style. Allows us to specify constraints to choose among the many different rendering options.
Constructors
Stylemode :: ModeThe rendering mode.
lineLength :: IntMaximum length of a line, in characters.
ribbonsPerLine :: FloatRatio of line length to ribbon length. A ribbon refers to the characters on a line excluding indentation. So a lineLength of 100, with a ribbonsPerLine of
2.0would only allow up to 50 characters of ribbon to be displayed on a line, while allowing it to be indented up to 50 characters.
Instances4Eq, Show, Generic, Rep
Eq StyleDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJShow StyleDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJGeneric StyleDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJtype Rep Style = D1 ('MetaDataDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJ"Style"
"Text.PrettyPrint.Annotated.HughesPJ"
"pretty-1.1.3.6-a72d"
'False) (C1 ('MetaCons"Style"
'PrefixI 'True) (S1 ('MetaSel ('Just"mode"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Mode) :*: (S1 ('MetaSel ('Just"lineLength"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel ('Just"ribbonsPerLine"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Float))))
The default style (mode=PageMode, lineLength=100, ribbonsPerLine=1.5).
Above, except that if the last line of the first argument stops at least one position before the first line of the second begins, these two lines are overlapped. For example:
text "hi" $$ nest 5 (text "there")lays out as
hi thererather than
hi
thereA document of height and width 1, containing a literal character.
"Paragraph fill" version of cat.
"Paragraph fill" version of sep.
fullRender :: ModeRendering mode.
-> IntLine length.
-> FloatRibbons per line.
-> (TextDetails -> a -> a)What to do with text.
-> aWhat to do at the end.
-> DocThe document.
-> aResult.
The general rendering interface. Please refer to the Style and Mode
types for a description of rendering mode, line length and ribbons.
hang d1 n d2 = sep [d1, nest n d2]List version of <+>.
Same as text. Used to be used for Bytestrings.
punctuate p [d1, ... dn] = [d1 <> p, d2 <> p, ... dn-1 <> p, dn]Render the Doc to a String using the given Style.
Some text with any width. (text s = sizedText (length s) s)
Some text, but without any width. Use for non-printing text such as a HTML or Latex tags
Instances8Pretty, …
Pretty CatDefined in BNFC-2.9.5 · BNFC.CFPretty IntegerDefined in BNFC-2.9.5 · BNFC.PrettyPrintPretty StringDefined in BNFC-2.9.5 · BNFC.PrettyPrintPretty IntDefined in BNFC-2.9.5 · BNFC.PrettyPrintPretty a => Pretty (BTree a)Defined in BNFC-2.9.5 · BNFC.Backend.Haskell.CFtoAlex3Pretty a => Pretty (WithPosition a)Defined in BNFC-2.9.5 · BNFC.CFPretty function => Pretty (Rul function)Defined in BNFC-2.9.5 · BNFC.CF(IsFun f, Pretty f) => Pretty (Exp' f)Defined in BNFC-2.9.5 · BNFC.CF
Put parens around document if given condition is true.
parensIf True "foo"(foo)
parensIf False "bar"bar
Render as String.
Separate vertically by a blank line.
"foo" $++$ "bar"foobar
"foo" $++$ emptyfoo
List version of $++$.
vsep [ "foo", nest 4 "bar" ]foo bar
vsep []List version of PrettyPrint.$+$.
vcat' [text "abc", nest 4 (text "def")]abc def
Pretty print separator with = (for assignments...).
"a" <=> "123"a = 123
prettyList Print a list of 0-1 elements on the same line as some preamble and from 2 elements on the following lines, indented.
prettyList 2 ("foo" <+> equals) lbrack rbrack comma []foo = []prettyList 2 ("foo" <+> equals) lbrack rbrack comma [ "a" ]foo = [a]prettyList 2 ("foo" <+> equals) lbrack rbrack comma [ "a", "b" ]foo = [ a , b ]
Used in the Agda backend.
Code block. A block of C/Java code, surrounded by {} and indented.
codeblock 4 ["abc", "def"]{ abc def}
Used in the C backend.