Skip to content

Commit cdc81a1

Browse files
osa1bgamari
authored andcommitted
Add support for unboxed sums
1 parent 008e61d commit cdc81a1

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

haddock-api/src/Haddock/Backends/LaTeX.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,10 @@ tupleParens HsUnboxedTuple = ubxParenList
885885
tupleParens _ = parenList
886886

887887

888+
sumParens :: [LaTeX] -> LaTeX
889+
sumParens = ubxparens . hsep . punctuate (text " | ")
890+
891+
888892
-------------------------------------------------------------------------------
889893
-- * Rendering of HsType
890894
--
@@ -948,6 +952,7 @@ ppr_mono_ty _ (HsBangTy b ty) u = ppBang b <> ppLParendType u ty
948952
ppr_mono_ty _ (HsTyVar (L _ name)) _ = ppDocName name
949953
ppr_mono_ty ctxt_prec (HsFunTy ty1 ty2) u = ppr_fun_ty ctxt_prec ty1 ty2 u
950954
ppr_mono_ty _ (HsTupleTy con tys) u = tupleParens con (map (ppLType u) tys)
955+
ppr_mono_ty _ (HsSumTy tys) u = sumParens (map (ppLType u) tys)
951956
ppr_mono_ty _ (HsKindSig ty kind) u = parens (ppr_mono_lty pREC_TOP ty u <+> dcolon u <+> ppLKind u kind)
952957
ppr_mono_ty _ (HsListTy ty) u = brackets (ppr_mono_lty pREC_TOP ty u)
953958
ppr_mono_ty _ (HsPArrTy ty) u = pabrackets (ppr_mono_lty pREC_TOP ty u)

haddock-api/src/Haddock/Backends/Xhtml/Decl.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,9 @@ tupleParens HsUnboxedTuple = ubxParenList
913913
tupleParens _ = parenList
914914

915915

916+
sumParens :: [Html] -> Html
917+
sumParens = ubxSumList
918+
916919
--------------------------------------------------------------------------------
917920
-- * Rendering of HsType
918921
--------------------------------------------------------------------------------
@@ -989,6 +992,7 @@ ppr_mono_ty _ (HsBangTy b ty) u q = ppBang b +++ ppLParendType u q t
989992
ppr_mono_ty _ (HsTyVar (L _ name)) _ q = ppDocName q Prefix True name
990993
ppr_mono_ty ctxt_prec (HsFunTy ty1 ty2) u q = ppr_fun_ty ctxt_prec ty1 ty2 u q
991994
ppr_mono_ty _ (HsTupleTy con tys) u q = tupleParens con (map (ppLType u q) tys)
995+
ppr_mono_ty _ (HsSumTy tys) u q = sumParens (map (ppLType u q) tys)
992996
ppr_mono_ty _ (HsKindSig ty kind) u q =
993997
parens (ppr_mono_lty pREC_TOP ty u q <+> dcolon u <+> ppLKind u q kind)
994998
ppr_mono_ty _ (HsListTy ty) u q = brackets (ppr_mono_lty pREC_TOP ty u q)

haddock-api/src/Haddock/Backends/Xhtml/Utils.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Haddock.Backends.Xhtml.Utils (
2020
(<+>), (<=>), char,
2121
keyword, punctuate,
2222

23-
braces, brackets, pabrackets, parens, parenList, ubxParenList,
23+
braces, brackets, pabrackets, parens, parenList, ubxParenList, ubxSumList,
2424
arrow, comma, dcolon, dot, darrow, equals, forallSymbol, quote, promoQuote,
2525

2626
hsep, vcat,
@@ -177,6 +177,10 @@ ubxParenList :: [Html] -> Html
177177
ubxParenList = ubxparens . hsep . punctuate comma
178178

179179

180+
ubxSumList :: [Html] -> Html
181+
ubxSumList = ubxparens . hsep . punctuate (toHtml " | ")
182+
183+
180184
ubxparens :: Html -> Html
181185
ubxparens h = toHtml "(#" +++ h +++ toHtml "#)"
182186

haddock-api/src/Haddock/Interface/Rename.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ renameType t = case t of
238238
HsEqTy ty1 ty2 -> liftM2 HsEqTy (renameLType ty1) (renameLType ty2)
239239

240240
HsTupleTy b ts -> return . HsTupleTy b =<< mapM renameLType ts
241+
HsSumTy ts -> HsSumTy <$> mapM renameLType ts
241242

242243
HsOpTy a (L loc op) b -> do
243244
op' <- rename op

haddock-api/src/Haddock/Interface/Specialize.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ renameType (HsFunTy la lr) = HsFunTy <$> renameLType la <*> renameLType lr
273273
renameType (HsListTy lt) = HsListTy <$> renameLType lt
274274
renameType (HsPArrTy lt) = HsPArrTy <$> renameLType lt
275275
renameType (HsTupleTy srt lt) = HsTupleTy srt <$> mapM renameLType lt
276+
renameType (HsSumTy lt) = HsSumTy <$> mapM renameLType lt
276277
renameType (HsOpTy la lop lb) =
277278
HsOpTy <$> renameLType la <*> located renameName lop <*> renameLType lb
278279
renameType (HsParTy lt) = HsParTy <$> renameLType lt

0 commit comments

Comments
 (0)