From fa5ffbd629ed466f6e1f121b805f2114e6b2bd47 Mon Sep 17 00:00:00 2001 From: "Iavor S. Diatchki" Date: Thu, 15 Mar 2012 22:43:35 -0700 Subject: Add support for type-level literals. --- src/Haddock/Backends/LaTeX.hs | 9 +++++++++ src/Haddock/Backends/Xhtml/Decl.hs | 6 ++++++ src/Haddock/Convert.hs | 5 +++++ src/Haddock/Interface/AttachInstances.hs | 5 ++++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Haddock/Backends/LaTeX.hs b/src/Haddock/Backends/LaTeX.hs index deb224a8..e5f85b92 100644 --- a/src/Haddock/Backends/LaTeX.hs +++ b/src/Haddock/Backends/LaTeX.hs @@ -903,6 +903,15 @@ ppr_mono_ty ctxt_prec (HsParTy ty) unicode ppr_mono_ty ctxt_prec (HsDocTy ty _) unicode = ppr_mono_lty ctxt_prec ty unicode +ppr_mono_ty _ (HsTyLit t) u = ppr_tylit t u + + +ppr_tylit :: HsTyLit -> Bool -> LaTeX +ppr_tylit (HsNumTy n) _ = integer n +ppr_tylit (HsStrTy s) _ = text (show s) + -- XXX: Ok in verbatim, but not otherwise + -- XXX: Do something with Unicode parameter? + ppr_fun_ty :: Int -> LHsType DocName -> LHsType DocName -> Bool -> LaTeX ppr_fun_ty ctxt_prec ty1 ty2 unicode diff --git a/src/Haddock/Backends/Xhtml/Decl.hs b/src/Haddock/Backends/Xhtml/Decl.hs index 71bcd581..adb1d598 100644 --- a/src/Haddock/Backends/Xhtml/Decl.hs +++ b/src/Haddock/Backends/Xhtml/Decl.hs @@ -751,6 +751,12 @@ ppr_mono_ty ctxt_prec (HsParTy ty) unicode qual ppr_mono_ty ctxt_prec (HsDocTy ty _) unicode qual = ppr_mono_lty ctxt_prec ty unicode qual +ppr_mono_ty _ (HsTyLit n) _ _ = ppr_tylit n + +ppr_tylit :: HsTyLit -> Html +ppr_tylit (HsNumTy n) = toHtml (show n) +ppr_tylit (HsStrTy s) = toHtml (show s) + ppr_fun_ty :: Int -> LHsType DocName -> LHsType DocName -> Bool -> Qualification -> Html ppr_fun_ty ctxt_prec ty1 ty2 unicode qual diff --git a/src/Haddock/Convert.hs b/src/Haddock/Convert.hs index 480e5728..54845787 100644 --- a/src/Haddock/Convert.hs +++ b/src/Haddock/Convert.hs @@ -308,6 +308,11 @@ synifyType s forallty@(ForAllTy _tv _ty) = sTau = synifyType WithinType tau in noLoc $ HsForAllTy forallPlicitness sTvs sCtx sTau +synifyType _ (LitTy t) = noLoc $ HsTyLit $ synifyTyLit t + +synifyTyLit :: TyLit -> HsTyLit +synifyTyLit (NumTyLit n) = HsNumTy n +synifyTyLit (StrTyLit s) = HsStrTy s synifyKind :: Kind -> LHsKind Name synifyKind = synifyType (error "synifyKind") diff --git a/src/Haddock/Interface/AttachInstances.hs b/src/Haddock/Interface/AttachInstances.hs index 90416cd0..a4d4764e 100644 --- a/src/Haddock/Interface/AttachInstances.hs +++ b/src/Haddock/Interface/AttachInstances.hs @@ -106,7 +106,9 @@ getAllInfo name = withSession $ \hsc_env -> do -- in Haddock output) and unifying special tycons with normal ones. -- For the benefit of the user (looks nice and predictable) and the -- tests (which prefer output to be deterministic). -data SimpleType = SimpleType Name [SimpleType] deriving (Eq,Ord) +data SimpleType = SimpleType Name [SimpleType] + | SimpleTyLit TyLit + deriving (Eq,Ord) instHead :: ([TyVar], [PredType], Class, [Type]) -> ([Int], Name, [SimpleType]) @@ -126,6 +128,7 @@ instHead (_, _, cls, args) where (SimpleType s ts) = simplify t1 simplify (TyVarTy v) = SimpleType (tyVarName v) [] simplify (TyConApp tc ts) = SimpleType (tyConName tc) (map simplify ts) + simplify (LitTy l) = SimpleTyLit l -- sortImage f = sortBy (\x y -> compare (f x) (f y)) -- cgit v1.2.3 From 780fdc54b96c40aedb75db4638530c110c07e96f Mon Sep 17 00:00:00 2001 From: "Iavor S. Diatchki" Date: Mon, 19 Mar 2012 20:31:27 -0700 Subject: Add a missing case for type literals. --- src/Haddock/Interface/Rename.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Haddock/Interface/Rename.hs b/src/Haddock/Interface/Rename.hs index 6034688e..0e75fef7 100644 --- a/src/Haddock/Interface/Rename.hs +++ b/src/Haddock/Interface/Rename.hs @@ -259,6 +259,8 @@ renameType t = case t of doc' <- renameLDocHsSyn doc return (HsDocTy ty' doc') + HsTyLit x -> return (HsTyLit x) + _ -> error "renameType" -- cgit v1.2.3 From 925c54bbffaf90b5719b332628c7540ab13dc6c2 Mon Sep 17 00:00:00 2001 From: "Iavor S. Diatchki" Date: Sat, 24 Mar 2012 13:28:29 -0700 Subject: Rename variable to avoid shadowing warning. --- src/Haddock/Backends/Xhtml/Decl.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Haddock/Backends/Xhtml/Decl.hs b/src/Haddock/Backends/Xhtml/Decl.hs index 94753f23..a5526505 100644 --- a/src/Haddock/Backends/Xhtml/Decl.hs +++ b/src/Haddock/Backends/Xhtml/Decl.hs @@ -741,8 +741,8 @@ ppr_mono_ty ctxt_prec (HsOpTy ty1 (_, op) ty2) unicode qual = maybeParen ctxt_prec pREC_FUN $ ppr_mono_lty pREC_OP ty1 unicode qual <+> ppr_op <+> ppr_mono_lty pREC_OP ty2 unicode qual where - ppr_op = if not (isSymOcc occName) then quote (ppLDocName qual op) else ppLDocName qual op - occName = nameOccName . getName . unLoc $ op + ppr_op = if not (isSymOcc occ) then quote (ppLDocName qual op) else ppLDocName qual op + occ = nameOccName . getName . unLoc $ op ppr_mono_ty ctxt_prec (HsParTy ty) unicode qual -- = parens (ppr_mono_lty pREC_TOP ty) -- cgit v1.2.3