haskell-src-1.0.4.2: Support for manipulating Haskell source code

Copyright | (c) The GHC Team Noel Winstanley 1997-2000
License | BSD-3-Clause
Maintainer | Andreas Abel
Stability | stable
Portability | portable
Safe Haskell | None
Language | Haskell98

Language.Haskell.Pretty

Contents

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

Description

Pretty printer for Haskell.

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
  - caseIndent :: Indent
  - letIndent :: Indent
  - whereIndent :: Indent
  - onsideIndent :: Indent
  - spacing :: Bool
  - layout :: PPLayout
  - linePragmas :: Bool
  - comments :: Bool
  }
- type Indent = Int
- data PPLayout
  - = PPOffsideRule
  - | PPSemiColon
  - | PPInLine
  - | PPNoLayout
- defaultMode :: PPHsMode

# Pretty printing

class Pretty a Source #

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

#### Instances

Instances details

Pretty HsAlt Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsAlt -> Doc prettyPrec :: Int -> HsAlt -> Doc
Pretty HsAssoc Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsAssoc -> Doc prettyPrec :: Int -> HsAssoc -> Doc
Pretty HsBangType Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsBangType -> Doc prettyPrec :: Int -> HsBangType -> Doc
Pretty HsCName Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsCName -> Doc prettyPrec :: Int -> HsCName -> Doc
Pretty HsConDecl Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsConDecl -> Doc prettyPrec :: Int -> HsConDecl -> Doc
Pretty HsDecl Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsDecl -> Doc prettyPrec :: Int -> HsDecl -> Doc
Pretty HsExp Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsExp -> Doc prettyPrec :: Int -> HsExp -> Doc
Pretty HsExportSpec Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsExportSpec -> Doc prettyPrec :: Int -> HsExportSpec -> Doc
Pretty HsFieldUpdate Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsFieldUpdate -> Doc prettyPrec :: Int -> HsFieldUpdate -> Doc
Pretty HsGuardedAlt Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsGuardedAlt -> Doc prettyPrec :: Int -> HsGuardedAlt -> Doc
Pretty HsGuardedAlts Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsGuardedAlts -> Doc prettyPrec :: Int -> HsGuardedAlts -> Doc
Pretty HsGuardedRhs Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsGuardedRhs -> Doc prettyPrec :: Int -> HsGuardedRhs -> Doc
Pretty HsImportDecl Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsImportDecl -> Doc prettyPrec :: Int -> HsImportDecl -> Doc
Pretty HsImportSpec Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsImportSpec -> Doc prettyPrec :: Int -> HsImportSpec -> Doc
Pretty HsLiteral Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsLiteral -> Doc prettyPrec :: Int -> HsLiteral -> Doc
Pretty HsMatch Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsMatch -> Doc prettyPrec :: Int -> HsMatch -> Doc
Pretty HsModule Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsModule -> Doc prettyPrec :: Int -> HsModule -> Doc
Pretty HsName Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsName -> Doc prettyPrec :: Int -> HsName -> Doc
Pretty HsOp Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsOp -> Doc prettyPrec :: Int -> HsOp -> Doc
Pretty HsPat Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsPat -> Doc prettyPrec :: Int -> HsPat -> Doc
Pretty HsPatField Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsPatField -> Doc prettyPrec :: Int -> HsPatField -> Doc
Pretty HsQName Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsQName -> Doc prettyPrec :: Int -> HsQName -> Doc
Pretty HsQOp Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsQOp -> Doc prettyPrec :: Int -> HsQOp -> Doc
Pretty HsQualType Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsQualType -> Doc prettyPrec :: Int -> HsQualType -> Doc
Pretty HsRhs Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsRhs -> Doc prettyPrec :: Int -> HsRhs -> Doc
Pretty HsSafety Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsSafety -> Doc prettyPrec :: Int -> HsSafety -> Doc
Pretty HsStmt Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsStmt -> Doc prettyPrec :: Int -> HsStmt -> Doc
Pretty HsType Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: HsType -> Doc prettyPrec :: Int -> HsType -> Doc
Pretty Module Source # |
Instance details Defined in Language.Haskell.Pretty Methods pretty :: Module -> Doc prettyPrec :: Int -> Module -> Doc

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

pretty-print with a given style and mode.

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

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

prettyPrint :: Pretty a => a -> String Source #

pretty-print with the default style and `defaultMode`.

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

data Style Source #

A rendering style. Allows us to specify constraints to choose among the many different rendering options.

Constructors

Style |

Fields

- mode :: Mode

  The rendering mode.

- lineLength :: Int

  Maximum length of a line, in characters.

- ribbonsPerLine :: Float

  Ratio 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.0` would only allow up to 50 characters of ribbon to be displayed on a line, while allowing it to be indented up to 50 characters.

#### Instances

Instances details

Generic Style |

Instance details

Defined in Text.PrettyPrint.Annotated.HughesPJ

Associated Types

type Rep Style |

Instance details

Defined in Text.PrettyPrint.Annotated.HughesPJ

type Rep Style = D1 ('MetaData "Style" "Text.PrettyPrint.Annotated.HughesPJ" "pretty-1.1.3.6-inplace" '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))))

Methods

from :: Style -> Rep Style x Source #

to :: Rep Style x -> Style Source #

Show Style |
Instance details Defined in Text.PrettyPrint.Annotated.HughesPJ Methods showsPrec :: Int -> Style -> ShowS Source # show :: Style -> String Source # showList :: [Style] -> ShowS Source #
Eq Style |
Instance details Defined in Text.PrettyPrint.Annotated.HughesPJ Methods (==) :: Style -> Style -> Bool Source # (/=) :: Style -> Style -> Bool Source #
type Rep Style |

Instance details

Defined in Text.PrettyPrint.Annotated.HughesPJ

type Rep Style = D1 ('MetaData "Style" "Text.PrettyPrint.Annotated.HughesPJ" "pretty-1.1.3.6-inplace" '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))))

style :: Style Source #

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

data Mode Source #

Rendering mode.

Constructors

PageMode | Normal rendering (`lineLength` and `ribbonsPerLine` respected').
ZigZagMode | With zig-zag cuts.
LeftMode | No indentation, infinitely long lines (`lineLength` ignored), but explicit new lines, i.e., `text "one" $$ text "two"`, are respected.
OneLineMode | All on one line, `lineLength` ignored and explicit new lines (`$$`) are turned into spaces.

#### Instances

Instances details

Generic Mode |

Instance details

Defined in Text.PrettyPrint.Annotated.HughesPJ

Associated Types

type Rep Mode |

Instance details

Defined in Text.PrettyPrint.Annotated.HughesPJ

type Rep Mode = D1 ('MetaData "Mode" "Text.PrettyPrint.Annotated.HughesPJ" "pretty-1.1.3.6-inplace" 'False) ((C1 ('MetaCons "PageMode" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "ZigZagMode" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "LeftMode" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "OneLineMode" 'PrefixI 'False) (U1 :: Type -> Type)))

Methods

from :: Mode -> Rep Mode x Source #

to :: Rep Mode x -> Mode Source #

Show Mode |
Instance details Defined in Text.PrettyPrint.Annotated.HughesPJ Methods showsPrec :: Int -> Mode -> ShowS Source # show :: Mode -> String Source # showList :: [Mode] -> ShowS Source #
Eq Mode |
Instance details Defined in Text.PrettyPrint.Annotated.HughesPJ Methods (==) :: Mode -> Mode -> Bool Source # (/=) :: Mode -> Mode -> Bool Source #
type Rep Mode |

Instance details

Defined in Text.PrettyPrint.Annotated.HughesPJ

type Rep Mode = D1 ('MetaData "Mode" "Text.PrettyPrint.Annotated.HughesPJ" "pretty-1.1.3.6-inplace" 'False) ((C1 ('MetaCons "PageMode" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "ZigZagMode" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "LeftMode" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "OneLineMode" 'PrefixI 'False) (U1 :: Type -> Type)))

# Haskell formatting modes

data PPHsMode Source #

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.

- caseIndent :: Indent

  Indentation of the body of a `case` 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?

- comments :: Bool

  (not implemented yet)

type Indent = Int Source #

data PPLayout Source #

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

Instances details

Eq PPLayout Source # |
Instance details Defined in Language.Haskell.Pretty Methods (==) :: PPLayout -> PPLayout -> Bool Source # (/=) :: PPLayout -> PPLayout -> Bool Source #

defaultMode :: PPHsMode Source #

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