Hets - the Heterogeneous Tool Set
Copyright(c) Christian Maeder and Uni Bremen 2006
LicenseGPLv2 or higher, see LICENSE.txt
MaintainerChristian.Maeder@dfki.de
Stabilityprovisional
Portabilityportable
Safe HaskellSafe

Common.Doc

Description

This module contains a document data type Doc for displaying (heterogenous) CASL specifications at least as plain text and latex (and maybe html as well)

Inspired by John Hughes's and Simon Peyton Jones's Pretty Printer Combinators in Text.PrettyPrint.HughesPJ, Thomas Hallgren's PrettyDoc within programatica, Daan Leijen's PPrint: A prettier printer 2001, and Olaf Chiti's Pretty printing with lazy Dequeues 2003

The main combinators are those of HughesPJ except nest, hang and $$. Instead of $$ $+$ must be used that always forces a line break. Indentation must be constructed using <> or <+>, i.e. text "spec" <+> MultilineBlock.

Also char, ptext, int, integer, float, double and rational do not exist. These can all be simulated using text (and show). There's an instance for Int in Common.DocUtils.

Furthermore, documents can no longer be tested with isEmpty. empty documents are silently ignored (as by HughesPJ) and often it is more natural (or even necessary anyway) to test the original data structure for emptiness.

Putting a document into braces should be done using specBraces (but a function braces is also exported), ensuring that opening and closing braces are in the same column if the whole document does not fit on a single line.

Rendering of documents is achieved by translations to the old Common.Lib.Pretty. For plain text simply show can be used. Any document can be translated to LaTeX via toLatex and then processed further by Common.PrintLaTeX. If you like the output is a different question, but the result should be legal LaTeX in conjunction with the hetcasl.sty file.

For nicer looking LaTeX the predefined symbol constants should be used! There is a difference between bullet and dot that is not visible in plain text.

There are also three kinds of keywords, a plain keyword, a topSigKey having the width of "preds", and a topKey having the width of "view". In plain text only inserted spaces are visible.

Strings in small caps are created by structId and indexed. The latter puts the string also into a LaTeX index.

In order to avoid considering display annotations and precedences, documents can be constructed using annoDoc, idDoc, and idApplDoc.

Currently only a few annotations (i.e. labels and %implied) are printed flushRight. This function is problematic as it does not prevent something to be appended using <> or <+>. Furthermore flushed parts are currently only visible in plain text, if they don't fit on the same line (as nest is used for indenting).

Further functions are documented in Common.DocUtils.

Examples can be produced using: hets -v2 -o pp.dol,pp.tex

Synopsis

the document type

data Doc Source #

an abstract data type

Instances

Instances details
Show Doc Source # 
Instance details

Defined in Common.Doc

Methods

showsPrec :: Int -> Doc -> ShowS

show :: Doc -> String

showList :: [Doc] -> ShowS

Semigroup Doc Source # 
Instance details

Defined in Common.Doc

Methods

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

sconcat :: NonEmpty Doc -> Doc

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

ItemTypeable (String, Doc) Source # 
Instance details

Defined in Common.Item

Methods

toIT :: (String, Doc) -> ItemType Source #

newtype Label Source #

Constructors

MkLabel Bool 

newtype StripComment Source #

Constructors

StripComment Bool 

primitive documents

empty Source #

Arguments

:: Doc

An empty document

space Source #

Arguments

:: Doc

A horizontal space (omitted at end of line)

semi Source #

Arguments

:: Doc

A ';' character

comma Source #

Arguments

:: Doc

A ',' character

colon Source #

Arguments

:: Doc

A : character

equals Source #

Arguments

:: Doc

A '=' character

converting strings into documents

plainText :: String -> Doc Source #

text :: String -> Doc Source #

codeToken :: String -> Doc Source #

commentText :: String -> Doc Source #

keyword :: String -> Doc Source #

topSigKey :: String -> Doc Source #

topKey :: String -> Doc Source #

indexed :: String -> Doc Source #

structId :: String -> Doc Source #

wrapping documents in delimiters

parens Source #

Arguments

:: Doc 
-> Doc

Wrap document in (...)

brackets Source #

Arguments

:: Doc 
-> Doc

Wrap document in [...]

braces Source #

Arguments

:: Doc 
-> Doc

Wrap document in {...}

specBraces Source #

Arguments

:: Doc 
-> Doc

Wrap document in {...}

quotes Source #

Arguments

:: Doc 
-> Doc

Wrap document in '...'

doubleQuotes Source #

Arguments

:: Doc 
-> Doc

Wrap document in "..."

combining documents

(<+>) infixr 6 Source #

Arguments

:: Doc 
-> Doc 
-> Doc

Beside, separated by space

hcat Source #

Arguments

:: [Doc] 
-> Doc

List version of <>

hsep Source #

Arguments

:: [Doc] 
-> Doc

List version of <+>

($+$) infixl 5 Source #

Arguments

:: Doc 
-> Doc 
-> Doc

Above, without dovetailing.

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

vertical composition with one blank line

vcat Source #

Arguments

:: [Doc] 
-> Doc

List version of $+$

vsep :: [Doc] -> Doc Source #

list version of ($++$)

sep Source #

Arguments

:: [Doc] 
-> Doc

Either hsep or vcat

cat Source #

Arguments

:: [Doc] 
-> Doc

Either hcat or vcat

fsep Source #

Arguments

:: [Doc] 
-> Doc

"Paragraph fill" version of sep

fcat Source #

Arguments

:: [Doc] 
-> Doc

"Paragraph fill" version of cat

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

symbols possibly rendered differently for Text or LaTeX

for Hybrid casl

docifying annotations and ids

annoDoc :: Annotation -> Doc Source #

we know how to print annotations

idDoc :: Id -> Doc Source #

for plain ids outside of terms

idLabelDoc :: Id -> Doc Source #

for newly declared ids

predIdApplDoc :: Id -> [Doc] -> Doc Source #

for mixfix applications of predicate identifiers

idApplDoc :: Id -> [Doc] -> Doc Source #

for mixfix applications and literal terms (may print "" for empty)

transforming to existing formats

manipulating documents

flushRight :: Doc -> Doc Source #

put document as far to the right as fits (for annotations)

changeGlobalAnnos :: (GlobalAnnos -> GlobalAnnos) -> Doc -> Doc Source #

add global annotations for proper mixfix printing

rmTopKey :: Doc -> Doc Source #

change top-level to plain keywords

showRaw :: Doc -> String Source #