BNFC-2.9.4: A compiler front-end generator.
Safe HaskellSafe-Inferred
LanguageHaskell2010

BNFC.PrettyPrint

Description

Extends 'PrettyPrint'.

Synopsis

Documentation

class Pretty a where Source #

Overloaded function pretty.

Minimal complete definition

pretty | prettyPrec

Methods

pretty :: a -> Doc Source #

prettyPrec :: Int -> a -> Doc Source #

Instances

Instances details
Pretty Cat Source # 
Instance details

Defined in BNFC.CF

Methods

pretty :: Cat -> Doc Source #

prettyPrec :: Int -> Cat -> Doc Source #

Pretty String Source # 
Instance details

Defined in BNFC.PrettyPrint

Pretty Integer Source # 
Instance details

Defined in BNFC.PrettyPrint

Pretty Int Source # 
Instance details

Defined in BNFC.PrettyPrint

Methods

pretty :: Int -> Doc Source #

prettyPrec :: Int -> Int -> Doc Source #

(IsFun f, Pretty f) => Pretty (Exp' f) Source # 
Instance details

Defined in BNFC.CF

Methods

pretty :: Exp' f -> Doc Source #

prettyPrec :: Int -> Exp' f -> Doc Source #

Pretty function => Pretty (Rul function) Source # 
Instance details

Defined in BNFC.CF

Methods

pretty :: Rul function -> Doc Source #

prettyPrec :: Int -> Rul function -> Doc Source #

Pretty a => Pretty (WithPosition a) Source # 
Instance details

Defined in BNFC.CF

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

Render as String.

parensIf :: Bool -> Doc -> Doc Source #

Put parens around document if given condition is true.

>>> parensIf True "foo"
(foo)
>>> parensIf False "bar"
bar

($++$) :: Doc -> Doc -> Doc Source #

Separate vertically by a blank line.

>>> "foo" $++$ "bar"
foo

bar
>>> "foo" $++$ empty
foo

vsep :: [Doc] -> Doc Source #

List version of $++$.

>>> vsep [ "foo", nest 4 "bar" ]
foo

    bar
>>> vsep []

vcat' :: [Doc] -> Doc Source #

List version of $+$.

>>> vcat' [text "abc", nest 4 (text "def")]
abc
    def

(<=>) :: Doc -> Doc -> Doc Source #

Pretty print separator with = (for assignments...).

>>> "a" <=> "123"
a = 123

prettyList Source #

Arguments

:: Int

Indentation.

-> Doc

Preamble.

-> Doc

Left parenthesis.

-> Doc

Right parenthesis.

-> Doc

Separator (usually not including spaces).

-> [Doc]

List item.

-> Doc 

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.

codeblock :: Int -> [Doc] -> Doc Source #

Code block. A block of C/Java code, surrounded by {} and indented.

>>> codeblock 4 ["abc", "def"]
{
    abc
    def
}

Used in the C backend.