Language.Haskell.Exts.Pretty

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

Copyright | (c) Niklas Broberg 2004-2009, (c) The GHC Team, Noel Winstanley 1997-2000
License | BSD-style (see the file LICENSE.txt)
Maintainer | Niklas Broberg, d00nibro@chalmers.se
Stability | stable
Portability | portable
Safe Haskell | Safe
Language | Haskell98

Language.Haskell.Exts.Pretty

Contents

- Pretty printing
- Pretty-printing styles (from Text.PrettyPrint.HughesPJ)
- Haskell formatting modes
- Primitive Printers

Description

Pretty printer for Haskell with extensions.

Synopsis

- class Pretty a
- prettyPrintStyleMode :: Pretty a => Style -> PPHsMode -> a -> String
- prettyPrintWithMode :: Pretty a => PPHsMode -> a -> String
- prettyPrint :: Pretty a => a -> String
- data Style :: * = Style {
  - mode :: Mode
  - lineLength :: Int
  - ribbonsPerLine :: Float
  }
- style :: Style
- data Mode :: *
  - = PageMode
  - | ZigZagMode
  - | LeftMode
  - | OneLineMode
- data PPHsMode = PPHsMode {
  - classIndent :: Indent
  - doIndent :: Indent
  - multiIfIndent :: Indent
  - caseIndent :: Indent
  - letIndent :: Indent
  - whereIndent :: Indent
  - onsideIndent :: Indent
  - spacing :: Bool
  - layout :: PPLayout
  - linePragmas :: Bool
  }
- type Indent = Int
- data PPLayout
  - = PPOffsideRule
  - | PPSemiColon
  - | PPInLine
  - | PPNoLayout
- defaultMode :: PPHsMode
- prettyPrim :: Pretty a => a -> Doc
- prettyPrimWithMode :: Pretty a => PPHsMode -> a -> Doc

# 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.

Instances

Pretty Tool |
Pretty SrcSpan |
Pretty SrcLoc |
Pretty Alt |
Pretty FieldUpdate |
Pretty QualStmt |
Pretty Stmt |
Pretty PatField |
Pretty RPat |
Pretty RPatOp |
Pretty PXAttr |
Pretty Pat |
Pretty RuleVar |
Pretty Rule |
Pretty Activation |
Pretty Overlap |
Pretty ModulePragma |
Pretty CallConv |
Pretty Safety |
Pretty Splice |
Pretty Bracket |
Pretty XAttr |
Pretty XName |
Pretty Exp |
Pretty Literal |
Pretty Asst |
Pretty FunDep |
Pretty Kind |
Pretty TyVarBind |
Pretty Promoted |
Pretty Type |
Pretty GuardedRhs |
Pretty Rhs |
Pretty BangType |
Pretty InstDecl |
Pretty ClassDecl |
Pretty GadtDecl |
Pretty ConDecl |
Pretty QualConDecl |
Pretty Match |
Pretty IPBind |
Pretty DataOrNew |
Pretty Role |
Pretty BooleanFormula |
Pretty Annotation |
Pretty TypeEqn |
Pretty Decl |
Pretty Assoc |
Pretty ImportSpec |
Pretty ImportDecl |
Pretty Namespace |
Pretty ExportSpec |
Pretty Module |
Pretty CName |
Pretty Op |
Pretty QOp |
Pretty IPName |
Pretty Name |
Pretty QName |
Pretty SpecialCon |
Pretty ModuleName |
SrcInfo loc => Pretty (Alt loc) |
SrcInfo loc => Pretty (FieldUpdate loc) |
SrcInfo loc => Pretty (QualStmt loc) |
SrcInfo loc => Pretty (Stmt loc) |
SrcInfo loc => Pretty (PatField loc) |
SrcInfo loc => Pretty (RPat loc) |
Pretty (RPatOp l) |
SrcInfo loc => Pretty (PXAttr loc) |
SrcInfo loc => Pretty (Pat loc) |
Pretty (WarningText l) |
SrcInfo l => Pretty (RuleVar l) |
SrcInfo loc => Pretty (Rule loc) |
Pretty (Activation l) |
SrcInfo loc => Pretty (ModulePragma loc) |
Pretty (CallConv l) |
Pretty (Safety l) |
SrcInfo loc => Pretty (Splice loc) |
SrcInfo loc => Pretty (Bracket loc) |
SrcInfo loc => Pretty (XAttr loc) |
Pretty (XName l) |
SrcInfo loc => Pretty (Exp loc) |
Pretty (Literal l) |
SrcInfo l => Pretty (Asst l) |
SrcInfo l => Pretty (Context l) |
Pretty (FunDep l) |
Pretty (Kind l) |
Pretty (TyVarBind l) |
SrcInfo l => Pretty (Type l) |
SrcInfo loc => Pretty (GuardedRhs loc) |
SrcInfo loc => Pretty (Rhs loc) |
SrcInfo l => Pretty (BangType l) |
SrcInfo loc => Pretty (InstDecl loc) |
SrcInfo loc => Pretty (ClassDecl loc) |
SrcInfo l => Pretty (GadtDecl l) |
SrcInfo l => Pretty (FieldDecl l) |
SrcInfo l => Pretty (ConDecl l) |
SrcInfo l => Pretty (QualConDecl l) |
SrcInfo pos => Pretty (Match pos) |
SrcInfo loc => Pretty (IPBind loc) |
SrcInfo l => Pretty (Deriving l) |
SrcInfo l => Pretty (InstHead l) |
SrcInfo l => Pretty (InstRule l) |
Pretty (DeclHead l) |
Pretty (DataOrNew l) |
SrcInfo loc => Pretty (Annotation loc) |
SrcInfo pos => Pretty (Decl pos) |
Pretty (Assoc l) |
Pretty (ImportSpec l) |
Pretty (ImportSpecList l) |
SrcInfo pos => Pretty (ImportDecl pos) |
Pretty (ExportSpec l) |
Pretty (ExportSpecList l) |
Pretty (ModuleHead l) |
SrcInfo pos => Pretty (Module pos) |
Pretty (CName l) |
Pretty (Op l) |
Pretty (QOp l) |
Pretty (IPName l) |
Pretty (Name l) |
Pretty (QName l) |
Pretty (ModuleName l) |

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 :: *

A rendering style.

Constructors

Style |
Fields mode :: Mode The rendering mode lineLength :: Int Length of line, in chars ribbonsPerLine :: Float Ratio of line length to ribbon length

Instances

Eq Style |
Show Style |
Generic Style |
type Rep Style = D1 D1Style (C1 C1_0Style ((:*:) (S1 S1_0_0Style (Rec0 Mode)) ((:*:) (S1 S1_0_1Style (Rec0 Int)) (S1 S1_0_2Style (Rec0 Float))))) |

style :: Style

The default style (`mode=PageMode, lineLength=100, ribbonsPerLine=1.5`).

data Mode :: *

Rendering mode.

Constructors

PageMode | Normal
ZigZagMode | With zig-zag cuts
LeftMode | No indentation, infinitely long lines
OneLineMode | All on one line

Instances

Eq Mode |
Show Mode |
Generic Mode |
type Rep Mode = D1 D1Mode ((:+:) ((:+:) (C1 C1_0Mode U1) (C1 C1_1Mode U1)) ((:+:) (C1 C1_2Mode U1) (C1 C1_3Mode U1))) |

# 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

Eq PPLayout |

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.