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

Copyright | (c) The GHC Team Noel Winstanley 1997-2000
License | BSD-style (see the file libraries/base/LICENSE)
Maintainer | libraries@haskell.org
Stability | experimental
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 #

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

Instances

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

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

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

Eq Style |
Instance details Defined in Text.PrettyPrint.Annotated.HughesPJ Methods (==) :: Style -> Style -> Bool # (/=) :: Style -> Style -> Bool #
Show Style |
Instance details Defined in Text.PrettyPrint.Annotated.HughesPJ Methods showsPrec :: Int -> Style -> ShowS # show :: Style -> String # showList :: [Style] -> ShowS #
Generic Style |
Instance details Defined in Text.PrettyPrint.Annotated.HughesPJ Associated Types type Rep Style :: * -> * # Methods from :: Style -> Rep Style x # to :: Rep Style x -> Style #
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" 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 #

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

data Mode #

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

Eq Mode |
Instance details Defined in Text.PrettyPrint.Annotated.HughesPJ Methods (==) :: Mode -> Mode -> Bool # (/=) :: Mode -> Mode -> Bool #
Show Mode |
Instance details Defined in Text.PrettyPrint.Annotated.HughesPJ Methods showsPrec :: Int -> Mode -> ShowS # show :: Mode -> String # showList :: [Mode] -> ShowS #
Generic Mode |
Instance details Defined in Text.PrettyPrint.Annotated.HughesPJ Associated Types type Rep Mode :: * -> * # Methods from :: Mode -> Rep Mode x # to :: Rep Mode x -> Mode #
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" 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 :: * -> *)))

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

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 # |
Instance details Defined in Language.Haskell.Pretty Methods (==) :: PPLayout -> PPLayout -> Bool # (/=) :: PPLayout -> PPLayout -> Bool #

defaultMode :: PPHsMode #

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