PrintAs.hs revision 6e2c88c65d50b2e44f7afa165e6a5fac0724f08c
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder{- |
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian MaederModule : $Header$
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederDescription : print the abstract syntax so that it can be re-parsed
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian MaederCopyright : (c) Christian Maeder and Uni Bremen 2003
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederMaintainer : Christian.Maeder@dfki.de
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian MaederStability : experimental
413db961f13e112716509b6d61d7a7bbf50c98b2Christian MaederPortability : portable
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maederprinting data types of the abstract syntax
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-}
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maedermodule HasCASL.PrintAs where
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport HasCASL.As
d48085f765fca838c1d972d2123601997174583dChristian Maederimport HasCASL.AsUtils
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport HasCASL.FoldTerm
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport HasCASL.Builtin
0df692ce8b9293499b2e1768458613a63e7b5cd0Christian Maederimport Common.Id
d48085f765fca838c1d972d2123601997174583dChristian Maederimport Common.Keywords
47d6bc7bc9a708427f96be8d805f712697ad3d9eChristian Maederimport Common.DocUtils
23a00c966f2aa8da525d7a7c51933c99964426c0Christian Maederimport Common.Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport Common.AS_Annotation
df33a9af92444f63ad545da6bb326aac9284318eChristian Maederimport Data.List (groupBy, mapAccumL)
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
3c5cc698b0c061209ff83eb8de027daef5ae922aChristian Maeder-- | short cut for: if b then empty else d
3c5cc698b0c061209ff83eb8de027daef5ae922aChristian MaedernoPrint :: Bool -> Doc -> Doc
3c5cc698b0c061209ff83eb8de027daef5ae922aChristian MaedernoPrint b d = if b then empty else d
3c5cc698b0c061209ff83eb8de027daef5ae922aChristian Maeder
413db961f13e112716509b6d61d7a7bbf50c98b2Christian MaedernoNullPrint :: [a] -> Doc -> Doc
413db961f13e112716509b6d61d7a7bbf50c98b2Christian MaedernoNullPrint = noPrint . null
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedersemiDs :: Pretty a => [a] -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedersemiDs = fsep . punctuate semi . map pretty
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedersemiAnnoted :: Pretty a => [Annoted a] -> Doc
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaedersemiAnnoted = vcat . map (printSemiAnno pretty True)
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty Variance where
ce3928e71520030ad0275b72050a8f4377f9313cChristian Maeder pretty = sidDoc . mkSimpleId . show
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty a => Pretty (AnyKind a) where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty knd = case knd of
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maeder ClassKind ci -> pretty ci
eab576044505ba1fbc64610323053490fbd9e82cChristian Maeder FunKind v k1 k2 _ -> fsep
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder [ pretty v <> (case k1 of
81946e2b3f6dde6167f48769bd02c7a634736856Christian Maeder FunKind _ _ _ _ -> parens
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> id) (pretty k1)
eab576044505ba1fbc64610323053490fbd9e82cChristian Maeder , funArrow, pretty k2]
eab576044505ba1fbc64610323053490fbd9e82cChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedervarOfTypeArg :: TypeArg -> Id
120efeede54a5f7650cda8e91363bd6832eac9a9Christian MaedervarOfTypeArg (TypeArg i _ _ _ _ _ _) = i
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maederinstance Pretty TypePattern where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty tp = case tp of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder TypePattern name@(Id ts cs _) args _ ->
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder let ds = map (pretty . varOfTypeArg) args in
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder if placeCount name == length args then
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder let (ras, dts) = mapAccumL ( \ l t -> if isPlace t then
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder case l of
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder x : r -> (r, x)
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder _ -> error "Pretty TypePattern"
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder else (l, printTypeToken t)) ds ts
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder in fsep $ dts ++ (if null cs then [] else
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder [brackets $ sepByCommas $ map printTypeId cs])
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder ++ ras
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder else printTypeId name <+> fsep ds
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder TypePatternToken t -> printTypeToken t
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder MixfixTypePattern ts -> fsep $ map pretty ts
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder BracketTypePattern k l _ -> bracket k $ ppWithCommas l
ce3928e71520030ad0275b72050a8f4377f9313cChristian Maeder TypePatternArg t _ -> parens $ pretty t
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- | put proper brackets around a document
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maederbracket :: BracketKind -> Doc -> Doc
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maederbracket b = case b of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Parens -> parens
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Squares -> brackets
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Braces -> specBraces
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder NoBrackets -> id
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- | print a 'Kind' plus a preceding colon (or nothing)
92aa1b88f02d2a413da60dba78acd34312e6f29aChristian MaederprintKind :: Kind -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintKind k = noPrint (k == universe) $ printVarKind InVar (VarKind k)
d92635f998347112e5d5803301c2abfe7832ab65Christian Maeder
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder-- | print the kind of a variable with its variance and a preceding colon
81946e2b3f6dde6167f48769bd02c7a634736856Christian MaederprintVarKind :: Variance -> VarKind -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintVarKind e vk = case vk of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Downset t -> less <+> pretty t
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder VarKind k -> colon <+> pretty e <> pretty k
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder MissingKind -> empty
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata TypePrec = Outfix | Prefix | Lazyfix | ProdInfix | FunInfix | Absfix
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder deriving (Eq, Ord)
024621f43239cfe9629e35d35a8669fad7acbba2Christian Maeder
99f16a0f9ca757410960ff51a79b034503384fe2Christian MaederparenPrec :: TypePrec -> (TypePrec, Doc) -> Doc
932f71e6f6f404ac139399c3d6a2b906ba055cbdChristian MaederparenPrec p1 (p2, d) = if p2 < p1 then d else parens d
d48085f765fca838c1d972d2123601997174583dChristian Maeder
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaederprintTypeToken :: Token -> Doc
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaederprintTypeToken t = let
d48085f765fca838c1d972d2123601997174583dChristian Maeder l = ("*", cross) : map ( \ (a, d) -> (show a, d) )
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder [ (FunArr, funArrow)
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder , (PFunArr, pfun)
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder , (ContFunArr, cfun)
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder , (PContFunArr, pcfun) ]
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder in case lookup (tokStr t) l of
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder Just d -> d
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder _ -> pretty t
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaederprintTypeId :: Id -> Doc
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaederprintTypeId (Id ts cs _) = let (toks, pls) = splitMixToken ts in
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder fcat $ map printTypeToken toks
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder ++ (if null cs then [] else [brackets $ sepByCommas $ map printTypeId cs])
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder ++ map printTypeToken pls
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder
df33a9af92444f63ad545da6bb326aac9284318eChristian MaedertoMixType :: Type -> (TypePrec, Doc)
df33a9af92444f63ad545da6bb326aac9284318eChristian MaedertoMixType typ = case typ of
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder TypeName name _ _ -> (Outfix, printTypeId name)
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder TypeToken tt -> (Outfix, printTypeToken tt)
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder TypeAbs v t _ ->
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder (Absfix, sep [ lambda <+> pretty v, bullet <+> snd (toMixType t)])
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder ExpandedType t1 _ -> toMixType t1 -- here we print the unexpanded type
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder BracketType k l _ ->
04a1ed0b360858b85de6f449b84df4eab81b3fc9Christian Maeder (Outfix, bracket k $ sepByCommas $ map (snd . toMixType) l)
04a1ed0b360858b85de6f449b84df4eab81b3fc9Christian Maeder KindedType t kind _ ->
04a1ed0b360858b85de6f449b84df4eab81b3fc9Christian Maeder (Lazyfix, fsep [parenPrec Lazyfix $ toMixType t, colon, pretty kind])
932f71e6f6f404ac139399c3d6a2b906ba055cbdChristian Maeder MixfixType ts -> (Prefix, fsep $ map (snd . toMixType) ts)
ae8052003e1ec7247597f034069db0939a7387e1Christian Maeder TypeAppl t1 t2 -> let
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder (topTy, tyArgs) = getTypeApplAux False typ
99f16a0f9ca757410960ff51a79b034503384fe2Christian Maeder aArgs = (Prefix, sep [ parenPrec ProdInfix $ toMixType t1
99f16a0f9ca757410960ff51a79b034503384fe2Christian Maeder , parenPrec Prefix $ toMixType t2 ])
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder in case topTy of
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maeder TypeName name@(Id ts cs _) _k _i ->
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maeder case map toMixType tyArgs of
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maeder [dArg] -> case ts of
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maeder [e] | name == lazyTypeId ->
932f71e6f6f404ac139399c3d6a2b906ba055cbdChristian Maeder (Lazyfix, pretty e <+> parenPrec Lazyfix dArg)
932f71e6f6f404ac139399c3d6a2b906ba055cbdChristian Maeder [e1, e2, e3] | not (isPlace e1) && isPlace e2
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maeder && not (isPlace e3) && null cs ->
932f71e6f6f404ac139399c3d6a2b906ba055cbdChristian Maeder (Outfix, fsep [pretty e1, snd dArg, pretty e3])
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder _ -> aArgs
99f16a0f9ca757410960ff51a79b034503384fe2Christian Maeder [dArg1, dArg2] -> case ts of
99f16a0f9ca757410960ff51a79b034503384fe2Christian Maeder [_, e2, _] | isInfix name && null cs ->
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder if tokStr e2 == prodS then
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder (ProdInfix, fsep
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder [ parenPrec ProdInfix dArg1
932f71e6f6f404ac139399c3d6a2b906ba055cbdChristian Maeder , cross, parenPrec ProdInfix dArg2])
04a1ed0b360858b85de6f449b84df4eab81b3fc9Christian Maeder else -- assume fun type
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder (FunInfix, fsep
d48085f765fca838c1d972d2123601997174583dChristian Maeder [ parenPrec FunInfix dArg1
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder , printTypeToken e2, snd dArg2])
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder _ -> aArgs
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder dArgs -> if isProductIdWithArgs name $ length tyArgs then
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder (ProdInfix, fsep $ punctuate (space <> cross) $
d48085f765fca838c1d972d2123601997174583dChristian Maeder map (parenPrec ProdInfix) dArgs) else aArgs
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder _ -> aArgs
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maederinstance Pretty Type where
932f71e6f6f404ac139399c3d6a2b906ba055cbdChristian Maeder pretty = snd . toMixType
35cd0c10843c2cdbbe29f00a2a5d7e5e4f2d0064Christian Maeder
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian MaederprintTypeScheme :: PolyId -> TypeScheme -> Doc
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian MaederprintTypeScheme (PolyId _ tys _) (TypeScheme vs t _) =
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maeder let tdoc = pretty t in
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maeder if null vs || not (null tys) then tdoc else
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maeder fsep [forallDoc, semiDs vs, bullet <+> tdoc]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder-- no curried notation for bound variables
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maederinstance Pretty TypeScheme where
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder pretty = printTypeScheme (PolyId applId [] nullRange)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty Partiality where
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder pretty p = case p of
99edc5256de959957a8c27b05ae4ad4f0572233dChristian Maeder Partial -> quMarkD
48c4688439e0aade4faeebf25ca8b16d661e47afChristian Maeder Total -> empty
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty Quantifier where
37354e3ed68875fb527338105a610df481f98cb0Christian Maeder pretty q = case q of
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder Universal -> forallDoc
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder Existential -> exists
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Unique -> unique
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty TypeQual where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty q = case q of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder OfType -> colon
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder AsType -> text asS
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder InType -> inDoc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Inferred -> colon
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty Term where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty = printTerm . rmSomeTypes
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederisSimpleTerm :: Term -> Bool
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederisSimpleTerm trm = case trm of
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder QualVar _ -> True
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder QualOp _ _ _ _ _ _ -> True
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ResolvedMixTerm _ _ _ _ -> True
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ApplTerm _ _ _ -> True
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder TupleTerm _ _ -> True
9d75ab580dbf51b7ca60903fb32e7f38d939d326Christian Maeder TermToken _ -> True
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder BracketTerm _ _ _ -> True
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> False
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | used only to produce CASL applications
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederisSimpleArgTerm :: Term -> Bool
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian MaederisSimpleArgTerm trm = case trm of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder QualVar vd -> not (isPatVarDecl vd)
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder QualOp _ _ _ _ _ _ -> True
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder ResolvedMixTerm n _ l _ -> placeCount n /= 0 || not (null l)
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder TupleTerm _ _ -> True
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder BracketTerm _ _ _ -> True
9d75ab580dbf51b7ca60903fb32e7f38d939d326Christian Maeder _ -> False
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian MaederhasRightQuant :: Term -> Bool
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian MaederhasRightQuant t = case t of
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder QuantifiedTerm {} -> True
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder LambdaTerm {} -> True
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder CaseTerm {} -> True
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder LetTerm Let _ _ _ -> True
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder ResolvedMixTerm n _ ts _ | endPlace n && placeCount n == length ts
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder -> hasRightQuant (last ts)
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder ApplTerm (ResolvedMixTerm n _ [] _) t2 _ | endPlace n ->
79bf169bcae16ce390683c698bae248c1ed6ab13Christian Maeder case t2 of
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder TupleTerm ts _ | placeCount n == length ts -> hasRightQuant (last ts)
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder _ -> hasRightQuant t2
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder ApplTerm _ t2 _ -> hasRightQuant t2
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder _ -> False
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaederzipArgs :: Id -> [Term] -> [Doc] -> [Doc]
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaederzipArgs n ts ds = case (ts, ds) of
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder (t : r, d : s) -> let
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder p = parenTermDoc t d
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder e = if hasRightQuant t then parens d else p
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder in if null r && null s && endPlace n then
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder [if hasRightQuant t then d else p]
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder else e : zipArgs n r s
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder _ -> []
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaederisPatVarDecl :: VarDecl -> Bool
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaederisPatVarDecl (VarDecl v ty _ _) = case ty of
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder TypeName t _ _ -> isSimpleId v && take 2 (show t) == "_v"
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder _ -> False
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian Maeder
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederparenTermDoc :: Term -> Doc -> Doc
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederparenTermDoc trm = if isSimpleTerm trm then id else parens
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian Maeder
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian MaederprintTermRec :: FoldRec Doc (Doc, Doc)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintTermRec = FoldRec
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian Maeder { foldQualVar = \ _ vd@(VarDecl v _ _ _) ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder if isPatVarDecl vd then pretty v
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder else parens $ keyword varS <+> pretty vd
ce3928e71520030ad0275b72050a8f4377f9313cChristian Maeder , foldQualOp = \ _ br n t tys k _ ->
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder (if null tys || k == Infer then id else
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder (<> brackets (ppWithCommas tys))) $
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian Maeder parens $ fsep [pretty br, pretty n, colon, printTypeScheme n $
b06572b54fcf9d6976cfff57da22672f996b4748Christian Maeder if isPred br then unPredTypeScheme t else t]
b06572b54fcf9d6976cfff57da22672f996b4748Christian Maeder , foldResolvedMixTerm =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder \ (ResolvedMixTerm _ _ os _) n@(Id toks cs ps) tys ts _ ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder let pn = placeCount n in if pn == length ts || null ts then
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder let ds = zipArgs n os ts in
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder if null tys then idApplDoc n ds
b06572b54fcf9d6976cfff57da22672f996b4748Christian Maeder else let (ftoks, _) = splitMixToken toks
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder fId = Id ftoks cs ps
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder (fts, rts) = splitAt (placeCount fId) $ if null ts
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder then replicate pn $ pretty placeTok else ds
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder in fsep $ (idApplDoc fId fts <> brackets (ppWithCommas tys))
b06572b54fcf9d6976cfff57da22672f996b4748Christian Maeder : rts
b06572b54fcf9d6976cfff57da22672f996b4748Christian Maeder else idApplDoc applId [idDoc n, parens $ sepByCommas ts]
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder , foldApplTerm = \ (ApplTerm o1 o2 _) t1 t2 _ ->
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder case (o1, o2) of
ce3928e71520030ad0275b72050a8f4377f9313cChristian Maeder -- comment out the following two guards for CASL applications
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder (ResolvedMixTerm n _ [] _, TupleTerm ts@(_ : _) _)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | placeCount n == length ts ->
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder idApplDoc n (zipArgs n ts $ map printTerm ts)
84e7cfca5b97aef300acdaa8cf63a3572f9151c0Christian Maeder (ResolvedMixTerm n _ [] _, _) | placeCount n == 1
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder -> idApplDoc n $ zipArgs n [o2] [t2]
84e7cfca5b97aef300acdaa8cf63a3572f9151c0Christian Maeder _ -> idApplDoc applId $ zipArgs applId [o1, o2] [t1, t2]
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder , foldTupleTerm = \ _ ts _ -> parens $ sepByCommas ts
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder , foldTypedTerm = \ (TypedTerm ot _ _ _) t q typ _ -> fsep [(case ot of
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder LambdaTerm {} -> parens
ce3928e71520030ad0275b72050a8f4377f9313cChristian Maeder LetTerm {} -> parens
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder CaseTerm {} -> parens
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder QuantifiedTerm {} -> parens
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder TypedTerm {} | elem q [Inferred, OfType] -> parens
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder ApplTerm (ResolvedMixTerm n _ [] _) arg _ ->
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder let pn = placeCount n in case arg of
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder TupleTerm ts@(_ : _) _ | pn == length ts -> parens
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian Maeder _ | pn == 1 -> parens
99edc5256de959957a8c27b05ae4ad4f0572233dChristian Maeder _ -> id
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian Maeder _ -> id) t, pretty q, pretty typ]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , foldQuantifiedTerm = \ _ q vs t _ ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder fsep [pretty q, printGenVarDecls vs, bullet <+> t]
a53f4b7cb8bedee4fb7a8b386efcb47246467948Christian Maeder , foldLambdaTerm = \ (LambdaTerm ops _ _ _) ps q t _ ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder fsep [ lambda
99edc5256de959957a8c27b05ae4ad4f0572233dChristian Maeder , case ops of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder [p] -> case p of
99edc5256de959957a8c27b05ae4ad4f0572233dChristian Maeder TupleTerm [] _ -> empty
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian Maeder QualVar vd@(VarDecl v ty _ _) ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty v <+> if isPatVarDecl vd then empty
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder else printVarDeclType ty
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> head ps
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> if all ( \ p -> case p of
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder QualVar vd -> not $ isPatVarDecl vd
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder _ -> False) ops
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder then printGenVarDecls $ map
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ( \ (QualVar vd) -> GenVarDecl vd) ops
966e627a1c06b302a06d59d08b8ab45905f3509cChristian Maeder else fcat $ map parens ps
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , (case q of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Partial -> bullet
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Total -> bullet <> text exMark) <+> t]
ce3928e71520030ad0275b72050a8f4377f9313cChristian Maeder , foldCaseTerm = \ _ t es _ ->
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder fsep [text caseS, t, text ofS,
eab576044505ba1fbc64610323053490fbd9e82cChristian Maeder cat $ punctuate (space <> bar <> space) $
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder map (printEq0 funArrow) es]
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian Maeder , foldLetTerm = \ _ br es t _ ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder let des = sep $ punctuate semi $ map (printEq0 equals) es
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder in case br of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Let -> fsep [sep [text letS <+> des, text inS], t]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Where -> fsep [sep [t, text whereS], des]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Program -> text programS <+> des
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , foldTermToken = \ _ t -> pretty t
9d75ab580dbf51b7ca60903fb32e7f38d939d326Christian Maeder , foldMixTypeTerm = \ _ q t _ -> pretty q <+> pretty t
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder , foldMixfixTerm = \ _ ts -> fsep ts
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder , foldBracketTerm = \ _ k l _ -> bracket k $ sepByCommas l
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , foldAsPattern = \ _ (VarDecl v _ _ _) p _ ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder fsep [pretty v, text asP, p]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , foldProgEq = \ _ p t _ -> (p, t) }
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintTerm :: Term -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintTerm = foldTerm printTermRec
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederrmTypeRec :: MapRec
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederrmTypeRec = mapRec
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder { foldQualOp = \ t _ (PolyId i _ _) _ tys k ps ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder if elem i $ map fst bList then ResolvedMixTerm i
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder (if k == Infer then [] else tys) [] ps else t
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder , foldTypedTerm = \ _ nt q ty ps -> case q of
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder Inferred -> nt
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder _ -> case nt of
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder TypedTerm _ oq oty _ | oty == ty || oq == InType -> nt
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder QualVar (VarDecl _ oty _ _) | oty == ty -> nt
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder _ -> TypedTerm nt q ty ps }
9d75ab580dbf51b7ca60903fb32e7f38d939d326Christian Maeder
028f19cdb09d52bb2fd207399b6fa874540d1670Christian MaederrmSomeTypes :: Term -> Term
028f19cdb09d52bb2fd207399b6fa874540d1670Christian MaederrmSomeTypes = foldTerm rmTypeRec
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder-- | put parenthesis around applications
028f19cdb09d52bb2fd207399b6fa874540d1670Christian MaederparenTermRec :: MapRec
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederparenTermRec = let
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder addParAppl t = case t of
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder ResolvedMixTerm _ _ [] _ -> t
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder QualVar _ -> t
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder QualOp _ _ _ _ _ _ -> t
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder TermToken _ -> t
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder BracketTerm _ _ _ -> t
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder TupleTerm _ _ -> t
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder _ -> TupleTerm [t] nullRange
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder in mapRec
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder { foldApplTerm = \ _ t1 t2 ps ->
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder ApplTerm (addParAppl t1) (addParAppl t2) ps
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder , foldResolvedMixTerm = \ _ n tys ts ps ->
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder ResolvedMixTerm n tys (map addParAppl ts) ps
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , foldTypedTerm = \ _ t q typ ps ->
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder TypedTerm (addParAppl t) q typ ps
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder , foldMixfixTerm = \ _ ts -> MixfixTerm $ map addParAppl ts
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder , foldAsPattern = \ _ v p ps -> AsPattern v (addParAppl p) ps
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder }
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian MaederparenTerm :: Term -> Term
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederparenTerm = foldTerm parenTermRec
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder-- | print an equation with different symbols between pattern and term
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederprintEq0 :: Doc -> (Doc, Doc) -> Doc
120efeede54a5f7650cda8e91363bd6832eac9a9Christian MaederprintEq0 s (p, t) = sep [p, hsep [s, t]]
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian MaederprintGenVarDecls :: [GenVarDecl] -> Doc
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian MaederprintGenVarDecls = fsep . punctuate semi . map
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder ( \ l -> case l of
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder [x] -> pretty x
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder GenVarDecl (VarDecl _ t _ _) : _ -> sep
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder [ ppWithCommas (map ( \ (GenVarDecl (VarDecl v _ _ _)) -> v) l)
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder , printVarDeclType t]
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder GenTypeVarDecl (TypeArg _ e c _ _ _ _) : _ -> sep
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder [ ppWithCommas (map ( \ (GenTypeVarDecl v) -> varOfTypeArg v) l)
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder , printVarKind e c]
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder _ -> error "printGenVarDecls") . groupBy sameType
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder
413db961f13e112716509b6d61d7a7bbf50c98b2Christian MaedersameType :: GenVarDecl -> GenVarDecl -> Bool
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedersameType g1 g2 = case (g1, g2) of
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder (GenVarDecl (VarDecl _ t1 Comma _), GenVarDecl (VarDecl _ t2 _ _))
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder | t1 == t2 -> True
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder (GenTypeVarDecl (TypeArg _ e1 c1 _ _ Comma _),
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder GenTypeVarDecl (TypeArg _ e2 c2 _ _ _ _)) | e1 == e2 && c1 == c2 -> True
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> False
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintVarDeclType :: Type -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintVarDeclType t = case t of
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder MixfixType [] -> empty
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> colon <+> pretty t
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty VarDecl where
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder pretty (VarDecl v t _ _) = pretty v <+> printVarDeclType t
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty GenVarDecl where
d92635f998347112e5d5803301c2abfe7832ab65Christian Maeder pretty gvd = case gvd of
9c5b1136299d9052e4e995614a3a36a051a2682fChristian Maeder GenVarDecl v -> pretty v
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder GenTypeVarDecl tv -> pretty tv
ce3928e71520030ad0275b72050a8f4377f9313cChristian Maeder
da245da15da78363c896e44ea97a14ab1f83eb50Christian Maederinstance Pretty TypeArg where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty (TypeArg v e c _ _ _ _) =
32a2f5f00ff72c095b39629101043db4407974f9Christian Maeder pretty v <+> printVarKind e c
32a2f5f00ff72c095b39629101043db4407974f9Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | don't print an empty list and put parens around longer lists
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintList0 :: (Pretty a) => [a] -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintList0 l = case l of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder [] -> empty
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder [x] -> pretty x
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> parens $ ppWithCommas l
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian Maederinstance Pretty BasicSpec where
011b7807145efa2af0c7470414a96e0133c26dbcChristian Maeder pretty (BasicSpec l) = if null l then specBraces empty else
011b7807145efa2af0c7470414a96e0133c26dbcChristian Maeder changeGlobalAnnos addBuiltins . vcat $ map pretty l
011b7807145efa2af0c7470414a96e0133c26dbcChristian Maeder
011b7807145efa2af0c7470414a96e0133c26dbcChristian Maederinstance Pretty ProgEq where
011b7807145efa2af0c7470414a96e0133c26dbcChristian Maeder pretty (ProgEq p t ps) = printEq0 equals $ foldEq printTermRec
011b7807145efa2af0c7470414a96e0133c26dbcChristian Maeder $ ProgEq (rmSomeTypes p) (rmSomeTypes t) ps
011b7807145efa2af0c7470414a96e0133c26dbcChristian Maeder
011b7807145efa2af0c7470414a96e0133c26dbcChristian Maederinstance Pretty BasicItem where
011b7807145efa2af0c7470414a96e0133c26dbcChristian Maeder pretty bi = case bi of
011b7807145efa2af0c7470414a96e0133c26dbcChristian Maeder SigItems s -> pretty s
2fbe4699ac5d2a8bafe8c0c8aa41e6717d36d5ceChristian Maeder ProgItems l _ -> sep [keyword programS, semiAnnoted l]
2fbe4699ac5d2a8bafe8c0c8aa41e6717d36d5ceChristian Maeder ClassItems i l _ -> let
2fbe4699ac5d2a8bafe8c0c8aa41e6717d36d5ceChristian Maeder b = semiAnnos pretty l
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder p = plClass l
79bf169bcae16ce390683c698bae248c1ed6ab13Christian Maeder in case i of
3d8c57f00a518c990c07eef14f4da8d390322093Christian Maeder Plain -> topSigKey (classS ++ if p then "es" else "") <+> b
3d8c57f00a518c990c07eef14f4da8d390322093Christian Maeder Instance -> sep [keyword classS <+>
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder keyword (instanceS ++ if p then sS else ""), b]
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder GenVarItems l _ -> topSigKey (varS ++ pluralS l) <+> printGenVarDecls l
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder FreeDatatype l _ -> sep
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder [ keyword freeS <+> keyword (typeS ++ pluralS l)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , semiAnnos pretty l]
359e79584976afb25d37502669a67093a75f3c5bChristian Maeder GenItems l _ -> let gkw = keyword generatedS in
359e79584976afb25d37502669a67093a75f3c5bChristian Maeder (if all (isDatatype . item) l then \ i -> gkw <+> rmTopKey i
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder else \ i -> sep [gkw, specBraces i])
359e79584976afb25d37502669a67093a75f3c5bChristian Maeder $ vcat $ map (printAnnoted pretty) l
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder AxiomItems vs fs _ -> sep
359e79584976afb25d37502669a67093a75f3c5bChristian Maeder [ if null vs then empty else forallDoc <+> printGenVarDecls vs
359e79584976afb25d37502669a67093a75f3c5bChristian Maeder , case fs of
bf4263f9dab040818efc7a67172aab8f32218061Christian Maeder [] -> empty
32a2f5f00ff72c095b39629101043db4407974f9Christian Maeder _ -> let pp = addBullet . pretty in
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder vcat $ map (printAnnoted pp) (init fs)
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder ++ [printSemiAnno pp True $ last fs]]
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder Internal l _ -> sep
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder [ keyword internalS
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder , specBraces $ vcat $ map (printAnnoted pretty) l]
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederplClass :: [Annoted ClassItem] -> Bool
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederplClass l = case map item l of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ : _ : _ -> True
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder [ClassItem (ClassDecl (_ : _ : _) _ _) _ _] -> True
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> False
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederpluralS :: [a] -> String
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian MaederpluralS l = case l of
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder _ : _ : _ -> sS
62fb92b09f732b770317b46a793b60b960d5f481Christian Maeder _ -> ""
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian MaederisDatatype :: SigItems -> Bool
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian MaederisDatatype si = case si of
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder TypeItems _ l _ -> all
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder ((\ t -> case t of
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder Datatype _ -> True
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian Maeder _ -> False) . item) l
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian Maeder _ -> False
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian Maeder
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maederinstance Pretty OpBrand where
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian Maeder pretty b = keyword $ show b
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian Maeder
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maederinstance Pretty SigItems where
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder pretty si = case si of
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder TypeItems i l _ -> let b = semiAnnos pretty l in case i of
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder Plain -> topSigKey ((if all (isSimpleTypeItem . item) l
fec19c3890105f041a9ab00aabb3602db45d287aChristian Maeder then typeS else typeS) ++ plTypes l) <+> b
fec19c3890105f041a9ab00aabb3602db45d287aChristian Maeder Instance ->
fec19c3890105f041a9ab00aabb3602db45d287aChristian Maeder sep [keyword typeS <+> keyword (instanceS ++ plTypes l), b]
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder OpItems b l _ -> noNullPrint l $ topSigKey (show b ++ plOps l)
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder <+> let po = (prettyOpItem $ isPred b) in
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder if case item $ last l of
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder OpDecl _ _ a@(_ : _) _ -> case last a of
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder UnitOpAttr {} -> True
fec19c3890105f041a9ab00aabb3602db45d287aChristian Maeder _ -> False
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder OpDefn {} -> True
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder _ -> False
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder then vcat (map (printSemiAnno po True) l)
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder else semiAnnos po l
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederplTypes :: [Annoted TypeItem] -> String
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian MaederplTypes l = case map item l of
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder _ : _ : _ -> sS
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder [TypeDecl (_ : _ : _) _ _] -> sS
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder [SubtypeDecl (_ : _ : _) _ _] -> sS
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder [IsoDecl (_ : _ : _) _] -> sS
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder _ -> ""
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian MaederplOps :: [Annoted OpItem] -> String
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian MaederplOps l = case map item l of
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder _ : _ : _ -> sS
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder [OpDecl (_ : _ : _) _ _ _] -> sS
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder _ -> ""
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian MaederisSimpleTypeItem :: TypeItem -> Bool
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian MaederisSimpleTypeItem ti = case ti of
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder TypeDecl l k _ -> k == universe && all isSimpleTypePat l
48c4688439e0aade4faeebf25ca8b16d661e47afChristian Maeder SubtypeDecl l (TypeName i _ _) _ ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder not (isMixfix i) && all isSimpleTypePat l
bf4263f9dab040818efc7a67172aab8f32218061Christian Maeder SubtypeDefn p (Var _) t _ _ ->
32a2f5f00ff72c095b39629101043db4407974f9Christian Maeder isSimpleTypePat p && isSimpleType t
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> False
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
df33a9af92444f63ad545da6bb326aac9284318eChristian MaederisSimpleTypePat :: TypePattern -> Bool
749074bf849727439f584139415f6a985a8aa875Christian MaederisSimpleTypePat tp = case tp of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder TypePattern i [] _ -> not $ isMixfix i
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> False
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederisSimpleType :: Type -> Bool
ce3928e71520030ad0275b72050a8f4377f9313cChristian MaederisSimpleType t = case t of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder TypeName i _ _ -> not $ isMixfix i
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder TypeToken _ -> True
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder MixfixType[TypeToken _, BracketType Squares (_ : _) _] -> True
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian Maeder _ -> False
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian Maederinstance Pretty ClassItem where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty (ClassItem d l _) = pretty d $+$ noNullPrint l
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian Maeder (specBraces $ vcat $ map (printAnnoted pretty) l)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian Maederinstance Pretty ClassDecl where
99edc5256de959957a8c27b05ae4ad4f0572233dChristian Maeder pretty (ClassDecl l k _) = let cs = ppWithCommas l in
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder if k == universe then cs else fsep [cs, less, pretty k]
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maederinstance Pretty Vars where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty vd = case vd of
48c4688439e0aade4faeebf25ca8b16d661e47afChristian Maeder Var v -> pretty v
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder VarTuple vs _ -> parens $ ppWithCommas vs
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maederinstance Pretty TypeItem where
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder pretty ti = case ti of
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder TypeDecl l k _ -> sep [ppWithCommas l, printKind k]
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder SubtypeDecl l t _ ->
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder fsep [ppWithCommas l, less, pretty t]
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder IsoDecl l _ -> fsep $ punctuate (space <> equals) $ map pretty l
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder SubtypeDefn p v t f _ ->
3daa82a175c7cfabf22455aa77c4beda327404e4Christian Maeder fsep [pretty p, equals,
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder specBraces $ fsep
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder [pretty v, colon <+> pretty t, bullet <+> pretty f]]
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder AliasType p _ (TypeScheme l t _) _ ->
3daa82a175c7cfabf22455aa77c4beda327404e4Christian Maeder fsep $ pretty p : map (pretty . varOfTypeArg) l
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder ++ [text assignS <+> pretty t]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Datatype t -> pretty t
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintItScheme :: [PolyId] -> Bool -> TypeScheme -> Doc
48c4688439e0aade4faeebf25ca8b16d661e47afChristian MaederprintItScheme ps b = (case ps of
48c4688439e0aade4faeebf25ca8b16d661e47afChristian Maeder [p] -> printTypeScheme p
48c4688439e0aade4faeebf25ca8b16d661e47afChristian Maeder _ -> pretty) . (if b then unPredTypeScheme else id)
aae7a026a323021c5364aef85a0e03d586e5a5c3Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprettyOpItem :: Bool -> OpItem -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprettyOpItem b oi = case oi of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder OpDecl l t a _ -> fsep $ punctuate comma (map pretty l)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ++ [colon <+>
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder (if null a then id else (<> comma))(printItScheme l b t)]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ++ punctuate comma (map pretty a)
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder OpDefn n ps s t _ -> fcat $
54b698a84a1686b828c99d839fc671942b817534Christian Maeder ((if null ps then (<> space) else id) $ pretty n)
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder : map ((<> space) . parens . printGenVarDecls . map GenVarDecl) ps
54b698a84a1686b828c99d839fc671942b817534Christian Maeder ++ (if b then [] else [colon <+> printItScheme [n] b s <> space])
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder ++ [(if b then equiv else equals) <> space, pretty t]
54b698a84a1686b828c99d839fc671942b817534Christian Maeder
d92635f998347112e5d5803301c2abfe7832ab65Christian Maederinstance Pretty PolyId where
aae7a026a323021c5364aef85a0e03d586e5a5c3Christian Maeder pretty (PolyId i@(Id ts cs ps) tys _) = if null tys then pretty i else
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder let (fts, plcs) = splitMixToken ts
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder in idDoc (Id fts cs ps) <> brackets (ppWithCommas tys)
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder <> hcat (map pretty plcs)
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maederinstance Pretty BinOpAttr where
bf4263f9dab040818efc7a67172aab8f32218061Christian Maeder pretty a = text $ case a of
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder Assoc -> assocS
62fb92b09f732b770317b46a793b60b960d5f481Christian Maeder Comm -> commS
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder Idem -> idemS
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty OpAttr where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty oa = case oa of
3daa82a175c7cfabf22455aa77c4beda327404e4Christian Maeder BinOpAttr a _ -> pretty a
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder UnitOpAttr t _ -> text unitS <+> pretty t
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty DatatypeDecl where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty (DatatypeDecl p k alts d _) =
99edc5256de959957a8c27b05ae4ad4f0572233dChristian Maeder fsep [ pretty p, printKind k, defn
99edc5256de959957a8c27b05ae4ad4f0572233dChristian Maeder <+> cat (punctuate (space <> bar <> space)
99edc5256de959957a8c27b05ae4ad4f0572233dChristian Maeder $ map pretty alts)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , case d of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder [] -> empty
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> keyword derivingS <+> ppWithCommas d]
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty Alternative where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty alt = case alt of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Constructor n cs p _ -> pretty n <+> fsep
99edc5256de959957a8c27b05ae4ad4f0572233dChristian Maeder (map ( \ l -> case (l, p) of
99edc5256de959957a8c27b05ae4ad4f0572233dChristian Maeder-- comment out the following line to output real CASL
99edc5256de959957a8c27b05ae4ad4f0572233dChristian Maeder ([NoSelector (TypeToken t)], Total) | isSimpleId n -> pretty t
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> parens $ semiDs l) cs) <> pretty p
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Subtype l _ -> text (if all isSimpleType l then typeS else typeS)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder <+> ppWithCommas l
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maederinstance Pretty Component where
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder pretty sel = case sel of
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder Selector n _ t _ _ -> sep [pretty n, colon <+> pretty t]
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder NoSelector t -> pretty t
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maederinstance Pretty Symb where
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder pretty (Symb i mt _) =
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder sep $ pretty i : case mt of
Nothing -> []
Just (SymbType t) -> [colon <+> pretty t]
instance Pretty SymbItems where
pretty (SymbItems k syms _ _) =
printSK k syms <> ppWithCommas syms
instance Pretty SymbOrMap where
pretty (SymbOrMap s mt _) =
sep $ pretty s : case mt of
Nothing -> []
Just t -> [mapsto <+> pretty t]
instance Pretty SymbMapItems where
pretty (SymbMapItems k syms _ _) =
printSK k syms <> ppWithCommas syms
-- | print symbol kind
printSK :: SymbKind -> [a] -> Doc
printSK k l = case k of
Implicit -> empty
_ -> keyword (drop 3 (show k) ++ case l of
_ : _ : _ -> sS
_ -> "") <> space