Ticket #215: submission_20120929_ghc-7.4.1.patch
| File submission_20120929_ghc-7.4.1.patch, 68.2 kB (added by lars_e_krueger, 8 months ago) |
|---|
-
(a) /dev/null vs. (b) b/.gitignore
From c9ad4aad410d051ec25ae4c59d187a16366ae89e Mon Sep 17 00:00:00 2001 From: Lars Krueger <lars_e_krueger@gmx.de> Date: Sat, 14 Apr 2012 21:17:03 +0200 Subject: [PATCH 1/6] Squashed commit of the following: commit aedb6c7987edbd21fae704af8bfe5366528543a2 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sat Apr 14 19:58:11 2012 +0200 hlint suggestions integrated commit 098707c8de20f7650f664b8d6a9fa7b6c2f04f5b Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sat Apr 14 19:06:46 2012 +0200 formatting according to coding guide lines commit 694ec87fcaca9d9906edd0d5a9ddb05bfcfdacb5 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sat Apr 14 13:01:13 2012 +0200 markup renderer without state monad commit 86c2edb98ba7279b7ae57ac1171d70747585b7f4 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sat Apr 14 11:15:43 2012 +0200 factorisation commit 2bb4301266cca500d025650118b14030ebb9a259 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sat Apr 14 10:35:15 2012 +0200 VimHelp code is warning free now commit c8cba4846ee41358881f33e15f1883f555246d65 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sat Apr 14 10:27:20 2012 +0200 VimHelp backend: API cleanup commit 461dd13d070cc5c981342e522742e8a0da92fe8b Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Fri Apr 13 13:31:50 2012 +0200 render bugs fixed (missing spaces etc) commit 9a4374dc55df0a873ba072c078c35271cf042ca9 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sun Mar 25 14:33:40 2012 +0200 install help files in vim folder commit c6cd0610e9b6813db6a789831dd10351e7ff2f91 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sat Mar 24 17:07:13 2012 +0100 removed some debug strings commit 90299b3644a8b23533cbe6f0b87faafef5be1bc8 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sat Mar 24 17:07:03 2012 +0100 build help for all packages commit 8f1156ac0315d32ef66370baa12c72a0e7f34225 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sat Mar 17 15:10:23 2012 +0100 added script to rebuild vimhelp docu commit 9cd228d0e34b9ff4589318a1b8e4cf26fda3bfe9 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Fri Mar 16 21:59:36 2012 +0100 formatting correct on examples commit 1763dc1a19c09705c7458978a374a027d6162aa7 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Thu Mar 15 23:29:46 2012 +0100 formatting fixed commit b1b556fafd3aecc6ba524db04c4e06c650237e85 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Mon Mar 5 22:17:38 2012 +0100 everything ported to linear markup commit 0fd6567f2b76ba57dd3fc3ea26c3af42ed3229ad Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Mon Mar 5 08:54:03 2012 +0100 utils use new markup commit 5d87785b4dd8a5b1ad07b26e2e1aaa74640b6a42 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Mon Mar 5 08:53:42 2012 +0100 more state modifiers commit 2e71618fdbc3f1f88cecc1783c2c474469ae47fe Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Mon Mar 5 08:53:24 2012 +0100 added package mtl commit 23a8f98e0491b952faf4de4f33c6f5eb7d46b96e Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sun Mar 4 21:38:41 2012 +0100 Implemented linear markup commit 862b5145ee33cc60e2787254b307c7e86f679ef8 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sun Mar 4 19:45:39 2012 +0100 special case for builtin types commit 4f256232bc1d9b1b6891c7da8b2b7c8a8daf9415 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sun Mar 4 19:45:26 2012 +0100 added vhText to strip EOLs commit 065921d36471120317fd8bd5039affde52fc6649 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sat Mar 3 11:17:20 2012 +0100 activated all top level renderers commit 0a491ab001b37603920c3d6db24d3c381c93ab07 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Mon Feb 27 21:28:02 2012 +0100 ported Xhtml.Decl to VimHelp.Decl commit 667adaf7ef8cf298cf8c7529e2b3a08d8d023b6a Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sun Feb 19 22:44:43 2012 +0100 use own markup engine commit 070bd38511f90c369e006a8fc5d5ba1c41652149 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sun Feb 19 22:44:22 2012 +0100 added simple markup engine commit 60b0d3f3b1ebc19a84680386410e831b8e5e4a78 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Thu Feb 16 20:45:55 2012 +0100 Basic ExportItem output added commit 6f9a03c18c09f234763626702706c1d99f669328 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Thu Feb 16 20:45:32 2012 +0100 removed dummy text for maybeDoc commit 243150343c98d8227434ea332ad112a032188157 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Thu Feb 16 20:44:51 2012 +0100 fixed DocParagraph output commit d97621b586e37b6436a390f654138b7e3b76995c Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Thu Feb 16 20:44:33 2012 +0100 fixed DocModule output commit 8d68bd17fe0e9caf421f10c18a5eb2b6a5972cd9 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Thu Feb 16 20:43:57 2012 +0100 fixed examples and code blocks commit f19958aa26ded9474873ea233b3f6277ed62af90 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Tue Feb 14 22:15:24 2012 +0100 added index and module generation commit 846beaaf183198680eb36c3207e124d6712c1fd8 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sun Feb 12 16:31:16 2012 +0100 ignore .viminfo commit b1a84a2a04eae75a518e730f86f3932ad10abda4 Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sun Feb 12 14:51:10 2012 +0100 integrated VimHelp backend commit d0144b6c361af340d17d83144741e7db1ed3b7dd Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sun Feb 12 14:50:24 2012 +0100 ignore vim backup files commit f9858abd10cc36d6938ad8476576a04d80cb892a Author: Lars Krueger <lars_e_krueger@gmx.de> Date: Sun Feb 12 14:06:34 2012 +0100 added gitignore Signed-off-by: Lars Krueger <lars_e_krueger@gmx.de> --- .gitignore | 4 + haddock-rebuild-vimhelp.sh | 85 ++++ haddock.cabal | 4 + src/Haddock/Backends/VimHelp.hs | 94 +++++ src/Haddock/Backends/VimHelp/Decl.hs | 690 ++++++++++++++++++++++++++++++++ src/Haddock/Backends/VimHelp/Markup.hs | 200 +++++++++ src/Haddock/Backends/VimHelp/Utils.hs | 293 ++++++++++++++ src/Haddock/Options.hs | 2 + src/Main.hs | 10 +- 9 files changed, 1381 insertions(+), 1 deletions(-) create mode 100644 .gitignore create mode 100755 haddock-rebuild-vimhelp.sh create mode 100644 src/Haddock/Backends/VimHelp.hs create mode 100644 src/Haddock/Backends/VimHelp/Decl.hs create mode 100644 src/Haddock/Backends/VimHelp/Markup.hs create mode 100644 src/Haddock/Backends/VimHelp/Utils.hs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f35f5ba b 1 dist 2 *~ 3 .*.sw? 4 .viminfo -
(a) /dev/null vs. (b) b/haddock-rebuild-vimhelp.sh
diff --git a/haddock-rebuild-vimhelp.sh b/haddock-rebuild-vimhelp.sh new file mode 100755 index 0000000..c0c0bc5
a b 1 #! /bin/bash 2 3 # Script to rebuild the vimhelp from the list of installed packages 4 5 workDir="$PWD/temp" 6 HADDOCK="$PWD/haddock/dist/build/haddock/haddock" 7 8 9 # set the language to US english, UTF-8, to handle unicode correctly 10 export LANG=en_US.UTF-8 11 12 # Check for the required tools 13 test_for_program() { 14 prgName=$1 15 command -v $prgName > /dev/null 2>&1 16 [ $? -ne 0 ] || return 0 17 echo "Required program $prgName not found" 18 exit 1 19 } 20 21 test_for_program 'ghc-pkg' 22 test_for_program 'cabal' 23 test_for_program 'vim' 24 25 # Get the list of installed packages 26 instPkg=`ghc-pkg list --simple-output --names-only` 27 28 # Process the packages 29 workList='' 30 for pkg in $instPkg; do 31 # Get the latest version of package 32 latestPkg=`ghc-pkg latest $pkg` 33 34 # Check for hidden packages 35 isExposed=`ghc-pkg field $latestPkg exposed | cut -d ' ' -f 2 | head -1` 36 # if [ $isExposed == 'True' ]; then 37 echo -n "Checking for package $latestPkg ... " 38 39 # Download the package using cabal 40 cabal fetch --no-dependencies $latestPkg > /dev/null 2>&1 41 42 if [ $? -eq 0 ] ; then 43 workList="$workList $pkg" 44 echo "OK" 45 else 46 echo "ignored" 47 fi 48 # else 49 # echo "Package $pkg is hidden" 50 # fi 51 done 52 53 # workList='digest ghc-paths ghc-paths base64-bytestring extensible-exceptions zip-archive transformers array blaze-builder citeproc-hs syb utf8-string containers blaze-html json highlighting-kate hpc binary zlib texmath bytestring text tagsoup regex-compat regex-base regex-pcre-builtin regex-posix old-locale random old-time html pretty haskell-src process directory haskell98 deepseq temporary filepath time HUnit xml pandoc-types pandoc Cabal hscolour mtl GLUT stm OpenGL network QuickCheck unix template-haskell haddock parallel parsec base hs-bibutils fgl xhtml xhtml cgi HTTP' 54 55 workList=`(for w in $workList; do echo $w; done) | sort -u` 56 57 versionList=`(for w in $workList; do ghc-pkg latest $w; done)` 58 59 # Unpack all the packages 60 rm -Rf $workDir 61 cabal unpack --destdir=$workDir/src $versionList 62 63 # For each package, run haddock and make it generate the vimhelp info 64 docDir="/home/lars/.vim/doc" 65 mkdir -p $docDir 66 for pkg in $workList; do 67 versionPkg=`ghc-pkg latest $pkg` 68 69 # Generating the docs 70 ( 71 cd $workDir/src/$versionPkg 72 cabal configure 73 cabal haddock --with-haddock=$HADDOCK --haddock-options="--vimhelp" 74 ) 75 # Reading the modules and copying them 76 modDocDir="$workDir/src/$versionPkg/dist/doc/html/$pkg" 77 modList="$modDocDir/vimhelp_modules.txt" 78 for mod in `cat $modList`; do 79 cp $modDocDir/${mod}.txt $docDir/haddock_${mod}.txt 80 done 81 done 82 83 # Rebuild the helptags 84 vim --cmd "helptags $docDir" --cmd quit 85 -
haddock.cabal
diff --git a/haddock.cabal b/haddock.cabal index 84d3c2a..5563472 100644
a b 127 127 Haddock.Backends.Xhtml.Types 128 128 Haddock.Backends.Xhtml.Utils 129 129 Haddock.Backends.LaTeX 130 Haddock.Backends.VimHelp 131 Haddock.Backends.VimHelp.Markup 132 Haddock.Backends.VimHelp.Utils 133 Haddock.Backends.VimHelp.Decl 130 134 Haddock.Backends.HaddockDB 131 135 Haddock.Backends.Hoogle 132 136 Haddock.ModuleTree -
(a) /dev/null vs. (b) b/src/Haddock/Backends/VimHelp.hs
diff --git a/src/Haddock/Backends/VimHelp.hs b/src/Haddock/Backends/VimHelp.hs new file mode 100644 index 0000000..b935e4d
a b 1 ----------------------------------------------------------------------------- 2 -- | 3 -- Module : Haddock.Backends.VimHelp 4 -- Copyright : (c) Lars Krueger 2012 5 -- License : BSD-like 6 -- 7 -- Maintainer : lars_e_krueger@gmx.de 8 -- Stability : experimental 9 -- Portability : portable 10 ----------------------------------------------------------------------------- 11 module Haddock.Backends.VimHelp ( 12 ppVimHelp 13 ) where 14 15 import Haddock.Backends.VimHelp.Decl 16 import Haddock.Backends.VimHelp.Markup 17 import Haddock.Backends.VimHelp.Utils 18 19 import Haddock.GhcUtils 20 import Haddock.Types 21 22 import Control.Monad 23 import System.Directory 24 import System.FilePath 25 26 27 -- | Generate vim help files from interfaces. 28 ppVimHelp :: [Interface] 29 -> FilePath -- destination directory 30 -> IO () 31 ppVimHelp visible_ifaces odir = do 32 createDirectoryIfMissing True odir 33 -- Write module index for haddock-rebuild-vimhelp.sh 34 let mdlNameList = map (moduleString . ifaceMod) visible_ifaces 35 writeFile (odir </> "vimhelp_modules.txt") $ unlines mdlNameList 36 -- Write the module help files 37 forM_ visible_ifaces $ \iface -> do 38 let (ifaceTxt,modName)= ppModuleText iface 39 writeFile (odir </> (modName ++ ".txt")) ifaceTxt 40 41 42 -- | Render the text of this module 43 ppModuleText :: Interface -> (String,String) 44 ppModuleText iface = 45 let mdl = ifaceMod iface 46 modName = moduleString mdl 47 txt = [ ppRef $ "haddock_" ++ modName ++ ".txt" 48 , MiNonBreakable " Haddock documentation" 49 ] 50 ++ modInfotxt 51 ++ ppRuler '=' 52 ++ [MiLineBreak] 53 ++ maybeDocSection (ifaceRnDoc iface) 54 ++ [MiLineBreak] 55 ++ concatMap docExpIt (ifaceRnExportItems iface) 56 ++ [ MiPushIndent0 57 , MiLineBreak 58 , MiLineBreak 59 , MiNonBreakable "vim:tw=78:fo=tcq2:isk=!-~,^*,^\\|,^\\\":ts=8:ft=help:norl:" ] 60 in ( ppRender txt , modName) 61 where 62 modInfo = ifaceInfo iface 63 modInfotxt = concat 64 [ maybeTab "Portability: " $ hmi_portability modInfo 65 , maybeTab "Stability: " $ hmi_stability modInfo 66 , maybeTab "Maintainer: " $ hmi_maintainer modInfo 67 ] 68 69 maybeTab :: String -> Maybe String -> Markup 70 maybeTab _ (Nothing) = [] 71 maybeTab a (Just b) = [MiLineBreak, MiNonBreakable $ a ++ b] 72 73 74 -- | ExportItem to Markup. 75 docExpIt :: ExportItem DocName -> Markup 76 docExpIt (ExportDecl decl doc subdocs insts) = ppDecl decl doc insts subdocs 77 docExpIt (ExportNoDecl y []) = [ppDocName y] 78 docExpIt (ExportDoc d) = ppRenderDoc d 79 80 docExpIt (ExportNoDecl y subs) 81 = ppDocName y : parenList (map (\a -> [ppDocName a]) subs) 82 83 docExpIt (ExportGroup lvl _ doc) 84 = [ MiPushIndent0, MiLineBreak 85 , MiNonBreakable $ replicate lvl '*' ++ " " 86 ] 87 ++ ppRenderDoc doc 88 ++ [MiIndent 2] 89 90 docExpIt (ExportModule m) 91 = [ MiNonBreakable "module " 92 , ppLink $ moduleString m 93 , MiLineBreak 94 ] -
(a) /dev/null vs. (b) b/src/Haddock/Backends/VimHelp/Decl.hs
diff --git a/src/Haddock/Backends/VimHelp/Decl.hs b/src/Haddock/Backends/VimHelp/Decl.hs new file mode 100644 index 0000000..9b7a69f
a b 1 ----------------------------------------------------------------------------- 2 -- | 3 -- Module : Haddock.Backends.VimHelp.Decl 4 -- Copyright : (c) Simon Marlow 2003-2006, 5 -- David Waern 2006-2009, 6 -- Mark Lentczner 2010 7 -- Lars Krueger 2012 8 -- License : BSD-like 9 -- 10 -- Maintainer : haddock@projects.haskell.org 11 -- Stability : experimental 12 -- Portability : portable 13 -- 14 -- This is based on Haddock.Backends.Xhtml.Decl 15 ----------------------------------------------------------------------------- 16 module Haddock.Backends.VimHelp.Decl ( 17 ppDecl, 18 ) where 19 20 21 import Haddock.Backends.VimHelp.Markup 22 import Haddock.Backends.VimHelp.Utils 23 24 import Haddock.GhcUtils 25 import Haddock.Types 26 27 import BasicTypes ( IPName(..), Boxity(..) ) 28 import GHC 29 import Name 30 import Outputable ( ppr, showSDoc, Outputable ) 31 32 import Control.Monad ( join ) 33 import qualified Data.Map as Map 34 import Data.Maybe 35 import Data.List 36 37 38 forallSymbol :: MarkupItem 39 forallSymbol = MiNonBreakable "forall" 40 41 42 -- | Generate markup for a declaration. 43 ppDecl :: LHsDecl DocName 44 -> DocForDecl DocName 45 -> [DocInstance DocName] 46 -> [(DocName, DocForDecl DocName)] 47 -> Markup 48 ppDecl (L _ decl) (mbDoc, fnArgsDoc) instances subdocs = case decl of 49 TyClD d@(TyFamily {}) -> ppTyFam False mbDoc d 50 TyClD d@(TyData {}) 51 | Nothing <- tcdTyPats d -> ppDataDecl instances subdocs mbDoc d 52 | Just _ <- tcdTyPats d -> ppDataInst mbDoc d 53 TyClD d@(TySynonym {}) 54 | Nothing <- tcdTyPats d -> ppTySyn (mbDoc, fnArgsDoc) d 55 | Just _ <- tcdTyPats d -> ppTyInst False mbDoc d 56 TyClD d@(ClassDecl {}) -> ppClassDecl instances mbDoc subdocs d 57 SigD (TypeSig (L _ n) (L _ t)) -> ppFunSig (mbDoc, fnArgsDoc) n t 58 ForD d -> ppFor (mbDoc, fnArgsDoc) d 59 InstD _ -> [] 60 _ -> error "declaration not supported by ppDecl" 61 62 63 -- | Generate markup for function signature. 64 ppFunSig :: DocForDecl DocName -> DocName -> HsType DocName -> Markup 65 ppFunSig doc docname typ = 66 ppTypeOrFunSig typ doc 67 (ppTypeSig docname typ, [ppBinder docname], [dcolon]) 68 69 70 ppTypeOrFunSig :: HsType DocName 71 -> DocForDecl DocName 72 -> (Markup, Markup, Markup) 73 -> Markup 74 ppTypeOrFunSig typ (doc, argDocs) (pref1, pref2, sep) 75 | Map.null argDocs = topDeclElem pref1 $ maybeDocSection doc 76 | otherwise = topDeclElem pref2 $ 77 subArguments (do_args 0 sep typ) ++ maybeDocSection doc 78 where 79 argDoc n = Map.lookup n argDocs 80 81 do_largs n leader (L _ t) = do_args n leader t 82 do_args :: Int -> Markup -> HsType DocName -> [SubDecl] 83 do_args n leader (HsForAllTy Explicit tvs lctxt ltype) 84 = (leader <+> 85 ((forallSymbol: ppTyVars tvs) ++ [dot]) <+> 86 ppLContextNoArrow lctxt, 87 Nothing, []) 88 : do_largs n [darrow] ltype 89 do_args n leader (HsForAllTy Implicit _ lctxt ltype) 90 | not (null (unLoc lctxt)) 91 = (leader <+> ppLContextNoArrow lctxt, 92 Nothing, []) 93 : do_largs n [darrow] ltype 94 -- if we're not showing any 'forall' or class constraints or 95 -- anything, skip having an empty line for the context. 96 | otherwise 97 = do_largs n leader ltype 98 do_args n leader (HsFunTy lt r) 99 = (leader <+> ppLFunLhType lt, argDoc n, []) 100 : do_largs (n+1) [arrow] r 101 do_args n leader t 102 = [(leader <+> ppType t, argDoc n, [])] 103 104 105 ppTyVars :: [LHsTyVarBndr DocName] -> Markup 106 ppTyVars tvs = intercalate [space] $ map ppTyName (tyvarNames tvs) 107 108 109 tyvarNames :: [LHsTyVarBndr DocName] -> [Name] 110 tyvarNames = map (getName . hsTyVarName . unLoc) 111 112 113 ppFor :: DocForDecl DocName -> ForeignDecl DocName -> Markup 114 ppFor doc (ForeignImport (L _ name) (L _ typ) _) = ppFunSig doc name typ 115 ppFor _ _ = error "ppFor" 116 117 118 -- we skip type patterns for now 119 ppTySyn :: DocForDecl DocName -> TyClDecl DocName -> Markup 120 ppTySyn doc (TySynonym (L _ name) ltyvars _ ltype) = 121 ppTypeOrFunSig (unLoc ltype) doc (full, hdr, [space,equals]) 122 where 123 hdr = [MiNonBreakable "type ", ppBinder name, MiSpaceBeforeLetter] 124 ++ 125 ppTyVars ltyvars 126 full = hdr <+> [equals] <+> ppLType ltype 127 ppTySyn _ _ = error "declaration not supported by ppTySyn" 128 129 130 ppTypeSig :: DocName -> HsType DocName -> Markup 131 ppTypeSig nm ty = 132 [ppBinder nm, space, dcolon] <+> ppType ty 133 134 135 ppName :: Name -> Markup 136 ppName n = [MiNonBreakable $ getOccString n] 137 138 139 ppTyName :: Name -> Markup 140 ppTyName name 141 | isNameSym name = parens (ppName name) 142 | otherwise = ppName name 143 144 145 -------------------------------------------------------------------------------- 146 -- * Type families 147 -------------------------------------------------------------------------------- 148 149 150 ppTyFamHeader :: Bool -> TyClDecl DocName -> Markup 151 ppTyFamHeader associated decl = 152 (case tcdFlavour decl of 153 TypeFamily 154 | associated -> [MiNonBreakable "type"] 155 | otherwise -> [MiNonBreakable "type family"] 156 DataFamily 157 | associated -> [MiNonBreakable "data"] 158 | otherwise -> [MiNonBreakable "data family"] 159 ) <+> 160 ppTyClBinderWithVars decl <+> 161 case tcdKind decl of 162 Just kind -> [dcolon,space] ++ ppKind kind 163 Nothing -> [] 164 165 166 ppTyFam :: Bool -> Maybe (Doc DocName) -> TyClDecl DocName -> Markup 167 ppTyFam associated mbDoc decl = 168 header_ ++ maybeDocSection mbDoc ++ instancesBit 169 where 170 header_ = ppTyFamHeader associated decl 171 instancesBit = ppInstances instances 172 -- TODO: get the instances 173 instances = [] 174 175 176 -------------------------------------------------------------------------------- 177 -- * Indexed data types 178 -------------------------------------------------------------------------------- 179 180 181 ppDataInst :: a 182 ppDataInst = undefined 183 184 185 -------------------------------------------------------------------------------- 186 -- * Indexed types 187 -------------------------------------------------------------------------------- 188 189 190 ppTyInst :: Bool 191 -> Maybe (Doc DocName) 192 -> TyClDecl DocName 193 -> Markup 194 ppTyInst associated mbDoc decl = header_ ++ maybeDocSection mbDoc 195 where 196 docname = tcdName decl 197 header_ = topDeclElem [ppBinder docname] (ppTyInstHeader associated decl) 198 199 200 ppTyInstHeader :: Bool -> TyClDecl DocName -> Markup 201 ppTyInstHeader _ decl = 202 MiNonBreakable "type instance " : ppAppNameTypes (tcdName decl) typeArgs 203 where 204 typeArgs = map unLoc . fromJust . tcdTyPats $ decl 205 206 207 -------------------------------------------------------------------------------- 208 -- * Associated Types 209 -------------------------------------------------------------------------------- 210 211 212 ppAssocType :: DocForDecl DocName -> LTyClDecl DocName -> Markup 213 ppAssocType doc (L _ decl) = 214 case decl of 215 TyFamily {} -> ppTyFam True (fst doc) decl 216 TySynonym {} -> ppTySyn doc decl 217 _ -> error "declaration type not supported by ppAssocType" 218 219 220 -------------------------------------------------------------------------------- 221 -- * TyClDecl helpers 222 -------------------------------------------------------------------------------- 223 224 225 -- | Print a type family / newtype / data / class binder and its variables 226 ppTyClBinderWithVars :: TyClDecl DocName -> Markup 227 ppTyClBinderWithVars decl = 228 ppAppDocNameNames (unLoc $ tcdLName decl) (tyvarNames $ tcdTyVars decl) 229 230 231 -------------------------------------------------------------------------------- 232 -- * Type applications 233 -------------------------------------------------------------------------------- 234 235 236 -- | Print an application of a DocName and a list of HsTypes 237 ppAppNameTypes :: DocName -> [HsType DocName] -> Markup 238 ppAppNameTypes n ts = 239 ppTypeApp n ts ppDocName ppParendType 240 241 242 -- | Print an application of a DocName and a list of Names 243 ppAppDocNameNames :: DocName -> [Name] -> Markup 244 ppAppDocNameNames n ns = 245 ppTypeApp n ns ppBinder ppTyName 246 247 248 -- | General printing of type applications 249 ppTypeApp :: DocName 250 -> [a] 251 -> (DocName -> MarkupItem) 252 -> (a -> Markup) 253 -> Markup 254 ppTypeApp n (t1:t2:rest) ppDN ppT 255 | operator, not . null $ rest = 256 parens $ opApp <+> intercalate [space] (map ppT rest) 257 | operator = opApp 258 where 259 operator = isNameSym . getName $ n 260 opApp = ppT t1 <+> [ppDN n] <+> ppT t2 261 262 ppTypeApp n ts ppDN ppT = 263 [ppDN n] <+> intercalate [space] (map ppT ts) 264 265 266 ------------------------------------------------------------------------------- 267 -- * Contexts 268 ------------------------------------------------------------------------------- 269 270 271 ppLContext, ppLContextNoArrow :: Located (HsContext DocName) -> Markup 272 ppLContext = ppContext . unLoc 273 ppLContextNoArrow = ppContextNoArrow . unLoc 274 275 276 ppContextNoArrow :: HsContext DocName -> Markup 277 ppContextNoArrow [] = [] 278 ppContextNoArrow cxt = ppHsContext (map unLoc cxt) 279 280 281 ppContextNoLocs :: [HsPred DocName] -> Markup 282 ppContextNoLocs [] = [] 283 ppContextNoLocs cxt = ppHsContext cxt <+> [darrow] 284 285 286 ppContext :: HsContext DocName -> Markup 287 ppContext cxt = ppContextNoLocs (map unLoc cxt) 288 289 290 ppHsContext :: [HsPred DocName] -> Markup 291 ppHsContext [] = [] 292 ppHsContext [p] = ppPred p 293 ppHsContext cxt = parenList (intersperse [space] $ map ppPred cxt) 294 295 296 ppPred :: HsPred DocName -> Markup 297 ppPred (HsClassP n ts) = ppAppNameTypes n (map unLoc ts) 298 ppPred (HsEqualP t1 t2) = ppLType t1 <+> [MiNonBreakable "~"] <+> ppLType t2 299 ppPred (HsIParam (IPName n) t) = 300 [MiNonBreakable "?", ppDocName n, space, dcolon] <+> ppLType t 301 302 303 ------------------------------------------------------------------------------- 304 -- * Class declarations 305 ------------------------------------------------------------------------------- 306 307 308 ppClassHdr :: Located [LHsPred DocName] 309 -> DocName 310 -> [Located (HsTyVarBndr DocName)] 311 -> [Located ([DocName], [DocName])] 312 -> Markup 313 ppClassHdr lctxt n tvs fds = 314 [MiNonBreakable "class"] 315 <+> (if not . null . unLoc $ lctxt then ppLContext lctxt else []) 316 <+> ppAppDocNameNames n (tyvarNames tvs) 317 <+> ppFds fds 318 319 320 ppFds :: [Located ([DocName], [DocName])] -> Markup 321 ppFds fds = 322 if null fds 323 then [] 324 else [ MiNonBreakable "|", space] 325 ++ intersperse comma (concatMap (fundep . unLoc) fds) 326 where 327 fundep (vars1,vars2) = map ppDocName vars1 328 <+> [arrow] 329 <+> map ppDocName vars2 330 331 332 ppClassDecl :: [DocInstance DocName] 333 -> Maybe (Doc DocName) 334 -> [(DocName, DocForDecl DocName)] 335 -> TyClDecl DocName 336 -> Markup 337 ppClassDecl instances mbDoc subdocs 338 (ClassDecl lctxt lname ltyvars lfds lsigs _ ats _) = 339 classheader 340 ++ maybeDocSection mbDoc 341 ++ atBit 342 ++ methodBit 343 ++ instancesBit 344 where 345 classheader 346 | null lsigs = hdr 347 | otherwise = hdr ++ [MiNonBreakable " where"] 348 349 hdr = ppClassHdr lctxt (unLoc lname) ltyvars lfds 350 351 atBit = subAssociatedTypes [ ppAssocType doc at 352 | at <- ats 353 , let doc = lookupAnySubdoc (tcdName $ unL at) subdocs ] 354 355 methodBit = subMethods [ ppFunSig doc n typ 356 | L _ (TypeSig (L _ n) (L _ typ)) <- lsigs 357 , let doc = lookupAnySubdoc n subdocs ] 358 359 instancesBit = ppInstances instances 360 361 ppClassDecl _ _ _ _ = error "declaration type not supported by ppShortClassDecl" 362 363 364 ppInstances :: [DocInstance DocName] -> Markup 365 ppInstances instances = subInstances (map instDecl instances) 366 where 367 instDecl :: DocInstance DocName -> SubDecl 368 instDecl (inst, maybeDoc) = (instHead inst, maybeDoc, []) 369 instHead ([], n, ts) = ppAppNameTypes n ts 370 instHead (ctxt, n, ts) = ppContextNoLocs ctxt <+> ppAppNameTypes n ts 371 372 373 lookupAnySubdoc :: (Eq name1) => 374 name1 -> [(name1, DocForDecl name2)] -> DocForDecl name2 375 lookupAnySubdoc n subdocs = fromMaybe noDocForDecl (lookup n subdocs) 376 377 378 ------------------------------------------------------------------------------- 379 -- * Data & newtype declarations 380 ------------------------------------------------------------------------------- 381 382 383 ppDataDecl :: [DocInstance DocName] 384 -> [(DocName, DocForDecl DocName)] 385 -> Maybe (Doc DocName) 386 -> TyClDecl DocName 387 -> Markup 388 ppDataDecl instances subdocs mbDoc dataDecl = 389 topDeclElem header_ $ maybeDocSection mbDoc ++ constrBit ++ instancesBit 390 where 391 cons = tcdCons dataDecl 392 resTy = (con_res . unLoc . head) cons 393 394 header_ = ppDataHeader dataDecl 395 ++ [whereBit] 396 397 whereBit 398 | null cons = MiNothing 399 | otherwise = case resTy of 400 ResTyGADT _ -> MiNonBreakable "where" 401 _ -> MiNothing 402 403 constrBit = subConstructors 404 (map (ppSideBySideConstr subdocs) cons) 405 406 instancesBit = ppInstances instances 407 408 409 -- ppConstrHdr is for (non-GADT) existentials constructors' syntax 410 ppConstrHdr :: HsExplicitFlag -> [Name] -> HsContext DocName -> Markup 411 ppConstrHdr forAllFlag tvs ctxt 412 = (if null tvs then [] else ppForall) 413 ++ 414 (if null ctxt then [] else ppContextNoArrow ctxt 415 <+> [darrow, space]) 416 where 417 ppForall = case forAllFlag of 418 Explicit -> 419 [forallSymbol] 420 <+> intercalate [space] (map ppName tvs) 421 ++ [MiNonBreakable " . "] 422 Implicit -> [] 423 424 425 ppSideBySideConstr :: [(DocName, DocForDecl DocName)] 426 -> LConDecl DocName 427 -> SubDecl 428 ppSideBySideConstr subdocs (L _ con) = (decl, mbDoc, fieldPart) 429 where 430 decl = case con_res con of 431 ResTyH98 -> case con_details con of 432 PrefixCon args -> 433 header_ ++ [ppBinderConstr occ] ++ 434 concatMap (\a -> space:ppLParendType a) args 435 436 RecCon _ -> header_ ++ [ppBinderConstr occ] 437 438 InfixCon arg1 arg2 -> 439 (header_ ++ ppLParendType arg1) ++ 440 [ppBinder occ] ++ 441 ppLParendType arg2 442 443 ResTyGADT resTy -> case con_details con of 444 -- prefix & infix could also use hsConDeclArgTys if it seemed to 445 -- simplify the code. 446 PrefixCon args -> doGADTCon args resTy 447 cd@(RecCon _) -> doGADTCon (hsConDeclArgTys cd) resTy 448 InfixCon arg1 arg2 -> doGADTCon [arg1, arg2] resTy 449 450 fieldPart = case con_details con of 451 RecCon fields -> [doRecordFields fields] 452 _ -> [] 453 454 doRecordFields fields = subFields 455 (map (ppSideBySideField subdocs ) fields) 456 doGADTCon :: [LHsType DocName] -> Located (HsType DocName) -> Markup 457 doGADTCon args resTy = 458 [ppBinderConstr occ, space, dcolon, space] ++ 459 (ppForAll forAllFlag ltvs (con_cxt con) ++ 460 ppLType (foldr mkFunTy resTy args) ) 461 462 header_ = ppConstrHdr forAllFlag tyVars context 463 occ = unLoc . con_name $ con 464 ltvs = con_qvars con 465 tyVars = tyvarNames (con_qvars con) 466 context = unLoc (con_cxt con) 467 forAllFlag = con_explicit con 468 -- don't use "con_doc con", in case it's reconstructed from a .hi file, 469 -- or also because we want Haddock to do the doc-parsing, not GHC. 470 -- 'join' is in Maybe. 471 mbDoc = join $ fmap fst $ lookup (unLoc $ con_name con) subdocs 472 mkFunTy a b = noLoc (HsFunTy a b) 473 474 475 ppSideBySideField :: [(DocName, DocForDecl DocName)] 476 -> ConDeclField DocName -> SubDecl 477 ppSideBySideField subdocs (ConDeclField (L _ name) ltype _) = 478 ([ppBinder name, space, dcolon, space] ++ ppLType ltype, 479 mbDoc, 480 []) 481 where 482 -- don't use cd_fld_doc for same reason we don't use con_doc above 483 mbDoc = join $ fmap fst $ lookup name subdocs 484 485 486 -- | Print the LHS of a data\/newtype declaration. 487 -- Currently doesn't handle 'data instance' decls or kind signatures 488 ppDataHeader :: TyClDecl DocName -> Markup 489 ppDataHeader decl 490 | not (isDataDecl decl) = error "ppDataHeader: illegal argument" 491 | otherwise = 492 -- newtype or data 493 [if tcdND decl == NewType 494 then MiNonBreakable "newtype" 495 else MiNonBreakable "data"] 496 -- context 497 <?> ppLContext (tcdCtxt decl) 498 -- T a b c ..., or a :+: b 499 <?> ppTyClBinderWithVars decl 500 501 502 -------------------------------------------------------------------------------- 503 -- * Types and contexts 504 -------------------------------------------------------------------------------- 505 506 507 ppKind :: Outputable a => a -> Markup 508 ppKind k = [MiNonBreakable $ showSDoc (ppr k)] 509 510 511 -- Unpacked args is an implementation detail, so we just show the strictness 512 -- annotation 513 ppBang :: HsBang -> Markup 514 ppBang HsNoBang = [] 515 ppBang _ = [MiNonBreakable "!" ] 516 517 518 tupleParens :: Boxity -> [Markup] -> Markup 519 tupleParens Boxed = parenList 520 tupleParens Unboxed = ubxParenList 521 522 523 -------------------------------------------------------------------------------- 524 -- * Rendering of HsType 525 -------------------------------------------------------------------------------- 526 527 528 pRECTOP, pRECFUN, pRECOP, pRECCON :: Int 529 530 pRECTOP = 0 :: Int -- type in ParseIface.y in GHC 531 pRECFUN = 1 :: Int -- btype in ParseIface.y in GHC 532 -- Used for LH arg of (->) 533 pRECOP = 2 :: Int -- Used for arg of any infix operator 534 -- (we don't keep their fixities around) 535 pRECCON = 3 :: Int -- Used for arg of type applicn: 536 -- always parenthesise unless atomic 537 538 maybeParen :: Int -- Precedence of context 539 -> Int -- Precedence of top-level operator 540 -> Markup -> Markup -- Wrap in parens if (ctxt >= op) 541 maybeParen ctxt_prec op_prec p | ctxt_prec >= op_prec = parens p 542 | otherwise = p 543 544 545 ppLType, ppLParendType, ppLFunLhType :: Located (HsType DocName) -> Markup 546 ppLType y = ppType (unLoc y) 547 ppLParendType y = ppParendType (unLoc y) 548 ppLFunLhType y = ppFunLhType (unLoc y) 549 550 551 ppType, ppParendType, ppFunLhType :: HsType DocName -> Markup 552 ppType = pprMonoTy pRECTOP 553 ppParendType = pprMonoTy pRECCON 554 ppFunLhType = pprMonoTy pRECFUN 555 556 557 -- Drop top-level for-all type variables in user style 558 -- since they are implicit in Haskell 559 560 ppForAll :: HsExplicitFlag -> [Located (HsTyVarBndr DocName)] 561 -> Located (HsContext DocName) -> Markup 562 ppForAll expl tvs cxt 563 | show_forall = forall_part <+> ppLContext cxt 564 | otherwise = ppLContext cxt 565 where 566 show_forall = not (null tvs) && is_explicit 567 is_explicit = case expl of {Explicit -> True; Implicit -> False} 568 forall_part = (forallSymbol : space : ppTyVars tvs) ++ [dot] 569 570 571 pprMonoLty :: Int -> LHsType DocName -> Markup 572 pprMonoLty ctxt_prec ty = pprMonoTy ctxt_prec (unLoc ty) 573 574 575 pprMonoTy :: Int -> HsType DocName -> Markup 576 pprMonoTy _ (HsListTy ty) = brackets (pprMonoLty pRECTOP ty) 577 pprMonoTy _ (HsBangTy b ty) = ppBang b ++ ppLParendType ty 578 pprMonoTy ctxt_prec (HsFunTy ty1 ty2) = pprFunTy ctxt_prec ty1 ty2 579 pprMonoTy _ (HsTupleTy con tys) = tupleParens con (map ppLType tys) 580 pprMonoTy _ (HsPredTy p) = parens (ppPred p) 581 pprMonoTy _ (HsNumTy n) = [MiNonBreakable (show n)] -- generics only 582 pprMonoTy ctxt_prec (HsParTy ty) = pprMonoLty ctxt_prec ty 583 pprMonoTy ctxt_prec (HsDocTy ty _) = pprMonoLty ctxt_prec ty 584 pprMonoTy _ (HsSpliceTy {}) = error "pprMonoTy HsSpliceTy" 585 pprMonoTy _ (HsQuasiQuoteTy {}) = error "pprMonoTy HsQuasiQuoteTy" 586 pprMonoTy _ (HsCoreTy {}) = error "pprMonoTy HsCoreTy" 587 pprMonoTy _ (HsRecTy {}) = error "pprMonoTy HsRecTy" 588 589 pprMonoTy ctxt_prec (HsForAllTy expl tvs ctxt ty) = 590 maybeParen ctxt_prec pRECFUN $ 591 ppForAll expl tvs ctxt <+> pprMonoLty pRECTOP ty 592 593 pprMonoTy _ (HsTyVar name) = 594 [ppDocName name, MiSpaceBeforeLetter] 595 596 pprMonoTy _ (HsKindSig ty kind) = 597 parens (pprMonoLty pRECTOP ty <+> [dcolon] <+> ppKind kind) 598 599 pprMonoTy _ (HsPArrTy ty) = 600 pabrackets (pprMonoLty pRECTOP ty) 601 602 pprMonoTy ctxt_prec (HsAppTy fun_ty arg_ty) = 603 maybeParen ctxt_prec pRECCON $ 604 pprMonoLty pRECFUN fun_ty ++ pprMonoLty pRECCON arg_ty 605 606 pprMonoTy ctxt_prec (HsOpTy ty1 op ty2) = 607 maybeParen ctxt_prec pRECFUN $ 608 pprMonoLty pRECOP ty1 <+> ppr_op <+> pprMonoLty pRECOP ty2 609 where 610 ppr_op = if not (isSymOcc occName) 611 then quote (ppLDocName op) 612 else ppLDocName op 613 occName = nameOccName . getName . unLoc $ op 614 615 616 pprFunTy :: Int -> LHsType DocName -> LHsType DocName -> Markup 617 pprFunTy ctxt_prec ty1 ty2 = 618 let p1 = pprMonoLty pRECFUN ty1 619 p2 = pprMonoLty pRECTOP ty2 620 in maybeParen ctxt_prec pRECFUN $ p1 <+> [arrow] <+> p2 621 622 623 ppLDocName :: Located DocName -> Markup 624 ppLDocName (L _ d) = [ppDocName d] 625 626 627 -------------------------------------------------------------------------------- 628 -- * Declaration containers 629 -------------------------------------------------------------------------------- 630 631 632 type SubDecl = (Markup, Maybe (Doc DocName), [Markup]) 633 634 635 divSubDecls :: String -> Maybe Markup -> Markup 636 divSubDecls _ Nothing = [MiLineBreak] 637 divSubDecls c (Just m) = 638 [ MiPushIndent 639 , MiIndent 2 640 , MiNonBreakable c 641 , MiPushIndent 642 , MiNextIndent 3 643 ] 644 ++ m 645 ++ 646 [ MiPopIndent 647 , MiPopIndent 648 , MiLineBreak 649 ] 650 651 652 subDlist :: [SubDecl] -> Maybe Markup 653 subDlist [] = Nothing 654 subDlist decls = Just $ concatMap subEntry decls 655 where 656 subEntry (decl, mdoc, subs) = 657 ppListItem True decl (maybeDocSection mdoc ++ concat subs) 658 659 660 subBlock :: [Markup] -> Maybe Markup 661 subBlock [] = Nothing 662 subBlock hs = Just $ concatMap (\a -> MiLineBreak : a) hs 663 664 665 subArguments :: [SubDecl] -> Markup 666 subArguments = divSubDecls "Arguments" . subDlist 667 668 669 subAssociatedTypes :: [Markup] -> Markup 670 subAssociatedTypes = divSubDecls "Associated Types" . subBlock 671 672 673 subConstructors :: [SubDecl] -> Markup 674 subConstructors = divSubDecls "Constructors" . subDlist 675 676 677 subFields :: [SubDecl] -> Markup 678 subFields = divSubDecls "Fields" . subDlist 679 680 681 subInstances :: [SubDecl] -> Markup 682 subInstances = divSubDecls "Instances" . subDlist 683 684 subMethods :: [Markup] -> Markup 685 subMethods = divSubDecls "Methods" . subBlock 686 687 688 -- a box for top level documented names 689 topDeclElem :: Markup -> Markup -> Markup 690 topDeclElem hd body = (MiPushIndent:(MiIndent 2:hd)) ++ body ++ [MiPopIndent] -
(a) /dev/null vs. (b) b/src/Haddock/Backends/VimHelp/Markup.hs
diff --git a/src/Haddock/Backends/VimHelp/Markup.hs b/src/Haddock/Backends/VimHelp/Markup.hs new file mode 100644 index 0000000..4c8fcf6
a b 1 ----------------------------------------------------------------------------- 2 -- | 3 -- Module : Haddock.Backends.VimHelp.Markup 4 -- Copyright : (c) Lars Krueger 2012 5 -- License : BSD-like 6 -- 7 -- Maintainer : lars_e_krueger@gmx.de 8 -- Stability : experimental 9 -- Portability : portable 10 -- 11 -- Simple markup processing to generate good-looking text without 12 -- too much character fiddling in the actual output generation. 13 -- The module takes care of the line width, breaks text, indents items, etc. 14 ----------------------------------------------------------------------------- 15 module Haddock.Backends.VimHelp.Markup 16 ( MarkupItem (..) 17 , Markup 18 , ppRender 19 , ppRuler 20 ) where 21 22 23 import Data.Char 24 25 26 -- | Simple linear markup. Each item influences the render state. 27 data MarkupItem 28 = MiBreakable String -- ^ Normal text, will be word-wrapped 29 | MiNonBreakable String -- ^ String to be treated as one character 30 | MiNothing -- ^ Empty string to cope with maybes 31 | MiParagraph -- ^ A paragraph begins 32 | MiIndent Int -- ^ Change the indentation 33 | MiLineBreak -- ^ A mandatory linebreak 34 | MiPushIndent0 -- ^ Store the indent level on the stack, set to 0 35 | MiPushIndent -- ^ Store the indent level on the stack 36 | MiNextIndent Int -- ^ Set the indent of the next line 37 | MiPopIndent -- ^ Get the former indent level from the stack 38 | MiSpaceBeforeLetter -- ^ If the next item begins with a letter, put 39 -- a space here 40 | MiVerbatim Bool -- ^ Do not manipulate the text 41 deriving (Eq) 42 43 44 -- | A list of markup items. 45 type Markup = [MarkupItem] 46 47 48 -- | The width of the page in characters 49 ppTextWidth :: Int 50 ppTextWidth = 80 51 52 53 -- | Render state. 54 data RenderState = RenderState 55 { rsIndent :: Int -- ^ Number of characters to indent 56 , rsChars :: Int -- ^ Number of characters in line 57 , rsIndStack :: [Int] -- ^ Indent stack 58 , rsSpcBefLet :: Bool -- ^ Space before letter flag 59 , rsVerbatim :: Bool -- ^ Do not manipulate space 60 } 61 62 63 -- | Result of a render function. 64 type RenderResult a = (RenderState,a) 65 66 67 -- | Convert markup into a string for printing. The final render state is not 68 -- made available, hence you can't pass it around. 69 ppRender :: Markup -> String 70 ppRender = concat . renderItems (RenderState 0 0 [] False False) 71 72 73 -- | Render the items and update the state. 74 renderItems :: RenderState -> Markup -> [String] 75 renderItems _ [] = [] 76 renderItems rs (it:its) = 77 let (nrs,mbLine) = render rs it 78 in case mbLine of 79 Nothing -> renderItems nrs its 80 Just l -> l:renderItems nrs its 81 82 83 -- | Begin a new line with correct identation and place the given string at 84 newLine :: RenderState -> String -> RenderResult String 85 newLine rs s = 86 let ls = length s 87 in ( rs { rsSpcBefLet = False 88 , rsChars = ls } 89 , "\n" ++ replicate (rsIndent rs) ' ' ++ s 90 ) 91 92 93 -- | Append string, but do not break the line. Handle optional spaces. 94 appendLine :: RenderState -> String -> RenderResult String 95 appendLine rs str = 96 let s = if rsSpcBefLet rs 97 then case str of 98 c1:_ -> if canHazSpace c1 99 then ' ' : str 100 else str 101 _ -> str 102 else str 103 ls = length s 104 in ( rs { rsChars = ls + rsChars rs 105 , rsSpcBefLet = False} 106 , s 107 ) 108 where 109 canHazSpace c = isLetter c || (c `elem` "*(|") 110 111 112 -- | Append string, but open a new line if the string would not fit. 113 appendWord :: RenderState -> String -> RenderResult String 114 appendWord rs s = 115 let ls = length s 116 in if (rsIndent rs + rsChars rs + ls) >= ppTextWidth 117 then newLine rs s 118 else appendLine rs s 119 120 121 -- | Helper for output-generating markup items. 122 just2 :: RenderResult a -> RenderResult (Maybe a) 123 just2 (rs,a) = (rs, Just a) 124 125 126 -- | Helper for state-changing markup items. 127 nothing2 :: RenderState -> RenderResult (Maybe a) 128 nothing2 rs = (rs,Nothing) 129 130 131 -- | Render a single markup item to a single sting or just change the state. 132 render :: RenderState -> MarkupItem -> RenderResult (Maybe String) 133 render rs (MiNothing) = nothing2 rs 134 render rs (MiSpaceBeforeLetter) = nothing2 $ rs { rsSpcBefLet = True } 135 render rs (MiVerbatim v) = nothing2 $ rs { rsVerbatim = v } 136 render rs (MiNonBreakable s) = just2 $ appendWord rs s 137 render rs (MiParagraph) = just2 $ newLine rs " " 138 render rs (MiLineBreak) = just2 $ newLine (rs { rsSpcBefLet = False }) "" 139 140 render rs (MiIndent ind) 141 = just2 $ newLine 142 (rs 143 { rsSpcBefLet = False 144 , rsIndent = max 0 $ rsIndent rs + ind } 145 ) 146 "" 147 148 -- | Linebreak the string or copy if verbatim is on. Since we need to pass the 149 -- render state through it and we need the final render state as a return 150 -- value, this works with an intermediate list of (RenderState,String) tuples. 151 -- Since most items here are short, this should not result in much memory 152 -- overhead 153 render rs (MiBreakable s) = 154 -- switch functions for verbatim mode 155 let (wrds,aw,al,alp) = 156 if rsVerbatim rs 157 then (lines, appendLine, newLine, "") 158 else (words, appendWord, appendLine, " ") 159 rs_lns = mapState (processWord aw al alp) rs $ wrds s 160 in case rs_lns of 161 [] -> nothing2 rs 162 lns -> just2 (fst $ last lns, concatMap snd lns) 163 where 164 processWord aw al alp rs1 w 165 = let (rs2,l1) = aw rs1 w 166 (rs3,l2) = al rs2 alp 167 in (rs3,l1++l2) 168 169 mapState _ _ [] = [] 170 mapState fun rs1 [a] = [fun rs1 a] 171 mapState fun rs1 (a:as) = let rs2b@(rs2,_) = fun rs1 a 172 in rs2b:mapState fun rs2 as 173 174 render rs (MiPushIndent0) = nothing2 $ 175 rs { rsSpcBefLet = False 176 , rsIndent = 0 177 , rsIndStack = rsIndent rs : rsIndStack rs} 178 179 render rs (MiPushIndent) = nothing2 $ 180 rs { rsIndStack = rsIndent rs : rsIndStack rs} 181 182 render rs (MiNextIndent ind) = nothing2 $ 183 rs { rsSpcBefLet = False 184 , rsIndent = max 0 $ rsIndent rs + ind } 185 186 render rs (MiPopIndent) = nothing2 $ 187 case rsIndStack rs of 188 [] -> rs 189 (i:rest) -> rs { rsSpcBefLet = False 190 , rsIndent = i 191 , rsIndStack = rest } 192 193 194 -- | Draw a horizontal line over the whole text width. 195 ppRuler :: Char -> Markup 196 ppRuler c = 197 [ MiPushIndent0 198 , MiNonBreakable $ replicate ppTextWidth c 199 , MiPopIndent 200 ] -
(a) /dev/null vs. (b) b/src/Haddock/Backends/VimHelp/Utils.hs
diff --git a/src/Haddock/Backends/VimHelp/Utils.hs b/src/Haddock/Backends/VimHelp/Utils.hs new file mode 100644 index 0000000..9dd0bce
a b 1 ----------------------------------------------------------------------------- 2 -- | 3 -- Module : Haddock.Backends.VimHelp.Utils 4 -- Copyright : (c) Lars Krueger 2012 5 -- License : BSD-like 6 -- 7 -- Maintainer : lars_e_krueger@gmx.de 8 -- Stability : experimental 9 -- Portability : portable 10 ----------------------------------------------------------------------------- 11 module Haddock.Backends.VimHelp.Utils 12 ( ppDocName 13 , ppBinder 14 , ppBinderConstr 15 , ppPlainName 16 , parenList 17 , dcolon 18 , parens 19 , brackets 20 , pabrackets 21 , braces 22 , (<+>) 23 , (<?>) 24 , dot 25 , darrow 26 , arrow 27 , equals 28 , space 29 , comma 30 , ubxParenList 31 , ubxparens 32 , maybeDocSection 33 , maybeIndentedDocSection 34 , quote 35 , ppRenderDoc 36 , ppLink 37 , ppRef 38 , ppListItem 39 ) where 40 41 import Haddock.Backends.VimHelp.Markup 42 43 import Haddock.GhcUtils 44 import Haddock.Types 45 46 import Module 47 import Name 48 49 import Data.List 50 import Text.Printf 51 52 53 -- | Generate a link to something (similar to <href>) 54 ppLink :: String -> MarkupItem 55 ppLink s = MiNonBreakable $ "|" ++ s ++ "|" 56 57 58 -- | Generate an anchor for something (similar to <a>) 59 ppRef :: String -> MarkupItem 60 ppRef s = MiNonBreakable $ "*" ++ s ++ "*" 61 62 63 -- | Markup for a DocName. Tries to be smart about built-in things. 64 ppDocName :: DocName -> MarkupItem 65 ppDocName (Undocumented name) = MiNonBreakable $ getOccString name 66 ppDocName (Documented name mdl) = 67 if isBuiltinModule mdl 68 then MiNonBreakable nameStr 69 else ppLink $ mdlStr ++ "." ++ nameStr 70 where 71 mdlStr = moduleString mdl 72 nameStr = getOccString name 73 74 75 -- | Check if module if built-in 76 isBuiltinModule :: Module -> Bool 77 isBuiltinModule mdl = modulePackageId mdl `elem` 78 [ primPackageId 79 , integerPackageId 80 , basePackageId 81 , rtsPackageId 82 , thPackageId 83 , dphSeqPackageId 84 , dphParPackageId 85 , mainPackageId 86 ] 87 88 89 -- | Generate a reference to this DocName, if possible 90 ppBinder :: DocName -> MarkupItem 91 ppBinder (Undocumented n) = MiNonBreakable $ getOccString n 92 ppBinder (Documented n m) = ppRef $ moduleString m ++ "." ++ getOccString n 93 94 95 -- | Generate a reference to this DocName, if possible. Special case for 96 -- constructors that may have the same name as their type. 97 ppBinderConstr :: DocName -> MarkupItem 98 ppBinderConstr (Undocumented n) = MiNonBreakable $ getOccString n 99 ppBinderConstr (Documented n m) = ppRef $ 100 "Constructor:" ++ moduleString m ++ "." ++ getOccString n 101 102 103 -- | DocName to regular string. 104 ppPlainName :: DocName -> MarkupItem 105 ppPlainName (Undocumented n) = MiNonBreakable $ getOccString n 106 ppPlainName (Documented n _) = MiNonBreakable $ getOccString n 107 108 109 parenList :: [Markup] -> Markup 110 parenList = parens . intercalate [comma] 111 112 113 dcolon :: MarkupItem 114 dcolon = MiNonBreakable "::" 115 116 117 dot :: MarkupItem 118 dot = MiNonBreakable "." 119 120 121 darrow :: MarkupItem 122 darrow = MiNonBreakable "=>" 123 124 125 arrow :: MarkupItem 126 arrow = MiNonBreakable "->" 127 128 129 equals :: MarkupItem 130 equals = MiNonBreakable "=" 131 132 133 space :: MarkupItem 134 space = MiNonBreakable " " 135 136 137 comma :: MarkupItem 138 comma = MiNonBreakable "," 139 140 141 ubxparens :: Markup -> Markup 142 ubxparens = enclose "(#" "#)" 143 144 145 dquote :: Markup -> Markup 146 dquote = enclose "''" "''" 147 148 149 quote :: Markup -> Markup 150 quote = enclose "'" "'" 151 152 153 parens :: Markup -> Markup 154 parens = enclose "(" ")" 155 156 157 brackets :: Markup -> Markup 158 brackets = enclose "[" "]" 159 160 161 pabrackets :: Markup -> Markup 162 pabrackets = enclose "[:" ":]" 163 164 165 braces :: Markup -> Markup 166 braces = enclose "{" "}" 167 168 169 enclose :: String -> String -> Markup -> Markup 170 enclose a b h = 171 (MiNonBreakable a : makeNonBreakable h) ++ [MiNonBreakable b] 172 where 173 makeNonBreakable = map toNonBreakable 174 toNonBreakable :: MarkupItem -> MarkupItem 175 toNonBreakable (MiBreakable s) = MiNonBreakable s 176 toNonBreakable i = i 177 178 179 infixr 8 <+> 180 (<+>) :: Markup-> Markup-> Markup 181 a <+> b = a ++ (MiNonBreakable " " : b) 182 183 184 infixr 8 <?> 185 (<?>) :: Markup-> Markup-> Markup 186 a <?> b = a ++ (MiSpaceBeforeLetter : b) 187 188 189 ubxParenList :: [Markup] -> Markup 190 ubxParenList = ubxparens . intercalate [comma] 191 192 193 maybeDocSection :: Maybe (Doc DocName) -> Markup 194 maybeDocSection Nothing = [] 195 maybeDocSection (Just s) = ppRenderDoc s 196 197 198 maybeIndentedDocSection :: Maybe (Doc DocName) -> Markup 199 maybeIndentedDocSection Nothing = [] 200 maybeIndentedDocSection (Just s) = 201 (MiPushIndent : MiIndent 2 : dropParagraph ( ppRenderDoc s)) 202 ++ 203 [MiPopIndent] 204 205 206 ppRenderDoc :: Doc DocName -> Markup 207 ppRenderDoc DocEmpty = [] 208 ppRenderDoc (DocPic _) = [] 209 ppRenderDoc (DocAppend a b) = ppRenderDoc a ++ ppRenderDoc b 210 ppRenderDoc (DocString s) = [MiBreakable s] 211 ppRenderDoc (DocParagraph d) = MiParagraph:ppRenderDoc d 212 ppRenderDoc (DocModule m) = [ppLink m] 213 ppRenderDoc (DocEmphasis d) = ppRenderDoc d 214 ppRenderDoc (DocMonospaced d) = ppRenderDoc d 215 ppRenderDoc (DocURL s) = [MiNonBreakable s] 216 ppRenderDoc (DocAName s) = [MiNonBreakable s] 217 218 ppRenderDoc (DocExamples ex) = concatMap renderEx ex 219 where 220 renderEx :: Example -> Markup 221 renderEx (Example exm res) = 222 beginCodeBlock 223 ++ [ 224 MiNonBreakable (">>> " ++ exm), 225 MiLineBreak] 226 ++ concatMap (\a -> [MiNonBreakable a, MiLineBreak]) res 227 ++ endCodeBlock 228 229 ppRenderDoc (DocCodeBlock d) = 230 beginCodeBlock ++ ppRenderDoc d ++ endCodeBlock 231 232 -- Show the first identifier only 233 ppRenderDoc (DocIdentifier ds) = [ppDocName $ head ds, MiSpaceBeforeLetter] 234 235 ppRenderDoc (DocUnorderedList ds) = 236 ppList (ppListItemDoc False [MiNonBreakable "-"]) ds 237 238 ppRenderDoc (DocOrderedList ds) = 239 ppList (\(d,i) -> ppListItemDoc False [MiNonBreakable $ printf "%2d." i] d) 240 $ 241 zip ds [(1::Int)..] 242 243 ppRenderDoc (DocDefList ds) = 244 ppList (\(c,d) -> ppListItemDoc True (dquote (ppRenderDoc c)) d) ds 245 246 247 ppList :: (a -> Markup) -> [a] -> Markup 248 ppList f ds = concatMap f ds ++ [MiLineBreak] 249 250 251 ppListItem :: Bool -> Markup -> Markup -> Markup 252 ppListItem _ bull [] = 253 [MiPushIndent,MiLineBreak,MiNextIndent 2] 254 ++ bull 255 ++ [MiPopIndent] 256 ppListItem doBreak bull desc = 257 [MiPushIndent,MiLineBreak,MiNextIndent 2] 258 ++ bull 259 ++ ((if doBreak then MiLineBreak else MiSpaceBeforeLetter):dropParagraph desc) 260 ++ [MiPopIndent] 261 262 263 ppListItemDoc :: Bool -> Markup -> Doc DocName -> Markup 264 ppListItemDoc doBreak bull desc = 265 ppListItem doBreak bull $ dropParagraph $ ppRenderDoc desc 266 267 268 dropParagraph :: Markup -> Markup 269 dropParagraph = dropWhile (== MiParagraph) 270 271 272 beginCodeBlock :: Markup 273 beginCodeBlock = 274 [ MiPushIndent0 275 , MiLineBreak 276 , MiNonBreakable ">" 277 , MiPopIndent 278 , MiPushIndent0 279 , MiIndent 2 280 , MiLineBreak 281 , MiVerbatim True 282 ] 283 284 285 endCodeBlock :: Markup 286 endCodeBlock = 287 [ MiVerbatim False 288 , MiPopIndent 289 , MiPushIndent0 290 , MiLineBreak 291 , MiNonBreakable "<" 292 , MiPopIndent 293 ] -
src/Haddock/Options.hs
diff --git a/src/Haddock/Options.hs b/src/Haddock/Options.hs index 4e42fd3..c64cf69 100644
a b 58 58 | Flag_WikiModuleURL String 59 59 | Flag_WikiEntityURL String 60 60 | Flag_LaTeX 61 | Flag_VimHelp 61 62 | Flag_LaTeXStyle String 62 63 | Flag_Help 63 64 | Flag_Verbosity String … … 101 102 "output in HTML (XHTML 1.0)", 102 103 Option [] ["latex"] (NoArg Flag_LaTeX) "use experimental LaTeX rendering", 103 104 Option [] ["latex-style"] (ReqArg Flag_LaTeXStyle "FILE") "provide your own LaTeX style in FILE", 105 Option [] ["vimhelp"] (NoArg Flag_VimHelp) "use experimental VIM help file rendering", 104 106 Option ['U'] ["use-unicode"] (NoArg Flag_UseUnicode) "use Unicode in HTML output", 105 107 Option [] ["hoogle"] (NoArg Flag_Hoogle) 106 108 "output for Hoogle", -
src/Main.hs
diff --git a/src/Main.hs b/src/Main.hs index 0a3c9ff..724b78f 100644
a b 21 21 import Haddock.Backends.Xhtml 22 22 import Haddock.Backends.Xhtml.Themes (getThemes) 23 23 import Haddock.Backends.LaTeX 24 import Haddock.Backends.VimHelp 24 25 import Haddock.Backends.Hoogle 25 26 import Haddock.Interface 26 27 import Haddock.Lex … … 142 143 renderStep flags packages ifaces 143 144 144 145 else do 145 when (any (`elem` [Flag_Html, Flag_Hoogle, Flag_LaTeX ]) flags) $146 when (any (`elem` [Flag_Html, Flag_Hoogle, Flag_LaTeX, Flag_VimHelp]) flags) $ 146 147 throwE "No input file(s)." 147 148 148 149 -- Get packages supplied with --read-interface. … … 247 248 ppLaTeX title pkgStr visibleIfaces odir prologue opt_latex_style 248 249 libDir 249 250 251 when (Flag_VimHelp `elem` flags) $ 252 ppVimHelp visibleIfaces odir 253 250 254 251 255 ------------------------------------------------------------------------------- 252 256 -- * Reading and dumping interface files … … 386 390 when ((Flag_GenIndex `elem` flags || Flag_GenContents `elem` flags) 387 391 && Flag_LaTeX `elem` flags) $ 388 392 throwE "--latex cannot be used with --gen-index or --gen-contents" 393 394 when ((Flag_GenIndex `elem` flags || Flag_GenContents `elem` flags) 395 && Flag_VimHelp `elem` flags) $ 396 throwE "--vimhelp cannot be used with --gen-index or --gen-contents" 389 397 where 390 398 byeVersion = bye $ 391 399 "Haddock version " ++ projectVersion ++ ", (c) Simon Marlow 2006\n" -
src/Haddock/Backends/VimHelp/Decl.hs
-- 1.7.8.6 From 2dc9deed1e9cef639d9f0f328f4348aefc29c295 Mon Sep 17 00:00:00 2001 From: Lars Krueger <lars_e_krueger@gmx.de> Date: Wed, 19 Sep 2012 20:59:32 +0200 Subject: [PATCH 2/6] partial fixes for new api Signed-off-by: Lars Krueger <lars_e_krueger@gmx.de> --- src/Haddock/Backends/VimHelp/Decl.hs | 46 ++++++++++++++------------------ src/Haddock/Backends/VimHelp/Utils.hs | 4 +- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/Haddock/Backends/VimHelp/Decl.hs b/src/Haddock/Backends/VimHelp/Decl.hs index 9b7a69f..504041c 100644
a b 54 54 | Nothing <- tcdTyPats d -> ppTySyn (mbDoc, fnArgsDoc) d 55 55 | Just _ <- tcdTyPats d -> ppTyInst False mbDoc d 56 56 TyClD d@(ClassDecl {}) -> ppClassDecl instances mbDoc subdocs d 57 SigD (TypeSig (L _ n) (L _ t)) -> ppFunSig (mbDoc, fnArgsDoc) nt57 SigD (TypeSig lnames (L _ t)) -> ppFunSig (mbDoc, fnArgsDoc) (map unLoc lnames) t 58 58 ForD d -> ppFor (mbDoc, fnArgsDoc) d 59 59 InstD _ -> [] 60 60 _ -> error "declaration not supported by ppDecl" 61 61 62 62 63 63 -- | Generate markup for function signature. 64 ppFunSig :: DocForDecl DocName -> DocName -> HsType DocName -> Markup 65 ppFunSig doc docname typ = 66 ppTypeOrFunSig typ doc 67 (ppTypeSig docname typ, [ppBinder docname], [dcolon]) 64 ppFunSig :: DocForDecl DocName -> [DocName] -> HsType DocName -> Markup 65 ppFunSig doc docnames typ = 66 concatMap (\docname -> 67 ppTypeOrFunSig typ doc 68 (ppTypeSig docname typ, [ppBinder docname], [dcolon]) 69 ) docnames 68 70 69 71 70 72 ppTypeOrFunSig :: HsType DocName … … 111 113 112 114 113 115 ppFor :: DocForDecl DocName -> ForeignDecl DocName -> Markup 114 ppFor doc (ForeignImport (L _ name) (L _ typ) _ ) = ppFunSig doc nametyp116 ppFor doc (ForeignImport (L _ name) (L _ typ) _ _) = ppFunSig doc [name] typ 115 117 ppFor _ _ = error "ppFor" 116 118 117 119 … … 159 161 ) <+> 160 162 ppTyClBinderWithVars decl <+> 161 163 case tcdKind decl of 162 Just kind -> [dcolon,space] ++ ppKind kind164 Just kind -> [dcolon,space] ++ ppKind (unLoc kind) 163 165 Nothing -> [] 164 166 165 167 … … 278 280 ppContextNoArrow cxt = ppHsContext (map unLoc cxt) 279 281 280 282 281 ppContextNoLocs :: [Hs PredDocName] -> Markup283 ppContextNoLocs :: [HsType DocName] -> Markup 282 284 ppContextNoLocs [] = [] 283 285 ppContextNoLocs cxt = ppHsContext cxt <+> [darrow] 284 286 … … 287 289 ppContext cxt = ppContextNoLocs (map unLoc cxt) 288 290 289 291 290 ppHsContext :: [Hs PredDocName] -> Markup292 ppHsContext :: [HsType DocName] -> Markup 291 293 ppHsContext [] = [] 292 ppHsContext [p] = ppPred p 293 ppHsContext cxt = parenList (intersperse [space] $ map ppPred cxt) 294 295 296 ppPred :: HsPred DocName -> Markup 297 ppPred (HsClassP n ts) = ppAppNameTypes n (map unLoc ts) 298 ppPred (HsEqualP t1 t2) = ppLType t1 <+> [MiNonBreakable "~"] <+> ppLType t2 299 ppPred (HsIParam (IPName n) t) = 300 [MiNonBreakable "?", ppDocName n, space, dcolon] <+> ppLType t 294 ppHsContext [p] = ppType p 295 ppHsContext cxt = parenList (intersperse [space] $ map ppType cxt) 301 296 302 297 303 298 ------------------------------------------------------------------------------- … … 305 300 ------------------------------------------------------------------------------- 306 301 307 302 308 ppClassHdr :: Located [LHs PredDocName]303 ppClassHdr :: Located [LHsType DocName] 309 304 -> DocName 310 305 -> [Located (HsTyVarBndr DocName)] 311 306 -> [Located ([DocName], [DocName])] … … 504 499 -------------------------------------------------------------------------------- 505 500 506 501 507 ppKind :: Outputable a => a-> Markup508 ppKind k = [MiNonBreakable $ showSDoc (ppr k)]502 ppKind :: HsKind DocName -> Markup 503 ppKind k = pprMonoTy pRECTOP k 509 504 510 505 511 506 -- Unpacked args is an implementation detail, so we just show the strictness … … 515 510 ppBang _ = [MiNonBreakable "!" ] 516 511 517 512 518 tupleParens :: Boxity -> [Markup] -> Markup 519 tupleParens Boxed = parenList 520 tupleParens Unboxed = ubxParenList 513 tupleParens :: HsTupleSort -> [Markup] -> Markup 514 tupleParens _ = parenList 521 515 522 516 523 517 -------------------------------------------------------------------------------- … … 577 571 pprMonoTy _ (HsBangTy b ty) = ppBang b ++ ppLParendType ty 578 572 pprMonoTy ctxt_prec (HsFunTy ty1 ty2) = pprFunTy ctxt_prec ty1 ty2 579 573 pprMonoTy _ (HsTupleTy con tys) = tupleParens con (map ppLType tys) 580 pprMonoTy _ (HsPredTy p) = parens (ppPred p)581 pprMonoTy _ (HsNumTy n) = [MiNonBreakable (show n)] -- generics only574 -- pprMonoTy _ (HsPredTy p) = parens (ppPred p) 575 -- pprMonoTy _ (HsNumTy n) = [MiNonBreakable (show n)] -- generics only 582 576 pprMonoTy ctxt_prec (HsParTy ty) = pprMonoLty ctxt_prec ty 583 577 pprMonoTy ctxt_prec (HsDocTy ty _) = pprMonoLty ctxt_prec ty 584 578 pprMonoTy _ (HsSpliceTy {}) = error "pprMonoTy HsSpliceTy" -
src/Haddock/Backends/VimHelp/Utils.hs
diff --git a/src/Haddock/Backends/VimHelp/Utils.hs b/src/Haddock/Backends/VimHelp/Utils.hs index 9dd0bce..c4be0d8 100644
a b 229 229 ppRenderDoc (DocCodeBlock d) = 230 230 beginCodeBlock ++ ppRenderDoc d ++ endCodeBlock 231 231 232 -- Show the first identifier only 233 ppRenderDoc (DocIdentifier ds) = [ppDocName $ head ds, MiSpaceBeforeLetter]232 ppRenderDoc (DocIdentifier d) = [ppDocName d, MiSpaceBeforeLetter] 233 ppRenderDoc (DocIdentifierUnchecked (mn,on)) = [MiNonBreakable $ moduleNameString mn ++ "." ++ occNameString on, MiSpaceBeforeLetter] 234 234 235 235 ppRenderDoc (DocUnorderedList ds) = 236 236 ppList (ppListItemDoc False [MiNonBreakable "-"]) ds -
src/Haddock/Backends/VimHelp/Utils.hs
-- 1.7.8.6 From 7bf7ff77738b8c69893e85a8bd86ef2a4693916d Mon Sep 17 00:00:00 2001 From: Lars Krueger <lars_e_krueger@gmx.de> Date: Fri, 28 Sep 2012 20:44:41 +0200 Subject: [PATCH 3/6] added tilde function Signed-off-by: Lars Krueger <lars_e_krueger@gmx.de> --- src/Haddock/Backends/VimHelp/Utils.hs | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/src/Haddock/Backends/VimHelp/Utils.hs b/src/Haddock/Backends/VimHelp/Utils.hs index c4be0d8..4a01337 100644
a b 15 15 , ppPlainName 16 16 , parenList 17 17 , dcolon 18 , tilde 18 19 , parens 19 20 , brackets 20 21 , pabrackets … … 114 115 dcolon = MiNonBreakable "::" 115 116 116 117 118 tilde :: MarkupItem 119 tilde = MiNonBreakable "~" 120 121 117 122 dot :: MarkupItem 118 123 dot = MiNonBreakable "." 119 124 -
src/Haddock/Backends/VimHelp/Decl.hs
-- 1.7.8.6 From 5016d07272970c25cc29566a5a314f047c62899f Mon Sep 17 00:00:00 2001 From: Lars Krueger <lars_e_krueger@gmx.de> Date: Fri, 28 Sep 2012 20:45:18 +0200 Subject: [PATCH 4/6] compiles now with 7.4.2 Signed-off-by: Lars Krueger <lars_e_krueger@gmx.de> --- src/Haddock/Backends/VimHelp/Decl.hs | 32 ++++++++++++++++++++++---------- 1 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/Haddock/Backends/VimHelp/Decl.hs b/src/Haddock/Backends/VimHelp/Decl.hs index 504041c..ab6cb32 100644
a b 24 24 import Haddock.GhcUtils 25 25 import Haddock.Types 26 26 27 import BasicTypes ( IPName(..), Boxity(..) )28 27 import GHC 29 28 import Name 30 import Outputable ( ppr, showSDoc, Outputable )29 import BasicTypes ( ipNameName ) 31 30 32 31 import Control.Monad ( join ) 33 32 import qualified Data.Map as Map … … 330 329 -> TyClDecl DocName 331 330 -> Markup 332 331 ppClassDecl instances mbDoc subdocs 333 (ClassDecl lctxt lname ltyvars lfds lsigs _ ats _ ) =332 (ClassDecl lctxt lname ltyvars lfds lsigs _ ats _ _) = 334 333 classheader 335 334 ++ maybeDocSection mbDoc 336 335 ++ atBit … … 347 346 | at <- ats 348 347 , let doc = lookupAnySubdoc (tcdName $ unL at) subdocs ] 349 348 350 methodBit = subMethods [ ppFunSig doc n typ 351 | L _ (TypeSig (L _ n) (L _ typ)) <- lsigs 352 , let doc = lookupAnySubdoc n subdocs ] 349 methodBit = subMethods [ ppFunSig doc names typ 350 | L _ (TypeSig lnames (L _ typ)) <- lsigs 351 , let doc = lookupAnySubdoc (head names) subdocs 352 names = map unLoc lnames] 353 353 354 354 instancesBit = ppInstances instances 355 355 … … 571 571 pprMonoTy _ (HsBangTy b ty) = ppBang b ++ ppLParendType ty 572 572 pprMonoTy ctxt_prec (HsFunTy ty1 ty2) = pprFunTy ctxt_prec ty1 ty2 573 573 pprMonoTy _ (HsTupleTy con tys) = tupleParens con (map ppLType tys) 574 -- pprMonoTy _ (HsPredTy p) = parens (ppPred p)575 -- pprMonoTy _ (HsNumTy n) = [MiNonBreakable (show n)] -- generics only576 574 pprMonoTy ctxt_prec (HsParTy ty) = pprMonoLty ctxt_prec ty 577 575 pprMonoTy ctxt_prec (HsDocTy ty _) = pprMonoLty ctxt_prec ty 578 576 pprMonoTy _ (HsSpliceTy {}) = error "pprMonoTy HsSpliceTy" 577 #if __GLASGOW_HASKELL__ == 612 578 pprMonoTy _ (HsSpliceTyOut {}) = error "pprMonoTy HsQuasiQuoteTy" 579 #else 579 580 pprMonoTy _ (HsQuasiQuoteTy {}) = error "pprMonoTy HsQuasiQuoteTy" 581 #endif 580 582 pprMonoTy _ (HsCoreTy {}) = error "pprMonoTy HsCoreTy" 581 583 pprMonoTy _ (HsRecTy {}) = error "pprMonoTy HsRecTy" 584 pprMonoTy _ (HsExplicitListTy _ tys) = quote $ brackets $ intercalate [comma] $ map ppLType tys 585 pprMonoTy _ (HsExplicitTupleTy _ tys) = quote $ parenList $ map ppLType tys 586 pprMonoTy _ (HsWrapTy {}) = error "ppr_mono_ty HsWrapTy" 587 588 pprMonoTy ctxt_prec (HsEqTy ty1 ty2) 589 = maybeParen ctxt_prec pRECOP $ 590 pprMonoLty pRECOP ty1 <+> [tilde] <+> pprMonoLty pRECOP ty2 582 591 583 592 pprMonoTy ctxt_prec (HsForAllTy expl tvs ctxt ty) = 584 593 maybeParen ctxt_prec pRECFUN $ … … 588 597 [ppDocName name, MiSpaceBeforeLetter] 589 598 590 599 pprMonoTy _ (HsKindSig ty kind) = 591 parens (pprMonoLty pRECTOP ty <+> [dcolon] <+> ppKind kind)600 parens (pprMonoLty pRECTOP ty <+> [dcolon] <+> (ppKind $ unLoc kind)) 592 601 593 602 pprMonoTy _ (HsPArrTy ty) = 594 603 pabrackets (pprMonoLty pRECTOP ty) 595 604 605 pprMonoTy _ (HsIParamTy n ty) = 606 brackets $ [ppDocName (ipNameName n)] <+> [dcolon] <+> pprMonoLty pRECTOP ty 607 596 608 pprMonoTy ctxt_prec (HsAppTy fun_ty arg_ty) = 597 609 maybeParen ctxt_prec pRECCON $ 598 610 pprMonoLty pRECFUN fun_ty ++ pprMonoLty pRECCON arg_ty 599 611 600 pprMonoTy ctxt_prec (HsOpTy ty1 opty2) =612 pprMonoTy ctxt_prec (HsOpTy ty1 (_,op) ty2) = 601 613 maybeParen ctxt_prec pRECFUN $ 602 614 pprMonoLty pRECOP ty1 <+> ppr_op <+> pprMonoLty pRECOP ty2 603 615 where -
src/Main.hs
-- 1.7.8.6 From 7bdb2ba16065e2defc0b70edcdd545a548aa0574 Mon Sep 17 00:00:00 2001 From: Lars Krueger <lars_e_krueger@gmx.de> Date: Fri, 28 Sep 2012 22:10:41 +0200 Subject: [PATCH 5/6] read themes only in html related modes Signed-off-by: Lars Krueger <lars_e_krueger@gmx.de> --- src/Main.hs | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 724b78f..ef5b921 100644
a b 218 218 219 219 libDir <- getHaddockLibDir flags 220 220 prologue <- getPrologue flags 221 themes <- getThemes libDir flags >>= either bye return222 221 223 222 when (Flag_GenIndex `elem` flags) $ do 223 themes <- getThemes libDir flags >>= either bye return 224 224 ppHtmlIndex odir title pkgStr 225 225 themes opt_contents_url sourceUrls' opt_wiki_urls 226 226 allVisibleIfaces pretty 227 227 copyHtmlBits odir libDir themes 228 228 229 229 when (Flag_GenContents `elem` flags) $ do 230 themes <- getThemes libDir flags >>= either bye return 230 231 ppHtmlContents odir title pkgStr 231 232 themes opt_index_url sourceUrls' opt_wiki_urls 232 233 allVisibleIfaces True prologue pretty opt_qualification 233 234 copyHtmlBits odir libDir themes 234 235 235 236 when (Flag_Html `elem` flags) $ do 237 themes <- getThemes libDir flags >>= either bye return 236 238 ppHtml title pkgStr visibleIfaces odir 237 239 prologue 238 240 themes sourceUrls' opt_wiki_urls -
haddock-rebuild-vimhelp.sh
-- 1.7.8.6 From d82e21aa28a6841dd221baa63044ca19ff117a4c Mon Sep 17 00:00:00 2001 From: Lars Krueger <lars_e_krueger@gmx.de> Date: Fri, 28 Sep 2012 22:25:49 +0200 Subject: [PATCH 6/6] More robust calls to haddock Signed-off-by: Lars Krueger <lars_e_krueger@gmx.de> --- haddock-rebuild-vimhelp.sh | 59 +++++++++++++++++++++++++++++--------------- 1 files changed, 39 insertions(+), 20 deletions(-) diff --git a/haddock-rebuild-vimhelp.sh b/haddock-rebuild-vimhelp.sh index c0c0bc5..3bd3680 100755
a b 3 3 # Script to rebuild the vimhelp from the list of installed packages 4 4 5 5 workDir="$PWD/temp" 6 HADDOCK="$PWD/haddock/dist/build/haddock/haddock"7 6 7 # try to detect haddock 8 HADDOCK= 9 10 try_haddock() { 11 [ "x$HADDOCK" == "x" ] || return 0 12 HADDOCK=$1 13 command -v $HADDOCK > /dev/null 2>&1 14 [ $? -ne 0 ] || return 0 15 HADDOCK= 16 } 17 18 try_haddock "$PWD/haddock/dist/build/haddock/haddock" 19 try_haddock "$PWD/dist/build/haddock/haddock" 20 try_haddock "haddock" 21 22 if [ "x$HADDOCK" == "x" ]; then 23 echo "haddock not found" 24 fi 8 25 9 26 # set the language to US english, UTF-8, to handle unicode correctly 10 27 export LANG=en_US.UTF-8 … … 33 50 34 51 # Check for hidden packages 35 52 isExposed=`ghc-pkg field $latestPkg exposed | cut -d ' ' -f 2 | head -1` 36 # if [ $isExposed == 'True' ]; then37 echo -n "Checking for package $latestPkg ... "38 53 39 # Download the package using cabal 40 cabal fetch --no-dependencies $latestPkg > /dev/null 2>&1 54 # Download the package using cabal 55 echo -n "Checking for package $latestPkg ... " 56 cabal fetch --no-dependencies $latestPkg > /dev/null 2>&1 41 57 42 if [ $? -eq 0 ] ; then 43 workList="$workList $pkg" 44 echo "OK" 45 else 46 echo "ignored" 47 fi 48 # else 49 # echo "Package $pkg is hidden" 50 # fi 58 if [ $? -eq 0 ] ; then 59 workList="$workList $pkg" 60 echo "OK" 61 else 62 echo "ignored" 63 fi 51 64 done 52 65 53 66 # workList='digest ghc-paths ghc-paths base64-bytestring extensible-exceptions zip-archive transformers array blaze-builder citeproc-hs syb utf8-string containers blaze-html json highlighting-kate hpc binary zlib texmath bytestring text tagsoup regex-compat regex-base regex-pcre-builtin regex-posix old-locale random old-time html pretty haskell-src process directory haskell98 deepseq temporary filepath time HUnit xml pandoc-types pandoc Cabal hscolour mtl GLUT stm OpenGL network QuickCheck unix template-haskell haddock parallel parsec base hs-bibutils fgl xhtml xhtml cgi HTTP' … … 70 83 ( 71 84 cd $workDir/src/$versionPkg 72 85 cabal configure 73 cabal haddock --with-haddock=$HADDOCK --haddock-options="--vimhelp" 86 cabal haddock --hoogle --with-haddock=$HADDOCK --haddock-options="--vimhelp" 87 if [ $? -ne 0 ] ; then 88 echo "cabal haddock failed. Wrong haddock version?" 89 exit 1 90 fi 74 91 ) 92 if [ $? -eq 0 ] ; then 75 93 # Reading the modules and copying them 76 modDocDir="$workDir/src/$versionPkg/dist/doc/html/$pkg" 77 modList="$modDocDir/vimhelp_modules.txt" 78 for mod in `cat $modList`; do 79 cp $modDocDir/${mod}.txt $docDir/haddock_${mod}.txt 80 done 94 modDocDir="$workDir/src/$versionPkg/dist/doc/html/$pkg" 95 modList="$modDocDir/vimhelp_modules.txt" 96 for mod in `cat $modList`; do 97 cp $modDocDir/${mod}.txt $docDir/haddock_${mod}.txt 98 done 99 fi 81 100 done 82 101 83 102 # Rebuild the helptags
