PrintAs.hs revision 42da000066c803fbbbe9e13bf6326888de3bbdc7
2cff1f0e5a572a33bc692c96ce2a1590f160eed7cmaeder Authors: Christian Maeder
34bff097c14521b5e57ce37279a34256e1f78aa5Klaus Luettich printing As data types
b53688bfed888214b485cf76439d57262d80e0a7Christian Maedermodule PrintAs where
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederimport Keywords
66771c3723200a54eceaf0d82de861ca4b917b05Christian Maederimport PrettyPrint
66771c3723200a54eceaf0d82de861ca4b917b05Christian Maederimport GlobalAnnotations(GlobalAnnos)
66771c3723200a54eceaf0d82de861ca4b917b05Christian Maederimport GlobalAnnotationsFunctions(emptyGlobalAnnos)
66771c3723200a54eceaf0d82de861ca4b917b05Christian Maederimport Print_AS_Annotation
66771c3723200a54eceaf0d82de861ca4b917b05Christian MaedernoPrint :: Bool -> Doc -> Doc
66771c3723200a54eceaf0d82de861ca4b917b05Christian MaedernoPrint b d = if b then empty else d
d0c8d69c1a35ed2972ae093ecf7abb12dfbafb4dChristian MaedershowPretty :: PrettyPrint a => a -> ShowS
ea2dff2ba7790f5c9f8f5454181f86f45d2674d2Christian MaedershowPretty = showString . render . printText0 emptyGlobalAnnos
91eeff7b19b22d7e5c5d83fa6e357496e291c718Christian Maeder where _just_avoid_unused_import_warning = smallSpace_latex
66771c3723200a54eceaf0d82de861ca4b917b05Christian Maedercommas, semis :: PrettyPrint a => GlobalAnnos -> [a] -> Doc
b53688bfed888214b485cf76439d57262d80e0a7Christian Maedercommas ga l = fcat $ punctuate comma (map (printText0 ga) l)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maedersemis ga l = sep $ punctuate semi (map (printText0 ga) l)
254df6f22d01eacf7c57b85729e0445747b630d9Christian Maederinstance PrettyPrint TypePattern where
bbcb456803d40f9b48dd43b1c84bdf8932d2672bChristian Maeder printText0 ga (TypePattern name args _) = printText0 ga name
4c8d3c5a9e938633f6147b5a595b9b93bfca99e6Christian Maeder <> fcat (map (parens . printText0 ga) args)
60e6795dd310e10194e12bb660575aadf941328bEugen Kuksa printText0 ga (TypePatternToken t) = printText0 ga t
4c8d3c5a9e938633f6147b5a595b9b93bfca99e6Christian Maeder printText0 ga (MixfixTypePattern ts) = fsep (map (printText0 ga) ts)
b0b5ce95f738d35e520c20d1b0bd253f152a677fChristian Maeder printText0 ga (BracketTypePattern k l _) = bracket k $ commas ga l
ef9e8535c168d3f774d9e74368a2317a9eda5826Christian Maeder printText0 ga (TypePatternArgs l) = semis ga l
ffd2214759f0055aa5dfa95583a6060516ad766fChristian Maederbracket :: BracketKind -> Doc -> Doc
91eeff7b19b22d7e5c5d83fa6e357496e291c718Christian Maederbracket Parens t = parens t
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederbracket Squares t = Pretty.brackets t
ffd2214759f0055aa5dfa95583a6060516ad766fChristian Maederbracket Braces t = braces t
b53688bfed888214b485cf76439d57262d80e0a7Christian MaederprintKind :: GlobalAnnos -> Kind -> Doc
91eeff7b19b22d7e5c5d83fa6e357496e291c718Christian MaederprintKind ga kind = case kind of
91a356d176c7e9b4eef6e8734559bfb858d5e630Christian Maeder PlainClass (Intersection [] _) -> empty
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder _ -> space <> colon <> printText0 ga kind
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederinstance PrettyPrint Type where
897a04683fb30873e84dc3360dea770a4435971cChristian Maeder printText0 ga (TypeName name i) = printText0 ga name
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder <> if i == 0 then empty
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder else parens (int i)
0130083f314580170af1195037be3325f125fbceChristian Maeder printText0 ga (TypeAppl t1 t2) = parens (printText0 ga t1)
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder <> parens (printText0 ga t2)
91eeff7b19b22d7e5c5d83fa6e357496e291c718Christian Maeder printText0 ga (TypeToken t) = printText0 ga t
af6e92e4a9ca308f928f9909acee115f801c5db5Ewaryst Schulz printText0 ga (BracketType k l _) = bracket k $ commas ga l
593ac6474255679d77ce1961474355822176ba43Christian Maeder printText0 ga (KindedType t kind _) = printText0 ga t
649fdc0d0502d62d160c150684356fef2c273484Eugen Kuksa <> printKind ga kind
bcd35fcdda4233c42766519772b2e9fbab57f975Christian Maeder printText0 ga (MixfixType ts) = fsep (map (printText0 ga) ts)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder printText0 ga (LazyType t _) = text quMark <+> printText0 ga (t)
3753288339ad80053053d92409bd37b335a96197Christian Maeder printText0 ga (ProductType ts _) = fsep (punctuate (space <> text timesS)
3753288339ad80053053d92409bd37b335a96197Christian Maeder (map (printText0 ga) ts))
3753288339ad80053053d92409bd37b335a96197Christian Maeder printText0 ga (FunType t1 arr t2 _) = printText0 ga t1
897a04683fb30873e84dc3360dea770a4435971cChristian Maeder <+> printText0 ga arr
3753288339ad80053053d92409bd37b335a96197Christian Maeder <+> printText0 ga t2
3753288339ad80053053d92409bd37b335a96197Christian Maederinstance PrettyPrint Pred where
897a04683fb30873e84dc3360dea770a4435971cChristian Maeder printText0 ga (IsIn c ts) = if null ts then printText0 ga c
897a04683fb30873e84dc3360dea770a4435971cChristian Maeder else if null $ tail ts then
3753288339ad80053053d92409bd37b335a96197Christian Maeder printText0 ga (head ts) <+>
897a04683fb30873e84dc3360dea770a4435971cChristian Maeder colon <+> printText0 ga c
897a04683fb30873e84dc3360dea770a4435971cChristian Maeder else printText0 ga c <+>
897a04683fb30873e84dc3360dea770a4435971cChristian Maeder fsep (punctuate space
897a04683fb30873e84dc3360dea770a4435971cChristian Maeder (map (printText0 ga) ts))
897a04683fb30873e84dc3360dea770a4435971cChristian Maederinstance PrettyPrint t => PrettyPrint (Qual t) where
897a04683fb30873e84dc3360dea770a4435971cChristian Maeder printText0 ga (ps :=> t) = (if null ps then empty
9a7f7c6399a1014e51abc7049a5fbd265461e1a7Christian Maeder else parens $ commas ga ps <+>
9a7f7c6399a1014e51abc7049a5fbd265461e1a7Christian Maeder ptext implS <+> space) <>
593ac6474255679d77ce1961474355822176ba43Christian Maeder printText0 ga t
dab742f3b90c81f4a926ef2cdb096d358fb72c12Christian Maeder-- no curried notation for bound variables
dab742f3b90c81f4a926ef2cdb096d358fb72c12Christian Maederinstance PrettyPrint TypeScheme where
c3d02da98e2806333eacf170309abff7a1377e14notanartist printText0 ga (TypeScheme vs t _) = noPrint (null vs) (text forallS
c3d02da98e2806333eacf170309abff7a1377e14notanartist <+> semis ga vs
c3d02da98e2806333eacf170309abff7a1377e14notanartist <+> text dotS <+> space)
dab742f3b90c81f4a926ef2cdb096d358fb72c12Christian Maeder <> printText0 ga t
9a7f7c6399a1014e51abc7049a5fbd265461e1a7Christian Maederinstance PrettyPrint Partiality where
9a7f7c6399a1014e51abc7049a5fbd265461e1a7Christian Maeder printText0 _ Partial = text quMark
593ac6474255679d77ce1961474355822176ba43Christian Maeder printText0 _ Total = text exMark
06b97c160c9160682f18591409cadc9e97873020Christian Maederinstance PrettyPrint Arrow where
06b97c160c9160682f18591409cadc9e97873020Christian Maeder printText0 _ FunArr = text funS
9a7f7c6399a1014e51abc7049a5fbd265461e1a7Christian Maeder printText0 _ PFunArr = text pFun
06b97c160c9160682f18591409cadc9e97873020Christian Maeder printText0 _ ContFunArr = text contFun
254df6f22d01eacf7c57b85729e0445747b630d9Christian Maeder printText0 _ PContFunArr = text pContFun
254df6f22d01eacf7c57b85729e0445747b630d9Christian Maederinstance PrettyPrint Quantifier where
38c817b94e0a5b1ae94178b1075c187e07bcc5e1Christian Maeder printText0 _ Universal = text forallS
254df6f22d01eacf7c57b85729e0445747b630d9Christian Maeder printText0 _ Existential = text existsS
254df6f22d01eacf7c57b85729e0445747b630d9Christian Maeder printText0 _ Unique = text $ existsS ++ exMark
60e6795dd310e10194e12bb660575aadf941328bEugen Kuksainstance PrettyPrint TypeQual where
60e6795dd310e10194e12bb660575aadf941328bEugen Kuksa printText0 _ OfType = colon
254df6f22d01eacf7c57b85729e0445747b630d9Christian Maeder printText0 _ AsType = text asS
38c817b94e0a5b1ae94178b1075c187e07bcc5e1Christian Maeder printText0 _ InType = text inS
8869b0b47d4ebc275098d1777301b652648b3c45Christian Maederinstance PrettyPrint LogOp where
94c729aeac99df6d844da014f46d584c035a91a6Christian Maeder printText0 _ NotOp = text notS
38c817b94e0a5b1ae94178b1075c187e07bcc5e1Christian Maeder printText0 _ AndOp = text lAnd
8869b0b47d4ebc275098d1777301b652648b3c45Christian Maeder printText0 _ OrOp = text lOr
8869b0b47d4ebc275098d1777301b652648b3c45Christian Maeder printText0 _ ImplOp = text implS
254df6f22d01eacf7c57b85729e0445747b630d9Christian Maeder printText0 _ EquivOp = text equivS
38c817b94e0a5b1ae94178b1075c187e07bcc5e1Christian Maederinstance PrettyPrint EqOp where
254df6f22d01eacf7c57b85729e0445747b630d9Christian Maeder printText0 _ EqualOp = text equalS
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder printText0 _ ExEqualOp = text exEqual
2a9702a373738717c83824512bd9389b5870fc92Christian Maederinstance PrettyPrint Formula where
2a9702a373738717c83824512bd9389b5870fc92Christian Maeder printText0 ga (TermFormula t) = printText0 ga t
e90b8ee3fac5c932d83af2061579c6b57d528885Christian Maeder printText0 ga (ConnectFormula o fs _) = parens $
254df6f22d01eacf7c57b85729e0445747b630d9Christian Maeder fsep (punctuate (space <> printText0 ga o) (map (printText0 ga) fs))
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder printText0 ga (EqFormula o t1 t2 _) = printText0 ga t1
a081d56252673c9e4a017e6282f59766f0cbcd42Christian Maeder <+> printText0 ga o
a081d56252673c9e4a017e6282f59766f0cbcd42Christian Maeder <+> printText0 ga t2
2a9702a373738717c83824512bd9389b5870fc92Christian Maeder printText0 ga (DefFormula t _) = text defS <+> printText0 ga t
2a9702a373738717c83824512bd9389b5870fc92Christian Maeder printText0 ga (QuantifiedFormula q vs f _) =
2a9702a373738717c83824512bd9389b5870fc92Christian Maeder printText0 ga q <+> semis ga vs <+> text dotS <+> printText0 ga f
91a356d176c7e9b4eef6e8734559bfb858d5e630Christian Maeder printText0 ga (PolyFormula ts f _) =
91a356d176c7e9b4eef6e8734559bfb858d5e630Christian Maeder text forallS <+> semis ga ts <+> text dotS <+> printText0 ga f
2a9702a373738717c83824512bd9389b5870fc92Christian Maederinstance PrettyPrint Term where
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder printText0 ga (CondTerm t1 f t2 _) = printText0 ga t1
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder <+> text whenS
f39c70229e74147a02d15bd45c05a0b1b325532dChristian Maeder <+> printText0 ga f
11c3a215d5cf043181e83929f1ce214df65cb587Christian Maeder <+> text elseS
db6729e623b4053149084ccf4b35e5308ac7e359Christian Maeder <+> printText0 ga t2
bcd35fcdda4233c42766519772b2e9fbab57f975Christian Maeder printText0 ga (QualVar v t _) = parens $ text varS
f997c50e79d277ae8d7d3bc536a276d67b75f953Simon Ulbricht <+> printText0 ga v
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder <+> printText0 ga t
f997c50e79d277ae8d7d3bc536a276d67b75f953Simon Ulbricht printText0 ga (QualOp n t _) = parens $
f39c70229e74147a02d15bd45c05a0b1b325532dChristian Maeder <+> printText0 ga n
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder <+> printText0 ga t
333780eae2be9f20fe46dedbf5eb46ffa0cbfd02Christian Maeder printText0 ga (ApplTerm t1 t2 _) = printText0 ga t1
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder <+> parens (printText0 ga t2)
8a2f18f56cc083acea15615185e5e9366bc9eceeChristian Maeder printText0 ga (TupleTerm ts _) = parens $ commas ga ts
cb2044812811d66efe038d914966e04290be93faChristian Maeder printText0 ga (TypedTerm term q typ _) = printText0 ga term
333780eae2be9f20fe46dedbf5eb46ffa0cbfd02Christian Maeder <+> printText0 ga q
cb2044812811d66efe038d914966e04290be93faChristian Maeder <+> printText0 ga typ
94c729aeac99df6d844da014f46d584c035a91a6Christian Maeder printText0 ga (QuantifiedTerm q vs t _) = printText0 ga q
94c729aeac99df6d844da014f46d584c035a91a6Christian Maeder <+> semis ga vs
94c729aeac99df6d844da014f46d584c035a91a6Christian Maeder <+> text dotS
94c729aeac99df6d844da014f46d584c035a91a6Christian Maeder <+> printText0 ga t
cb2044812811d66efe038d914966e04290be93faChristian Maeder printText0 ga (LambdaTerm ps q t _) = text lamS
ffd2214759f0055aa5dfa95583a6060516ad766fChristian Maeder <+> (if length ps == 1 then
c4b508b43eb5e3a92e464b5f85b5a2b5ecd7d3c3cmaeder printText0 ga $ head ps
c4b508b43eb5e3a92e464b5f85b5a2b5ecd7d3c3cmaeder else fcat $ map
c4b508b43eb5e3a92e464b5f85b5a2b5ecd7d3c3cmaeder <+> (case q of
c4b508b43eb5e3a92e464b5f85b5a2b5ecd7d3c3cmaeder Partial -> text dotS
93603bd881e43d4ff5a57d7ca4e2b9fa619f25b4cmaeder Total -> text $ dotS ++ exMark)
c4b508b43eb5e3a92e464b5f85b5a2b5ecd7d3c3cmaeder <+> printText0 ga t
55282ad62e8b6758abec43734ebde0015ac14b89Eugen Kuksa printText0 ga (CaseTerm t es _ ) = text caseS
c4b508b43eb5e3a92e464b5f85b5a2b5ecd7d3c3cmaeder <+> printText0 ga t
0130083f314580170af1195037be3325f125fbceChristian Maeder <+> vcat (punctuate (text " | ")
c4b508b43eb5e3a92e464b5f85b5a2b5ecd7d3c3cmaeder (map (printEq0 ga funS) es))
0130083f314580170af1195037be3325f125fbceChristian Maeder printText0 ga (LetTerm es t _) = text letS
0130083f314580170af1195037be3325f125fbceChristian Maeder <+> vcat (punctuate semi
0130083f314580170af1195037be3325f125fbceChristian Maeder (map (printEq0 ga equalS) es))
0130083f314580170af1195037be3325f125fbceChristian Maeder <+> printText0 ga t
0130083f314580170af1195037be3325f125fbceChristian Maeder printText0 ga (TermToken t) = printText0 ga t
0130083f314580170af1195037be3325f125fbceChristian Maeder printText0 ga (MixfixTerm ts) = fsep $ map (printText0 ga) ts
0130083f314580170af1195037be3325f125fbceChristian Maeder printText0 ga (BracketTerm k l _) = bracket k $ commas ga l
ffd2214759f0055aa5dfa95583a6060516ad766fChristian Maederinstance PrettyPrint Pattern where
649fdc0d0502d62d160c150684356fef2c273484Eugen Kuksa printText0 ga (PatternVars vs _) = semis ga vs
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa printText0 ga (PatternConstr n t args _) = printText0 ga n
23b1f89c05c67d7778e2736bd24fdec33212f323cmaeder <+> printText0 ga t
23b1f89c05c67d7778e2736bd24fdec33212f323cmaeder <+> fcat (map (parens.printText0 ga) args)
23b1f89c05c67d7778e2736bd24fdec33212f323cmaeder printText0 ga (PatternToken t) = printText0 ga t
23b1f89c05c67d7778e2736bd24fdec33212f323cmaeder printText0 ga (BracketPattern k l _) =
23b1f89c05c67d7778e2736bd24fdec33212f323cmaeder [TuplePattern _ _] -> printText0 ga $ head l
0130083f314580170af1195037be3325f125fbceChristian Maeder _ -> bracket k $ commas ga l
0130083f314580170af1195037be3325f125fbceChristian Maeder printText0 ga (TuplePattern ps _) = parens $ commas ga ps
0130083f314580170af1195037be3325f125fbceChristian Maeder printText0 ga (MixfixPattern ps) = fsep (map (printText0 ga) ps)
0130083f314580170af1195037be3325f125fbceChristian Maeder printText0 ga (TypedPattern p t _) = printText0 ga p
0130083f314580170af1195037be3325f125fbceChristian Maeder <+> printText0 ga t
c4b508b43eb5e3a92e464b5f85b5a2b5ecd7d3c3cmaeder printText0 ga (AsPattern v p _) = printText0 ga v
0130083f314580170af1195037be3325f125fbceChristian Maeder <+> printText0 ga p
0130083f314580170af1195037be3325f125fbceChristian MaederprintEq0 :: GlobalAnnos -> String -> ProgEq -> Doc
0130083f314580170af1195037be3325f125fbceChristian MaederprintEq0 ga s (ProgEq p t _) = fsep [printText0 ga p
0130083f314580170af1195037be3325f125fbceChristian Maeder , printText0 ga t]
2cff1f0e5a572a33bc692c96ce2a1590f160eed7cmaederinstance PrettyPrint VarDecl where
2cff1f0e5a572a33bc692c96ce2a1590f160eed7cmaeder printText0 ga (VarDecl v t _ _) = printText0 ga v <+> colon
2cff1f0e5a572a33bc692c96ce2a1590f160eed7cmaeder <+> printText0 ga t
2ccdb81b4018e0a76f6dad3a940ba1241e98f6d9cmaederinstance PrettyPrint GenVarDecl where
fb9ec1e4dd1877781ec2b491fb0a6bcd38a7b04dcmaeder printText0 ga (GenVarDecl v) = printText0 ga v
91eeff7b19b22d7e5c5d83fa6e357496e291c718Christian Maeder printText0 ga (GenTypeVarDecl tv) = printText0 ga tv
ea2dff2ba7790f5c9f8f5454181f86f45d2674d2Christian Maederinstance PrettyPrint TypeArg where
91eeff7b19b22d7e5c5d83fa6e357496e291c718Christian Maeder printText0 ga (TypeArg v c _ _) = printText0 ga v <> colon
91eeff7b19b22d7e5c5d83fa6e357496e291c718Christian Maeder <> printText0 ga c
fb9ec1e4dd1877781ec2b491fb0a6bcd38a7b04dcmaederinstance PrettyPrint Variance where
2ccdb81b4018e0a76f6dad3a940ba1241e98f6d9cmaeder printText0 _ CoVar = text plusS
2ccdb81b4018e0a76f6dad3a940ba1241e98f6d9cmaeder printText0 _ ContraVar = text minusS
ea2dff2ba7790f5c9f8f5454181f86f45d2674d2Christian Maeder printText0 _ InVar = empty
ea2dff2ba7790f5c9f8f5454181f86f45d2674d2Christian Maederinstance PrettyPrint Kind where
ea2dff2ba7790f5c9f8f5454181f86f45d2674d2Christian Maeder printText0 ga (PlainClass c) = printText0 ga c
ea2dff2ba7790f5c9f8f5454181f86f45d2674d2Christian Maeder printText0 ga (ExtClass k v _) = (case k of
fb9ec1e4dd1877781ec2b491fb0a6bcd38a7b04dcmaeder PlainClass _ -> id
ea2dff2ba7790f5c9f8f5454181f86f45d2674d2Christian Maeder _ -> parens) (printText0 ga k)
1c4dfa148603d4fcf4cdd2ed66c8b6e1de0dd696Till Mossakowski <> printText0 ga v
2ccdb81b4018e0a76f6dad3a940ba1241e98f6d9cmaeder printText0 ga (ProdClass l _) = fcat $ punctuate (space <> text timesS)
ea2dff2ba7790f5c9f8f5454181f86f45d2674d2Christian Maeder (case k of KindAppl _ _ _ -> parens
ea2dff2ba7790f5c9f8f5454181f86f45d2674d2Christian Maeder ProdClass _ _ -> parens
1c4dfa148603d4fcf4cdd2ed66c8b6e1de0dd696Till Mossakowski (printText0 ga k)) l)
f448ac6b7846addfe6041275edf1fb90962e76eacmaeder printText0 ga (KindAppl k1 k2 _) =
f448ac6b7846addfe6041275edf1fb90962e76eacmaeder (case k1 of
f448ac6b7846addfe6041275edf1fb90962e76eacmaeder KindAppl _ _ _ -> parens
f448ac6b7846addfe6041275edf1fb90962e76eacmaeder _ -> id) (printText0 ga k1)
f448ac6b7846addfe6041275edf1fb90962e76eacmaeder <+> text funS
f448ac6b7846addfe6041275edf1fb90962e76eacmaeder <> printText0 ga k2
f448ac6b7846addfe6041275edf1fb90962e76eacmaederinstance PrettyPrint Class where
f448ac6b7846addfe6041275edf1fb90962e76eacmaeder printText0 ga (Downset t) = braces $
printText0 ga (Types l _) = Pretty.brackets $ commas ga l
printText0 ga (TypeVarDecls l _) = Pretty.brackets $ semis ga l