ghc-lib-parser-9.14.1.20251220: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Hs.DocString

Description

An exactprintable structure for docstrings

Synopsis

- type LHsDocString = Located HsDocString
- data HsDocString
  - = MultiLineDocString !HsDocStringDecorator !(NonEmpty LHsDocStringChunk)
  - | NestedDocString !HsDocStringDecorator LHsDocStringChunk
  - | GeneratedDocString HsDocStringChunk
- data HsDocStringDecorator
  - = HsDocStringNext
  - | HsDocStringPrevious
  - | HsDocStringNamed !String
  - | HsDocStringGroup !Int
- newtype HsDocStringChunk = HsDocStringChunk ByteString
- type LHsDocStringChunk = Located HsDocStringChunk
- isEmptyDocString :: HsDocString -> Bool
- unpackHDSC :: HsDocStringChunk -> String
- mkHsDocStringChunk :: String -> HsDocStringChunk
- mkHsDocStringChunkUtf8ByteString :: ByteString -> HsDocStringChunk
- pprHsDocString :: HsDocString -> SDoc
- pprHsDocStrings :: [HsDocString] -> SDoc
- mkGeneratedHsDocString :: String -> HsDocString
- docStringChunks :: HsDocString -> [LHsDocStringChunk]
- renderHsDocString :: HsDocString -> String
- renderHsDocStrings :: [HsDocString] -> String
- exactPrintHsDocString :: HsDocString -> String
- pprWithDocString :: HsDocString -> SDoc -> SDoc
- printDecorator :: HsDocStringDecorator -> String

# Documentation

type LHsDocString = Located HsDocString #

data HsDocString #

Haskell Documentation String

Rich structure to support exact printing The location around each chunk doesn't include the decorators

Constructors

MultiLineDocString !HsDocStringDecorator !(NonEmpty LHsDocStringChunk) | The first chunk is preceded by "-- decorator" and each following chunk is preceded by "--" Example: -- | This is a docstring for `foo`. It is the line with the decorator '|' and is always included -- This continues that docstring and is the second element in the NonEmpty list foo :: a -> a
NestedDocString !HsDocStringDecorator LHsDocStringChunk | The docstring is preceded by "{-decorator" and followed by "-}" The chunk contains balanced pairs of '{-' and '-}'
GeneratedDocString HsDocStringChunk | A docstring generated either internally or via TH Pretty printed with the '-- |' decorator This is because it may contain unbalanced pairs of '{-' and '-}' and not form a valid `NestedDocString`

#### Instances

Instances details

NFData HsDocString # |
Instance details Defined in GHC.Hs.DocString Methods rnf :: HsDocString -> () #
Data HsDocString # |
Instance details Defined in GHC.Hs.DocString Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> HsDocString -> c HsDocString # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c HsDocString # toConstr :: HsDocString -> Constr # dataTypeOf :: HsDocString -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c HsDocString) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HsDocString) # gmapT :: (forall b. Data b => b -> b) -> HsDocString -> HsDocString # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> HsDocString -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> HsDocString -> r # gmapQ :: (forall d. Data d => d -> u) -> HsDocString -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> HsDocString -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> HsDocString -> m HsDocString # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> HsDocString -> m HsDocString # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> HsDocString -> m HsDocString #
Show HsDocString # |
Instance details Defined in GHC.Hs.DocString Methods showsPrec :: Int -> HsDocString -> ShowS # show :: HsDocString -> String # showList :: [HsDocString] -> ShowS #
Binary HsDocString # |
Instance details Defined in GHC.Hs.DocString Methods put_ :: WriteBinHandle -> HsDocString -> IO () # put :: WriteBinHandle -> HsDocString -> IO (Bin HsDocString) # get :: ReadBinHandle -> IO HsDocString #
Outputable HsDocString # |
Instance details Defined in GHC.Hs.DocString Methods ppr :: HsDocString -> SDoc #
Eq HsDocString # |
Instance details Defined in GHC.Hs.DocString Methods (==) :: HsDocString -> HsDocString -> Bool # (/=) :: HsDocString -> HsDocString -> Bool #

data HsDocStringDecorator #

Constructors

HsDocStringNext | '|' is the decorator
HsDocStringPrevious | `^` is the decorator
HsDocStringNamed !String | '$string' is the decorator
HsDocStringGroup !Int | The decorator is the given number of `*`s

#### Instances

Instances details

NFData HsDocStringDecorator # |
Instance details Defined in GHC.Hs.DocString Methods rnf :: HsDocStringDecorator -> () #
Data HsDocStringDecorator # |
Instance details Defined in GHC.Hs.DocString Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> HsDocStringDecorator -> c HsDocStringDecorator # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c HsDocStringDecorator # toConstr :: HsDocStringDecorator -> Constr # dataTypeOf :: HsDocStringDecorator -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c HsDocStringDecorator) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HsDocStringDecorator) # gmapT :: (forall b. Data b => b -> b) -> HsDocStringDecorator -> HsDocStringDecorator # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> HsDocStringDecorator -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> HsDocStringDecorator -> r # gmapQ :: (forall d. Data d => d -> u) -> HsDocStringDecorator -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> HsDocStringDecorator -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> HsDocStringDecorator -> m HsDocStringDecorator # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> HsDocStringDecorator -> m HsDocStringDecorator # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> HsDocStringDecorator -> m HsDocStringDecorator #
Show HsDocStringDecorator # |
Instance details Defined in GHC.Hs.DocString Methods showsPrec :: Int -> HsDocStringDecorator -> ShowS # show :: HsDocStringDecorator -> String # showList :: [HsDocStringDecorator] -> ShowS #
Binary HsDocStringDecorator # |
Instance details Defined in GHC.Hs.DocString Methods put_ :: WriteBinHandle -> HsDocStringDecorator -> IO () # put :: WriteBinHandle -> HsDocStringDecorator -> IO (Bin HsDocStringDecorator) # get :: ReadBinHandle -> IO HsDocStringDecorator #
Outputable HsDocStringDecorator # |
Instance details Defined in GHC.Hs.DocString Methods ppr :: HsDocStringDecorator -> SDoc #
Eq HsDocStringDecorator # |
Instance details Defined in GHC.Hs.DocString Methods (==) :: HsDocStringDecorator -> HsDocStringDecorator -> Bool # (/=) :: HsDocStringDecorator -> HsDocStringDecorator -> Bool #
Ord HsDocStringDecorator # |
Instance details Defined in GHC.Hs.DocString Methods compare :: HsDocStringDecorator -> HsDocStringDecorator -> Ordering # (<) :: HsDocStringDecorator -> HsDocStringDecorator -> Bool # (<=) :: HsDocStringDecorator -> HsDocStringDecorator -> Bool # (>) :: HsDocStringDecorator -> HsDocStringDecorator -> Bool # (>=) :: HsDocStringDecorator -> HsDocStringDecorator -> Bool # max :: HsDocStringDecorator -> HsDocStringDecorator -> HsDocStringDecorator # min :: HsDocStringDecorator -> HsDocStringDecorator -> HsDocStringDecorator #

newtype HsDocStringChunk #

A contiguous chunk of documentation

Constructors

HsDocStringChunk ByteString |

#### Instances

Instances details

NFData HsDocStringChunk # |
Instance details Defined in GHC.Hs.DocString Methods rnf :: HsDocStringChunk -> () #
Data HsDocStringChunk # |
Instance details Defined in GHC.Hs.DocString Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> HsDocStringChunk -> c HsDocStringChunk # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c HsDocStringChunk # toConstr :: HsDocStringChunk -> Constr # dataTypeOf :: HsDocStringChunk -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c HsDocStringChunk) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HsDocStringChunk) # gmapT :: (forall b. Data b => b -> b) -> HsDocStringChunk -> HsDocStringChunk # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> HsDocStringChunk -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> HsDocStringChunk -> r # gmapQ :: (forall d. Data d => d -> u) -> HsDocStringChunk -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> HsDocStringChunk -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> HsDocStringChunk -> m HsDocStringChunk # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> HsDocStringChunk -> m HsDocStringChunk # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> HsDocStringChunk -> m HsDocStringChunk #
Show HsDocStringChunk # |
Instance details Defined in GHC.Hs.DocString Methods showsPrec :: Int -> HsDocStringChunk -> ShowS # show :: HsDocStringChunk -> String # showList :: [HsDocStringChunk] -> ShowS #
Binary HsDocStringChunk # |
Instance details Defined in GHC.Hs.DocString Methods put_ :: WriteBinHandle -> HsDocStringChunk -> IO () # put :: WriteBinHandle -> HsDocStringChunk -> IO (Bin HsDocStringChunk) # get :: ReadBinHandle -> IO HsDocStringChunk #
Outputable HsDocStringChunk # |
Instance details Defined in GHC.Hs.DocString Methods ppr :: HsDocStringChunk -> SDoc #
Eq HsDocStringChunk # |
Instance details Defined in GHC.Hs.DocString Methods (==) :: HsDocStringChunk -> HsDocStringChunk -> Bool # (/=) :: HsDocStringChunk -> HsDocStringChunk -> Bool #
Ord HsDocStringChunk # |
Instance details Defined in GHC.Hs.DocString Methods compare :: HsDocStringChunk -> HsDocStringChunk -> Ordering # (<) :: HsDocStringChunk -> HsDocStringChunk -> Bool # (<=) :: HsDocStringChunk -> HsDocStringChunk -> Bool # (>) :: HsDocStringChunk -> HsDocStringChunk -> Bool # (>=) :: HsDocStringChunk -> HsDocStringChunk -> Bool # max :: HsDocStringChunk -> HsDocStringChunk -> HsDocStringChunk # min :: HsDocStringChunk -> HsDocStringChunk -> HsDocStringChunk #

type LHsDocStringChunk = Located HsDocStringChunk #

isEmptyDocString :: HsDocString -> Bool #

unpackHDSC :: HsDocStringChunk -> String #

mkHsDocStringChunk :: String -> HsDocStringChunk #

mkHsDocStringChunkUtf8ByteString :: ByteString -> HsDocStringChunk #

Create a `HsDocString` from a UTF8-encoded `ByteString`.

pprHsDocString :: HsDocString -> SDoc #

Pretty print with decorators, exactly as the user wrote it

pprHsDocStrings :: [HsDocString] -> SDoc #

mkGeneratedHsDocString :: String -> HsDocString #

docStringChunks :: HsDocString -> [LHsDocStringChunk] #

renderHsDocString :: HsDocString -> String #

Just get the docstring, without any decorators

renderHsDocStrings :: [HsDocString] -> String #

Just get the docstring, without any decorators Separates docstrings using "nn", which is how haddock likes to render them

exactPrintHsDocString :: HsDocString -> String #

Pretty print with decorators, exactly as the user wrote it

pprWithDocString :: HsDocString -> SDoc -> SDoc #

Annotate a pretty printed thing with its doc The docstring comes after if is `HsDocStringPrevious` Otherwise it comes before. Note - we convert MultiLineDocString HsDocStringPrevious to HsDocStringNext because we can't control if something else will be pretty printed on the same line

printDecorator :: HsDocStringDecorator -> String #