PrintLe.hs revision 772abb916b994ad9461ddb11c88829251c5ac87a
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerModule : $Header$
99748618df243076900b1fef4983b149be9f3246Mingyi LiuCopyright : (c) Christian Maeder and Uni Bremen 2002-2003
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuMaintainer : maeder@tzi.de
9af1cee46dd16ba0c55a904a9d21ee2200bca2aeMingyi LiuStability : experimental
2eeec5240b424984e3ee26296da1eeab6c6d739eChristian MaederPortability : portable
cd2265c1c7279c901e34383275e0ca44a11d5d6cMingyi Liupretty printing a HasCASL environment
c12ed09f57ee4eb14e4d7a083e851f5e94f56246Christian Maederimport qualified Common.Lib.Map as Map
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maederinstance PrettyPrint ClassInfo where
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maeder printText0 ga (ClassInfo ks) =
e3f6a3eefafeb228198cafb8592bb2962ed856caChristian Maeder text lessS <+> printList0 ga ks
c12ed09f57ee4eb14e4d7a083e851f5e94f56246Christian MaederprintGenKind :: GenKind -> Doc
c12ed09f57ee4eb14e4d7a083e851f5e94f56246Christian MaederprintGenKind k = case k of
a1c74798e60ca27823b960cba6fb7d720b1de93fChristian Maeder Loose -> empty
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder Free -> text freeS <> space
96a3f4b391a98d0e91bc1f608398442f29d4c69ecmaeder Generated -> text generatedS <> space
876bd2c70a93981cc80f8376284616bce4a0fefcChristian Maederinstance PrettyPrint TypeDefn where
9af1cee46dd16ba0c55a904a9d21ee2200bca2aeMingyi Liu printText0 _ NoTypeDefn = empty
cd2265c1c7279c901e34383275e0ca44a11d5d6cMingyi Liu printText0 _ PreDatatype = text "%(data type)%"
9af1cee46dd16ba0c55a904a9d21ee2200bca2aeMingyi Liu printText0 _ (TypeVarDefn i)= text ("%(var_" ++ show i ++ ")%")
cd2265c1c7279c901e34383275e0ca44a11d5d6cMingyi Liu printText0 ga (AliasTypeDefn s) = text assignS
876bd2c70a93981cc80f8376284616bce4a0fefcChristian Maeder <+> printPseudoType ga s
492287e5f5e91783ee5e169f773f28cafe93a3a9Mingyi Liu printText0 ga (Supertype v t f) = text equalS <+>
492287e5f5e91783ee5e169f773f28cafe93a3a9Mingyi Liu braces (printText0 ga v
2d5366b63639aebbea53d81aa70b18e6d07bc8f9Mingyi Liu <+> printText0 ga t
9af1cee46dd16ba0c55a904a9d21ee2200bca2aeMingyi Liu <+> text dotS
9af1cee46dd16ba0c55a904a9d21ee2200bca2aeMingyi Liu <+> printText0 ga f)
96a3f4b391a98d0e91bc1f608398442f29d4c69ecmaeder printText0 ga (DatatypeDefn dd) =
96a3f4b391a98d0e91bc1f608398442f29d4c69ecmaeder text " %[" <> printText0 ga dd <> text "]%"
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian MaederprintAltDefn :: GlobalAnnos -> DataPat -> AltDefn -> Doc
05e70c22732cd4e251ef5d7c1c5ef3839c8b772eChristian MaederprintAltDefn ga dt (Construct mi ts p sels) = case mi of
3c5ef0f1dfeed0d74a506249f31655540c9a4908Christian Maeder Just i -> hang (printText0 ga i <+> colon
3c5ef0f1dfeed0d74a506249f31655540c9a4908Christian Maeder <+> printText0 ga (getConstrType dt p ts))
3c5ef0f1dfeed0d74a506249f31655540c9a4908Christian Maeder 2 $ fcat (map (parens . semiT_text ga) sels)
3c5ef0f1dfeed0d74a506249f31655540c9a4908Christian Maeder Nothing -> text (typeS ++ sS) <+> commaT_text ga ts
92506fa81791d08e42c998a32b1239900f860cf5Christian Maederinstance PrettyPrint Selector where
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder printText0 ga (Select mi t p) =
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder Just i -> printText0 ga i <+> (case p of
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder Partial -> text (colonS++quMark)
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder Total -> colon) <> space
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder Nothing -> empty) <> printText0 ga t
92506fa81791d08e42c998a32b1239900f860cf5Christian Maederinstance PrettyPrint TypeInfo where
3c5ef0f1dfeed0d74a506249f31655540c9a4908Christian Maeder printText0 ga (TypeInfo _ ks sups defn) =
3c5ef0f1dfeed0d74a506249f31655540c9a4908Christian Maeder hang (colon <+> printList0 ga ks
96a3f4b391a98d0e91bc1f608398442f29d4c69ecmaeder <> noPrint (null sups)
96a3f4b391a98d0e91bc1f608398442f29d4c69ecmaeder (space <> text lessS <+> printList0 ga sups))
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder 2 $ printText0 ga defn
c12ed09f57ee4eb14e4d7a083e851f5e94f56246Christian Maederinstance PrettyPrint ConstrInfo where
c12ed09f57ee4eb14e4d7a083e851f5e94f56246Christian Maeder printText0 ga (ConstrInfo i t) =
ac4396d6f4957cbb9451aa1f778ff5146ed4b2cfChristian Maeder printText0 ga i <+> colon <+> printText0 ga t
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maederinstance PrettyPrint OpDefn where
eeefbfb04e4bd24c0e64d1f8158b89bb00ab47b2cmaeder printText0 _ (NoOpDefn b) = text ("%(" ++ show b ++ ")%")
6ae1c0585e45e307316e6c74b6ebe6f7f3c5d0b0Christian Maeder printText0 _ VarDefn = text "%(var)%"
eeefbfb04e4bd24c0e64d1f8158b89bb00ab47b2cmaeder printText0 _ (ConstructData i) = text ("%(construct " ++
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maeder showId i ")%")
eeefbfb04e4bd24c0e64d1f8158b89bb00ab47b2cmaeder printText0 ga (SelectData c i) = text ("%(select from " ++
eeefbfb04e4bd24c0e64d1f8158b89bb00ab47b2cmaeder showId i " constructed by")
eeefbfb04e4bd24c0e64d1f8158b89bb00ab47b2cmaeder $$ printList0 ga c <> text ")%"
eeefbfb04e4bd24c0e64d1f8158b89bb00ab47b2cmaeder printText0 ga (Definition b t) = hang (printText0 ga (NoOpDefn b))
eeefbfb04e4bd24c0e64d1f8158b89bb00ab47b2cmaeder 2 (text equalS <+> printText0 ga t)
df0d74668ad4e978b8d367f8ce5caaad64792fa2cmaederinstance PrettyPrint OpInfo where
9af1cee46dd16ba0c55a904a9d21ee2200bca2aeMingyi Liu printText0 ga o = hang (colon <+> printText0 ga (opType o)
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder <> (case opAttrs o of
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder l -> comma <> commaT_text ga l))
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder 2 $ printText0 ga (opDefn o)
92506fa81791d08e42c998a32b1239900f860cf5Christian Maederinstance PrettyPrint OpInfos where
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder printText0 ga (OpInfos l) = vcat $ map (printText0 ga) l
92506fa81791d08e42c998a32b1239900f860cf5Christian Maederinstance PrettyPrint DataEntry where
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder printText0 ga (DataEntry im i k args alts) = hang
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder (printGenKind k <> text typeS <+> printText0 ga i
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder <> hcat (map (parens . printText0 ga) args))
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder 2 (text defnS <+> vcat (map (printAltDefn ga (i, args, star)) alts))
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder $$ nest 2 (noPrint (Map.isEmpty im)
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder (text withS <+> text (typeS ++ sS) <+> printText0 ga im))
92506fa81791d08e42c998a32b1239900f860cf5Christian Maederinstance PrettyPrint Sentence where
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder printText0 ga s = case s of
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder Formula t -> printText0 ga t
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder DatatypeSen ls -> vcat (map (printText0 ga) ls)
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder ProgEqSen _ _ pe -> text programS <+> printText0 ga pe
92506fa81791d08e42c998a32b1239900f860cf5Christian Maederinstance PrettyPrint Env where
064798f3c3fa09a775361e886ff11cb997f721a7Christian Maeder printText0 ga (Env{classMap=cm, typeMap=tm,
064798f3c3fa09a775361e886ff11cb997f721a7Christian Maeder assumps=as, sentences=se, envDiags=ds}) =
92506fa81791d08e42c998a32b1239900f860cf5Christian Maeder noPrint (Map.isEmpty cm) (header "Classes")
064798f3c3fa09a775361e886ff11cb997f721a7Christian Maeder $$ printMap0 ga cm
492287e5f5e91783ee5e169f773f28cafe93a3a9Mingyi Liu $$ noPrint (Map.isEmpty tm) (header "Type Constructors")
876bd2c70a93981cc80f8376284616bce4a0fefcChristian Maeder $$ printMap0 ga tm
e3f6a3eefafeb228198cafb8592bb2962ed856caChristian Maeder $$ noPrint (Map.isEmpty as) (header "Assumptions")
9af1cee46dd16ba0c55a904a9d21ee2200bca2aeMingyi Liu $$ printMap0 ga as
876bd2c70a93981cc80f8376284616bce4a0fefcChristian Maeder $$ noPrint (null se) (header "Sentences")
492287e5f5e91783ee5e169f773f28cafe93a3a9Mingyi Liu $$ vcat (map (printText0 ga) $ reverse se)
e3f6a3eefafeb228198cafb8592bb2962ed856caChristian Maeder $$ noPrint (null ds) (header "Diagnostics")
9af1cee46dd16ba0c55a904a9d21ee2200bca2aeMingyi Liu $$ vcat (map (printText0 ga) $ reverse ds)
a1c74798e60ca27823b960cba6fb7d720b1de93fChristian Maeder where header s = text "%%" <+> text s
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maeder <+> text (replicate (70 - length s) '-')
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maeder printMap0 :: (PrettyPrint a, Ord a, PrettyPrint b)
a1c74798e60ca27823b960cba6fb7d720b1de93fChristian Maeder => GlobalAnnos -> Map.Map a b -> Doc
a1c74798e60ca27823b960cba6fb7d720b1de93fChristian Maeder printMap0 g m =
a1c74798e60ca27823b960cba6fb7d720b1de93fChristian Maeder vcat(map (\ (a, b) -> hang (printText0 g a)
a1c74798e60ca27823b960cba6fb7d720b1de93fChristian Maeder 2 $ printText0 g b) l)
8cd72f2c9bc8a60a1f5f4439b4fcbffdf6feda79Christian Maederinstance PrettyPrint SymbolType where
8cd72f2c9bc8a60a1f5f4439b4fcbffdf6feda79Christian Maeder printText0 ga t = case t of
8cd72f2c9bc8a60a1f5f4439b4fcbffdf6feda79Christian Maeder OpAsItemType sc -> printText0 ga sc
492287e5f5e91783ee5e169f773f28cafe93a3a9Mingyi Liu TypeAsItemType k -> printText0 ga k
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maeder ClassAsItemType k -> printText0 ga k
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maederinstance PrettyPrint Symbol where
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maeder printText0 ga s = text (case symType s of
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maeder OpAsItemType _ -> opS
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maeder TypeAsItemType _ -> typeS
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maeder ClassAsItemType _ -> classS) <+>
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maeder printText0 ga (symName s) <+> text colonS <+>
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maeder printText0 ga (symType s)
492287e5f5e91783ee5e169f773f28cafe93a3a9Mingyi Liuinstance PrettyPrint RawSymbol where
492287e5f5e91783ee5e169f773f28cafe93a3a9Mingyi Liu printText0 ga rs = case rs of
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maeder AnID i -> printText0 ga i
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maeder AKindedId k i -> printSK k <> printText0 ga i
a59baad5cc2701cc8f2947b7a61eea117db8e423Christian Maeder AQualId i t -> printSK (symbTypeToKind t) <> printText0 ga i <+> colon
876bd2c70a93981cc80f8376284616bce4a0fefcChristian Maeder <+> printText0 ga t
e3f6a3eefafeb228198cafb8592bb2962ed856caChristian Maeder ASymbol s -> printText0 ga s