free-compiler-0.3.0.0: A Haskell to Coq compiler.

Safe HaskellSafe
LanguageHaskell2010

FreeC.Pretty

Contents

Description

This module contains functions for pretty printing.

We are using the Pretty type class from the 'wl-pprint-text' package.

Synopsis

Documentation

(<$$>) :: Doc -> Doc -> Doc #

(<++>) :: Doc -> Doc -> Doc #

(<+>) :: Doc -> Doc -> Doc #

(<//>) :: Doc -> Doc -> Doc #

(</>) :: Doc -> Doc -> Doc #

align :: Doc -> Doc #

angles :: Doc -> Doc #

beside :: Doc -> Doc -> Doc #

bool :: Bool -> Doc #

braces :: Doc -> Doc #

cat :: [Doc] -> Doc #

char :: Char -> Doc #

column :: (Int -> Doc) -> Doc #

dot :: Doc #

enclose :: Doc -> Doc -> Doc -> Doc #

encloseSep :: Doc -> Doc -> Doc -> [Doc] -> Doc #

fill :: Int -> Doc -> Doc #

fillBreak :: Int -> Doc -> Doc #

fillCat :: [Doc] -> Doc #

fillSep :: [Doc] -> Doc #

group :: Doc -> Doc #

hPutDoc :: Handle -> Doc -> IO () #

hang :: Int -> Doc -> Doc #

hcat :: [Doc] -> Doc #

hsep :: [Doc] -> Doc #

indent :: Int -> Doc -> Doc #

int :: Int -> Doc #

list :: [Doc] -> Doc #

nest :: Int -> Doc -> Doc #

nesting :: (Int -> Doc) -> Doc #

parens :: Doc -> Doc #

punctuate :: Doc -> [Doc] -> [Doc] #

putDoc :: Doc -> IO () #

sep :: [Doc] -> Doc #

text :: Text -> Doc #

tupled :: [Doc] -> Doc #

vcat :: [Doc] -> Doc #

vsep :: [Doc] -> Doc #

width :: Doc -> (Int -> Doc) -> Doc #

data Doc #

Instances
Show Doc 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

IsString Doc 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Semigroup Doc 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

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

sconcat :: NonEmpty Doc -> Doc Source #

stimes :: Integral b => b -> Doc -> Doc Source #

Monoid Doc 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Pretty Doc 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: Doc -> Doc #

prettyList :: [Doc] -> Doc #

class Pretty a where #

Minimal complete definition

pretty

Methods

pretty :: a -> Doc #

prettyList :: [a] -> Doc #

Instances
Pretty Bool 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: Bool -> Doc #

prettyList :: [Bool] -> Doc #

Pretty Char 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: Char -> Doc #

prettyList :: [Char] -> Doc #

Pretty Double 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: Double -> Doc #

prettyList :: [Double] -> Doc #

Pretty Float 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: Float -> Doc #

prettyList :: [Float] -> Doc #

Pretty Int 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: Int -> Doc #

prettyList :: [Int] -> Doc #

Pretty Integer 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: Integer -> Doc #

prettyList :: [Integer] -> Doc #

Pretty () 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: () -> Doc #

prettyList :: [()] -> Doc #

Pretty Text 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: Text -> Doc #

prettyList :: [Text] -> Doc #

Pretty Text 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: Text -> Doc #

prettyList :: [Text] -> Doc #

Pretty Sentence Source #

Sentences often need to be pretty printed in the tests and when writing the generated Coq code to the console or a file.

Instance details

Defined in FreeC.Backend.Coq.Pretty

Methods

pretty :: Sentence -> Doc #

prettyList :: [Sentence] -> Doc #

Pretty Term Source #

Terms often need to be pretty printed in the tests.

Instance details

Defined in FreeC.Backend.Coq.Pretty

Methods

pretty :: Term -> Doc #

prettyList :: [Term] -> Doc #

Pretty Doc 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: Doc -> Doc #

prettyList :: [Doc] -> Doc #

Pretty SrcSpan Source #

Pretty instance for a source span that displays the filename and the start and end position of the source span.

If the source span spans only a single line, the end position is omitted.

Instance details

Defined in FreeC.IR.SrcSpan

Methods

pretty :: SrcSpan -> Doc #

prettyList :: [SrcSpan] -> Doc #

Pretty SrcFile Source #

Pretty instance for a source file that displays the filename.

Instance details

Defined in FreeC.IR.SrcSpan

Methods

pretty :: SrcFile -> Doc #

prettyList :: [SrcFile] -> Doc #

Pretty Message Source #

Pretty instance for messages.

The format of the messages is based on the format used by GHC:

[file]:[line]:[column]: [severity]:
    [message-contents]
       |
[line] | [line of code ... culprit  ... ]
       |                   ^^^^^^^

If no location information is attached to the message, a place holder is text displayed instead of the filename, and start position and no code snippet will be shown.

Lists of messages are separated by a newline.

Instance details

Defined in FreeC.Monad.Reporter

Methods

pretty :: Message -> Doc #

prettyList :: [Message] -> Doc #

Pretty Severity Source #

Pretty instance for message severity levels.

Instance details

Defined in FreeC.Monad.Reporter

Methods

pretty :: Severity -> Doc #

prettyList :: [Severity] -> Doc #

Pretty DeclIdent Source #

Pretty instance for names of declarations.

Instance details

Defined in FreeC.IR.Syntax.Name

Pretty QName Source #

Pretty instance for qualifiable identifiers and symbols.

Instance details

Defined in FreeC.IR.Syntax.Name

Methods

pretty :: QName -> Doc #

prettyList :: [QName] -> Doc #

Pretty Name Source #

Pretty instance for identifiers and symbols.

Instance details

Defined in FreeC.IR.Syntax.Name

Methods

pretty :: Name -> Doc #

prettyList :: [Name] -> Doc #

Pretty Type Source #

Pretty instance for type expressions.

Instance details

Defined in FreeC.IR.Syntax.Type

Methods

pretty :: Type -> Doc #

prettyList :: [Type] -> Doc #

Pretty TypeVarDecl Source #

Pretty instance for type variable declaration.

Instance details

Defined in FreeC.IR.Syntax.TypeVarDecl

Pretty TypeScheme Source #

Pretty instance for type schemes.

Instance details

Defined in FreeC.IR.Syntax.TypeScheme

Pretty ConDecl Source #

Pretty instance for data constructor declarations.

Instance details

Defined in FreeC.IR.Syntax.TypeDecl

Methods

pretty :: ConDecl -> Doc #

prettyList :: [ConDecl] -> Doc #

Pretty TypeDecl Source #

Pretty instance for type declarations.

Instance details

Defined in FreeC.IR.Syntax.TypeDecl

Methods

pretty :: TypeDecl -> Doc #

prettyList :: [TypeDecl] -> Doc #

Pretty Pragma Source #

Pretty instance for custom {-# FreeC ... #-} pragmas.

Instance details

Defined in FreeC.IR.Syntax.Pragma

Methods

pretty :: Pragma -> Doc #

prettyList :: [Pragma] -> Doc #

Pretty Comment Source #

Pretty instance for comments.

Instance details

Defined in FreeC.IR.Syntax.Pragma

Methods

pretty :: Comment -> Doc #

prettyList :: [Comment] -> Doc #

Pretty Bind Source #

Pretty instance for let expression binds.

Instance details

Defined in FreeC.IR.Syntax.Expr

Methods

pretty :: Bind -> Doc #

prettyList :: [Bind] -> Doc #

Pretty VarPat Source #

Pretty instance for variable patterns.

Instance details

Defined in FreeC.IR.Syntax.Expr

Methods

pretty :: VarPat -> Doc #

prettyList :: [VarPat] -> Doc #

Pretty ConPat Source #

Pretty instance for constructor patterns.

Instance details

Defined in FreeC.IR.Syntax.Expr

Methods

pretty :: ConPat -> Doc #

prettyList :: [ConPat] -> Doc #

Pretty Alt Source #

Pretty instance for case expression alternatives.

Instance details

Defined in FreeC.IR.Syntax.Expr

Methods

pretty :: Alt -> Doc #

prettyList :: [Alt] -> Doc #

Pretty Expr Source #

Pretty instance for expressions.

If the expression contains type annotations, the output quickly becomes practically unreadable. Consider stripping type annotations before pretty printing (see FreeC.IR.Strip) to improve readability.

Instance details

Defined in FreeC.IR.Syntax.Expr

Methods

pretty :: Expr -> Doc #

prettyList :: [Expr] -> Doc #

Pretty FuncDecl Source #

Pretty instance for function declarations.

Instance details

Defined in FreeC.IR.Syntax.FuncDecl

Methods

pretty :: FuncDecl -> Doc #

prettyList :: [FuncDecl] -> Doc #

Pretty TypeSig Source #

Pretty instance for type signatures.

Instance details

Defined in FreeC.IR.Syntax.FuncDecl

Methods

pretty :: TypeSig -> Doc #

prettyList :: [TypeSig] -> Doc #

Pretty TopLevelDecl Source #

Pretty instance for top-level declarations.

Instance details

Defined in FreeC.IR.Syntax.Module

Pretty ImportDecl Source #

Pretty instance for import declarations.

Instance details

Defined in FreeC.IR.Syntax.Module

Pretty Pos Source #

Pretty prints a position.

Instance details

Defined in FreeC.IR.Subterm

Methods

pretty :: Pos -> Doc #

prettyList :: [Pos] -> Doc #

Pretty Keyword Source #

Pretty prints a keyword.

Instance details

Defined in FreeC.Frontend.IR.Token

Methods

pretty :: Keyword -> Doc #

prettyList :: [Keyword] -> Doc #

Pretty Token Source #

Pretty prints a token.

Instance details

Defined in FreeC.Frontend.IR.Token

Methods

pretty :: Token -> Doc #

prettyList :: [Token] -> Doc #

Pretty Declaration Source #

Declarations are a common AST node.

Instance details

Defined in FreeC.Backend.Agda.Pretty

Methods

pretty :: Declaration -> Doc #

prettyList :: [Declaration] -> Doc #

Pretty Expr Source #

Exprs are a common AST node.

Instance details

Defined in FreeC.Backend.Agda.Pretty

Methods

pretty :: Expr -> Doc #

prettyList :: [Expr] -> Doc #

Pretty a => Pretty [a] 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: [a] -> Doc #

prettyList :: [[a]] -> Doc #

Pretty a => Pretty (Maybe a) 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: Maybe a -> Doc #

prettyList :: [Maybe a] -> Doc #

Pretty a => Pretty (TrailingLine a) Source #

Pretty prints the wrapped value of a TrailingLine and adds the trailing newline to the resulting document.

Instance details

Defined in FreeC.Pretty

Pretty contents => Pretty (ModuleOf [contents]) Source #

Pretty instance for modules.

Instance details

Defined in FreeC.IR.Syntax.Module

Methods

pretty :: ModuleOf [contents] -> Doc #

prettyList :: [ModuleOf [contents]] -> Doc #

Pretty (Module l) Source #

Pretty instance for module nodes of Haskell Source Extensions AST.

Instance details

Defined in FreeC.Frontend.Haskell.Pretty

Methods

pretty :: Module l -> Doc #

prettyList :: [Module l] -> Doc #

Gallina a => Pretty (PrettyCoq a) Source #

Pretty instance for nodes of the Coq AST.

When pretty printing a list of nodes, the individual documents are concatenated with newlines.

Instance details

Defined in FreeC.Backend.Coq.Pretty

Methods

pretty :: PrettyCoq a -> Doc #

prettyList :: [PrettyCoq a] -> Doc #

Pretty decl => Pretty (DependencyComponent decl) Source #

Pretty instance that pretty prints the declarations of a strongly connected component.

Each declaration is on its own line and indented by two spaces. The first line of the document indicates whether the component was recursive or not.

Instance details

Defined in FreeC.IR.DependencyGraph

Pretty (DependencyGraph node) Source #

Pretty instance that converts a dependency graph to the DOT format.

Instance details

Defined in FreeC.IR.DependencyGraph

Methods

pretty :: DependencyGraph node -> Doc #

prettyList :: [DependencyGraph node] -> Doc #

Pretty a => Pretty (Subst a) Source #

Substitutions can be pretty printed for testing purposes.

Instance details

Defined in FreeC.IR.Subst

Methods

pretty :: Subst a -> Doc #

prettyList :: [Subst a] -> Doc #

(Pretty a, Pretty b) => Pretty (a, b) 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: (a, b) -> Doc #

prettyList :: [(a, b)] -> Doc #

(Pretty a, Pretty b, Pretty c) => Pretty (a, b, c) 
Instance details

Defined in Text.PrettyPrint.Leijen.Text

Methods

pretty :: (a, b, c) -> Doc #

prettyList :: [(a, b, c)] -> Doc #

Pretty Printing

prettySeparated :: Pretty a => Doc -> [a] -> Doc Source #

Pretty prints a list of pretty printable values by concatenating their documents with the given separator in between.

prettyMaybe :: (Pretty a, Pretty b) => a -> Maybe b -> Doc Source #

Pretty prints the value contained in the given Maybe value or pretty prints a default value.

There is also a Pretty instance for Maybe that produces the empty document if the value is Nothing.

prettyString :: String -> Doc Source #

Pretty prints a string without automatic newlines if the string does not fit onto the page.

prettyText :: String -> Doc Source #

Pretty prints a string such that long lines that don't fit the page are automatically broken between two words.

prettyLines :: String -> Doc Source #

Pretty prints each line of the given string using prettyText and concatenates the resulting documents vertically.

Trailing Lines

data TrailingLine a Source #

A pretty printable value with a trailing newline.

Instances
Pretty a => Pretty (TrailingLine a) Source #

Pretty prints the wrapped value of a TrailingLine and adds the trailing newline to the resulting document.

Instance details

Defined in FreeC.Pretty

Rendering

renderPretty' :: Pretty a => a -> SimpleDoc Source #

Pretty prints a value with a maximum line length of 120 characters of which 80 are allowed to be non-indentation characters.

Output

putPretty :: Pretty a => a -> IO () Source #

Prints a pretty printable value to stdout.

putPrettyLn :: Pretty a => a -> IO () Source #

Prints a pretty printable value to stdout with trailing newline.

hPutPretty :: Pretty a => Handle -> a -> IO () Source #

Prints a pretty printable value to the given file handle.

hPutPrettyLn :: Pretty a => Handle -> a -> IO () Source #

Prints a pretty printable value to the given file handle and adds a trailing newline.

writePrettyFile :: Pretty a => FilePath -> a -> IO () Source #

Writes a pretty printable value to the file located at the given path.

There is always a trailing newline at the end of the file.

Conversion

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

Converts a pretty printable value to a string.