haskell-src-exts-1.18.2: Manipulating Haskell source: abstract syntax, lexer, parser, and pretty-printer

Portabilityportable
Stabilitystable
MaintainerNiklas Broberg, d00nibro@chalmers.se
Safe HaskellSafe-Inferred

Language.Haskell.Exts.Pretty

Contents

Description

Pretty printer for Haskell with extensions.

Synopsis

Pretty printing

class Pretty a

Things that can be pretty-printed, including all the syntactic objects in Language.Haskell.Exts.Syntax and Language.Haskell.Exts.Annotated.Syntax.

prettyPrintStyleMode :: Pretty a => Style -> PPHsMode -> a -> String

render the document with a given mode. renderWithMode :: PPHsMode -> Doc -> String renderWithMode = renderStyleMode P.style

render the document with defaultMode. render :: Doc -> String render = renderWithMode defaultMode

pretty-print with a given style and mode.

prettyPrintWithMode :: Pretty a => PPHsMode -> a -> String

pretty-print with the default style and a given mode.

prettyPrint :: Pretty a => a -> String

pretty-print with the default style and defaultMode.

Pretty-printing styles (from Text.PrettyPrint.HughesPJ)

data Style

Constructors

Style 

Fields

mode :: Mode
 
lineLength :: Int
 
ribbonsPerLine :: Float
 

Haskell formatting modes

data PPHsMode

Pretty-printing parameters.

Note: the onsideIndent must be positive and less than all other indents.

Constructors

PPHsMode 

Fields

classIndent :: Indent

indentation of a class or instance

doIndent :: Indent

indentation of a do-expression

multiIfIndent :: Indent

indentation of the body of a case expression

caseIndent :: Indent

indentation of the body of a multi-if expression

letIndent :: Indent

indentation of the declarations in a let expression

whereIndent :: Indent

indentation of the declarations in a where clause

onsideIndent :: Indent

indentation added for continuation lines that would otherwise be offside

spacing :: Bool

blank lines between statements?

layout :: PPLayout

Pretty-printing style to use

linePragmas :: Bool

add GHC-style LINE pragmas to output?

type Indent = Int

data PPLayout

Varieties of layout we can use.

Constructors

PPOffsideRule

classical layout

PPSemiColon

classical layout made explicit

PPInLine

inline decls, with newlines between them

PPNoLayout

everything on a single line

Instances

defaultMode :: PPHsMode

The default mode: pretty-print using the offside rule and sensible defaults.

Primitive Printers

prettyPrim :: Pretty a => a -> Doc

pretty-print with the default style and defaultMode.

prettyPrimWithMode :: Pretty a => PPHsMode -> a -> Doc

pretty-print with the default style and a given mode.