{-# LANGUAGE CPP #-}{-# LANGUAGE DeriveDataTypeable #-}{-# LANGUAGE GeneralizedNewtypeDeriving #-}moduleHsDoc(HsDocString ,LHsDocString ,mkHsDocString ,mkHsDocStringUtf8ByteString ,unpackHDS ,hsDocStringToByteString ,ppr_mbDoc ,appendDocs ,concatDocs ,DeclDocMap (..),emptyDeclDocMap ,ArgDocMap (..),emptyArgDocMap )where#include "HsVersions.h"
importGhcPrelude importBinary importEncoding importFastFunctions importName importOutputable importSrcLoc importData.ByteString(ByteString)importqualifiedData.ByteStringasBSimportqualifiedData.ByteString.Char8asC8importqualifiedData.ByteString.InternalasBSimportData.DataimportData.Map(Map)importqualifiedData.MapasMapimportData.MaybeimportForeign-- | Haskell Documentation String---- Internally this is a UTF8-Encoded 'ByteString'.newtypeHsDocString =HsDocString ByteString-- There are at least two plausible Semigroup instances for this type:---- 1. Simple string concatenation.-- 2. Concatenation as documentation paragraphs with newlines in between.---- To avoid confusion, we pass on defining an instance at all.deriving(Eq,Show,Data)-- | Located Haskell Documentation StringtypeLHsDocString =Located HsDocString instanceBinary HsDocString whereput_ bh (HsDocString bs )=put_ bh bs get bh =HsDocString <$>get bh instanceOutputable HsDocString whereppr =doubleQuotes .text .unpackHDS mkHsDocString::String->HsDocString mkHsDocString s =inlinePerformIO $doletlen =utf8EncodedLength s buf <-mallocForeignPtrByteslen withForeignPtrbuf $\ptr ->doutf8EncodeString ptr s pure(HsDocString (BS.fromForeignPtrbuf 0len ))-- | Create a 'HsDocString' from a UTF8-encoded 'ByteString'.mkHsDocStringUtf8ByteString::ByteString->HsDocString mkHsDocStringUtf8ByteString =HsDocString unpackHDS::HsDocString ->StringunpackHDS =utf8DecodeByteString .hsDocStringToByteString -- | Return the contents of a 'HsDocString' as a UTF8-encoded 'ByteString'.hsDocStringToByteString::HsDocString ->ByteStringhsDocStringToByteString (HsDocString bs )=bs ppr_mbDoc::MaybeLHsDocString ->SDoc ppr_mbDoc (Justdoc )=ppr doc ppr_mbDocNothing=empty -- | Join two docstrings.---- Non-empty docstrings are joined with two newlines in between,-- resulting in separate paragraphs.appendDocs::HsDocString ->HsDocString ->HsDocString appendDocs x y =fromMaybe(HsDocString BS.empty)(concatDocs [x ,y ])-- | Concat docstrings with two newlines in between.---- Empty docstrings are skipped.---- If all inputs are empty, 'Nothing' is returned.concatDocs::[HsDocString ]->MaybeHsDocString concatDocs xs =ifBS.nullb thenNothingelseJust(HsDocString b )whereb =BS.intercalate(C8.pack"\n\n").filter(not.BS.null).maphsDocStringToByteString $xs -- | Docs for declarations: functions, data types, instances, methods etc.newtypeDeclDocMap =DeclDocMap (MapName HsDocString )instanceBinary DeclDocMap whereput_ bh (DeclDocMap m )=put_ bh (Map.toListm )-- We can't rely on a deterministic ordering of the `Name`s here.-- See the comments on `Name`'s `Ord` instance for context.get bh =DeclDocMap .Map.fromList<$>get bh instanceOutputable DeclDocMap whereppr (DeclDocMap m )=vcat (mappprPair (Map.toAscListm ))wherepprPair (name ,doc )=ppr name Outputable.<> colon $$ nest 2(ppr doc )emptyDeclDocMap::DeclDocMap emptyDeclDocMap =DeclDocMap Map.empty-- | Docs for arguments. E.g. function arguments, method arguments.newtypeArgDocMap =ArgDocMap (MapName (MapIntHsDocString ))instanceBinary ArgDocMap whereput_ bh (ArgDocMap m )=put_ bh (Map.toList(Map.toAscList<$>m ))-- We can't rely on a deterministic ordering of the `Name`s here.-- See the comments on `Name`'s `Ord` instance for context.get bh =ArgDocMap .fmapMap.fromDistinctAscList.Map.fromList<$>get bh instanceOutputable ArgDocMap whereppr (ArgDocMap m )=vcat (mappprPair (Map.toAscListm ))wherepprPair (name ,int_map )=ppr name Outputable.<> colon $$ nest 2(pprIntMap int_map )pprIntMap im =vcat (mappprIPair (Map.toAscListim ))pprIPair (i ,doc )=ppr i Outputable.<> colon $$ nest 2(ppr doc )emptyArgDocMap::ArgDocMap emptyArgDocMap =ArgDocMap Map.empty

AltStyle によって変換されたページ (->オリジナル) /