PrintLe.hs revision c1031ac42b3f3d7d0fe7d9d6b54423a092d473a0
4b0a4c7dea0f67a233dcc42ce9bb18d36de109aeChristian MaederModule : $Header$
4b0a4c7dea0f67a233dcc42ce9bb18d36de109aeChristian MaederCopyright : (c) Christian Maeder and Uni Bremen 2002-2003
23f2c59644866aa82e90de353e77f9f1d1b51b9aChristian MaederMaintainer : maeder@tzi.de
4b0a4c7dea0f67a233dcc42ce9bb18d36de109aeChristian MaederStability : experimental
4b0a4c7dea0f67a233dcc42ce9bb18d36de109aeChristian MaederPortability : portable
4b0a4c7dea0f67a233dcc42ce9bb18d36de109aeChristian Maederpretty printing a HasCASL environment
f8f78a2c8796a387a4348cc672ae08e8d9f69315Christian Maederimport qualified Common.Lib.Map as Map
53301de22afd7190981b363b57c48df86fcb50f7Christian Maederinstance PrettyPrint ClassInfo where
f8f78a2c8796a387a4348cc672ae08e8d9f69315Christian Maeder printText0 ga (ClassInfo ks) =
024621f43239cfe9629e35d35a8669fad7acbba2Christian Maeder space <> text lessS <+> printList0 ga ks
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian MaederprintGenKind :: GenKind -> Doc
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian MaederprintGenKind k = case k of
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder Loose -> empty
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder Free -> text freeS <> space
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder Generated -> text generatedS <> space
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maederinstance PrettyPrint TypeDefn where
986e0e9cf8c2358f455460b3fc75ce7c5dcf0973Christian Maeder printText0 _ NoTypeDefn = empty
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder printText0 _ PreDatatype = space <> text "%(data type)%"
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder printText0 _ TypeVarDefn = space <> text "%(var)%"
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder printText0 ga (AliasTypeDefn s) = space <> text assignS
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder <+> printPseudoType ga s
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder printText0 ga (Supertype v t f) = space <> text equalS <+>
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder braces (printText0 ga v
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder <+> printText0 ga t
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder <+> text dotS
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder <+> printText0 ga f)
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder printText0 ga (DatatypeDefn k args alts) = text " %[" <>
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder printGenKind k <> (text typeS <+> text place
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder <+> printList0 ga args
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder <+> text defnS $$
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder vcat (map (printText0 ga) alts)) <> text "]%"
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maederinstance PrettyPrint AltDefn where
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder printText0 ga (Construct i ts p sels) =
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder printText0 ga i <+> colon
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder <+> listSep_text (space<>text funS<>space) ga ts <+>
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder text (case p of
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder Partial -> funS ++ quMark
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder Total -> funS) <+> text place
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder <+> hcat (map (parens . printText0 ga) sels)
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maederinstance PrettyPrint Selector where
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder printText0 ga (Select i t p) =
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder printText0 ga i <+> (case p of
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder Partial -> text ":?"
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder Total -> colon) <+> printText0 ga t
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maederinstance PrettyPrint TypeInfo where
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder printText0 ga (TypeInfo _ ks sups defn) =
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder space <> colon <+> printList0 ga ks
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder <> noPrint (null sups)
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder (space <> text lessS <+> printList0 ga sups)
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder <> printText0 ga defn
53301de22afd7190981b363b57c48df86fcb50f7Christian Maederinstance PrettyPrint ConstrInfo where
4b0a4c7dea0f67a233dcc42ce9bb18d36de109aeChristian Maeder printText0 ga (ConstrInfo i t) =
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder printText0 ga i <+> colon <+> printText0 ga t
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maederinstance PrettyPrint OpDefn where
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder printText0 _ (NoOpDefn b) = space <> text ("%(" ++ show b ++ ")%")
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder printText0 _ VarDefn = space <> text "%(var)%"
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder printText0 _ (ConstructData i) = space <> text ("%(construct " ++
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder showId i ")%")
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder printText0 ga (SelectData c i) = space <> text ("%(select from " ++
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder showId i " constructed by")
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder $$ printList0 ga c <> text ")%"
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder printText0 ga (Definition b t) = printText0 ga (NoOpDefn b) <+>
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder text equalS <+> printText0 ga t
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maederinstance PrettyPrint OpInfo where
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder printText0 ga o = space <> colon <+> printText0 ga (opType o)
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder <> (case opAttrs o of
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder l -> comma <> commaT_text ga l)
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder <> printText0 ga (opDefn o)
23f8d286586ff38a9e73052b2c7c04c62c5c638fChristian Maederinstance PrettyPrint OpInfos where
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder printText0 ga (OpInfos l) = vcat $ map (printText0 ga) l
b5699d97a9e2b4496f98d624f4b0a537986651c3Christian Maederinstance PrettyPrint a => PrettyPrint (Maybe a) where
b5699d97a9e2b4496f98d624f4b0a537986651c3Christian Maeder printText0 _ Nothing = empty
3cafc73a998493f9ed3d5e934c0ab80bcfb465c2Christian Maeder printText0 ga (Just c) = printText0 ga c
7c554e9d4a39b8eb3b0881f20807c95dd8e793aeChristian Maederinstance PrettyPrint DatatypeDefn where
3cafc73a998493f9ed3d5e934c0ab80bcfb465c2Christian Maeder printText0 ga (DatatypeConstr i1 i2 k args alts) =
7c554e9d4a39b8eb3b0881f20807c95dd8e793aeChristian Maeder printGenKind k <> text typeS
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder <+> printText0 ga i1 <+> parens
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder (text mapsTo <+> printText0 ga i2)
7c554e9d4a39b8eb3b0881f20807c95dd8e793aeChristian Maeder <+> (printList0 ga args
7c554e9d4a39b8eb3b0881f20807c95dd8e793aeChristian Maeder <+> text defnS $$
7c554e9d4a39b8eb3b0881f20807c95dd8e793aeChristian Maeder vcat (map (printText0 ga) alts))
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maederinstance PrettyPrint Sentence where
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder printText0 ga s = case s of
3cafc73a998493f9ed3d5e934c0ab80bcfb465c2Christian Maeder Formula t -> printText0 ga t
3cafc73a998493f9ed3d5e934c0ab80bcfb465c2Christian Maeder DatatypeSen ls -> vcat (map (printText0 ga) ls)
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder ProgEqSen _ _ pe -> text programS <+> printText0 ga pe
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maederinstance PrettyPrint Env where
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder printText0 ga (Env{classMap=cm, typeMap=tm,
bb3bdd4a260606a6184b5f5a5774ca6632ca597aChristian Maeder assumps=as, sentences=se, envDiags=ds}) =
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder noPrint (Map.isEmpty cm) (header "Classes")
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder $$ printMap0 ga cm
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder $$ noPrint (Map.isEmpty tm) (header "Type Constructors")
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder $$ printMap0 ga tm
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder $$ noPrint (Map.isEmpty as) (header "Assumptions")
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder $$ printMap0 ga as
ff9a53595208f532c25ac5168f772f48fd80fdb5Christian Maeder $$ noPrint (null se) (header "Sentences")
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder $$ vcat (map (printText0 ga) se)
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder $$ noPrint (null ds) (header "Diagnostics")
e8a2ca3a7b3e9a19ef03b6b1c0b5d03dbad6463cChristian Maeder $$ vcat (map (printText0 ga) $ reverse ds)
=> GlobalAnnos -> Map.Map a b -> Doc
let l = Map.toList m in