Hets - the Heterogeneous Tool Set

Portabilityportable
Stabilityprovisional
MaintainerChristian.Maeder@dfki.de
Safe HaskellSafe-Inferred

Common.Doc

Contents

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.het,pp.tex

Synopsis

the document type

data Doc

an abstract data type

Instances

newtype Label

Constructors

MkLabel Bool 

newtype StripComment

Constructors

StripComment Bool 

primitive documents

empty

Arguments

:: Doc

An empty document

space

Arguments

:: Doc

A horizontal space (omitted at end of line)

semi

Arguments

:: Doc

A ';' character

comma

Arguments

:: Doc

A ',' character

colon

Arguments

:: Doc

A : character

equals

Arguments

:: Doc

A '=' character

converting strings into documents

wrapping documents in delimiters

parens

Arguments

:: Doc 
-> Doc

Wrap document in (...)

brackets

Arguments

:: Doc 
-> Doc

Wrap document in [...]

braces

Arguments

:: Doc 
-> Doc

Wrap document in {...}

specBraces

Arguments

:: Doc 
-> Doc

Wrap document in {...}

quotes

Arguments

:: Doc 
-> Doc

Wrap document in '...'

doubleQuotes

Arguments

:: Doc 
-> Doc

Wrap document in "..."

combining documents

(<>)

Arguments

:: Doc 
-> Doc 
-> Doc

Beside

(<+>)

Arguments

:: Doc 
-> Doc 
-> Doc

Beside, separated by space

hcat

Arguments

:: [Doc] 
-> Doc

List version of <>

hsep

Arguments

:: [Doc] 
-> Doc

List version of <+>

($+$)

Arguments

:: Doc 
-> Doc 
-> Doc

Above, without dovetailing.

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

vertical composition with one blank line

vcat

Arguments

:: [Doc] 
-> Doc

List version of $+$

vsep :: [Doc] -> Doc

list version of '($++$)'

sep

Arguments

:: [Doc] 
-> Doc

Either hsep or vcat

cat

Arguments

:: [Doc] 
-> Doc

Either hcat or vcat

fsep

Arguments

:: [Doc] 
-> Doc

"Paragraph fill" version of sep

fcat

Arguments

:: [Doc] 
-> Doc

"Paragraph fill" version of cat

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

symbols possibly rendered differently for Text or LaTeX

dot :: Doc

bar :: Doc

for Hybrid casl

docifying annotations and ids

annoDoc :: Annotation -> Doc

we know how to print annotations

idDoc :: Id -> Doc

for plain ids outside of terms

idLabelDoc :: Id -> Doc

for newly declared ids

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

for mixfix applications of predicate identifiers

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

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

transforming to existing formats

manipulating documents

flushRight :: Doc -> Doc

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

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

add global annotations for proper mixfix printing

rmTopKey :: Doc -> Doc

change top-level to plain keywords