Copyright | (c) Christian Maeder and Uni Bremen 2006 |
---|---|
License | GPLv2 or higher, see LICENSE.txt |
Maintainer | Christian.Maeder@dfki.de |
Stability | provisional |
Portability | portable |
Safe Haskell | Safe-Inferred |
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
- data Doc
- newtype Label = MkLabel Bool
- newtype StripComment = StripComment Bool
- renderHtml :: GlobalAnnos -> Doc -> String
- renderExtHtml :: StripComment -> Label -> GlobalAnnos -> Doc -> String
- renderText :: GlobalAnnos -> Doc -> String
- renderExtText :: StripComment -> GlobalAnnos -> Doc -> String
- empty :: Doc
- space :: Doc
- semi :: Doc
- comma :: Doc
- colon :: Doc
- quMarkD :: Doc
- equals :: Doc
- lparen :: Doc
- rparen :: Doc
- lbrack :: Doc
- rbrack :: Doc
- lbrace :: Doc
- rbrace :: Doc
- plainText :: String -> Doc
- text :: String -> Doc
- codeToken :: String -> Doc
- commentText :: String -> Doc
- keyword :: String -> Doc
- topSigKey :: String -> Doc
- topKey :: String -> Doc
- indexed :: String -> Doc
- structId :: String -> Doc
- parens :: Doc -> Doc
- brackets :: Doc -> Doc
- braces :: Doc -> Doc
- specBraces :: Doc -> Doc
- quotes :: Doc -> Doc
- doubleQuotes :: Doc -> Doc
- (<>) :: Doc -> Doc -> Doc
- (<+>) :: Doc -> Doc -> Doc
- hcat :: [Doc] -> Doc
- hsep :: [Doc] -> Doc
- ($+$) :: Doc -> Doc -> Doc
- ($++$) :: Doc -> Doc -> Doc
- vcat :: [Doc] -> Doc
- vsep :: [Doc] -> Doc
- sep :: [Doc] -> Doc
- cat :: [Doc] -> Doc
- fsep :: [Doc] -> Doc
- fcat :: [Doc] -> Doc
- punctuate :: Doc -> [Doc] -> [Doc]
- sepByCommas :: [Doc] -> Doc
- sepBySemis :: [Doc] -> Doc
- dot :: Doc
- bullet :: Doc
- defn :: Doc
- less :: Doc
- greater :: Doc
- lambda :: Doc
- mapsto :: Doc
- funArrow :: Doc
- pfun :: Doc
- cfun :: Doc
- pcfun :: Doc
- exequal :: Doc
- forallDoc :: Doc
- exists :: Doc
- unique :: Doc
- cross :: Doc
- bar :: Doc
- notDoc :: Doc
- inDoc :: Doc
- andDoc :: Doc
- orDoc :: Doc
- implies :: Doc
- equiv :: Doc
- prefix_proc :: Doc
- sequential :: Doc
- interleave :: Doc
- synchronous :: Doc
- genpar_open :: Doc
- genpar_close :: Doc
- alpar_open :: Doc
- alpar_sep :: Doc
- alpar_close :: Doc
- external_choice :: Doc
- internal_choice :: Doc
- hiding_proc :: Doc
- ren_proc_open :: Doc
- ren_proc_close :: Doc
- dagger :: Doc
- vdash :: Doc
- dashv :: Doc
- breve :: Doc
- prettyAt :: Doc
- prettyHere :: Doc
- prettyBind :: Doc
- prettyUniv :: Doc
- prettyExist :: Doc
- annoDoc :: Annotation -> Doc
- idDoc :: Id -> Doc
- idLabelDoc :: Id -> Doc
- predIdApplDoc :: Id -> [Doc] -> Doc
- idApplDoc :: Id -> [Doc] -> Doc
- toLatex :: GlobalAnnos -> Doc -> Doc
- toLatexAux :: StripComment -> Label -> GlobalAnnos -> Doc -> Doc
- flushRight :: Doc -> Doc
- changeGlobalAnnos :: (GlobalAnnos -> GlobalAnnos) -> Doc -> Doc
- rmTopKey :: Doc -> Doc
- showRaw :: Doc -> String
the document type
newtype StripComment
renderHtml :: GlobalAnnos -> Doc -> String
renderExtHtml :: StripComment -> Label -> GlobalAnnos -> Doc -> String
renderText :: GlobalAnnos -> Doc -> String
renderExtText :: StripComment -> GlobalAnnos -> Doc -> String
primitive documents
converting strings into documents
commentText :: String -> Doc
wrapping documents in delimiters
combining documents
sepByCommas :: [Doc] -> Doc
sepBySemis :: [Doc] -> Doc
symbols possibly rendered differently for Text or LaTeX
prefix_proc :: Doc
sequential :: Doc
interleave :: Doc
synchronous :: Doc
genpar_open :: Doc
genpar_close :: Doc
alpar_open :: Doc
alpar_close :: Doc
hiding_proc :: Doc
ren_proc_open :: Doc
for Hybrid casl
prettyHere :: Doc
prettyBind :: Doc
prettyUniv :: Doc
prettyExist :: Doc
docifying annotations and ids
annoDoc :: Annotation -> Doc
we know how to print annotations
idLabelDoc :: Id -> Doc
for newly declared ids
predIdApplDoc :: Id -> [Doc] -> Doc
for mixfix applications of predicate identifiers
transforming to existing formats
toLatex :: GlobalAnnos -> Doc -> Doc
toLatexAux :: StripComment -> Label -> GlobalAnnos -> Doc -> Doc
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