Ormolu.Utils

fourmolu-0.17.0.0: A formatter for Haskell source code

Safe Haskell | None
Language | GHC2021

Ormolu.Utils

Description

Random utilities used by the code.

Synopsis

- data RelativePos
  - = SinglePos
  - | FirstPos
  - | MiddlePos
  - | LastPos
- attachRelativePos :: [a] -> [(RelativePos, a)]
- combineSrcSpans' :: NonEmpty SrcSpan -> SrcSpan
- notImplemented :: String -> a
- showOutputable :: Outputable o => o -> String
- splitDocString :: Bool -> HsDocString -> [Text]
- incSpanLine :: Int -> SrcSpan -> SrcSpan
- separatedByBlank :: (a -> SrcSpan) -> a -> a -> Bool
- separatedByBlankNE :: (a -> SrcSpan) -> NonEmpty a -> NonEmpty a -> Bool
- onTheSameLine :: SrcSpan -> SrcSpan -> Bool
- groupBy' :: (a -> a -> Bool) -> [a] -> [NonEmpty a]
- matchAddEpAnn :: AnnKeywordId -> AddEpAnn -> Maybe EpaLocation
- textToStringBuffer :: Text -> StringBuffer
- ghcModuleNameToCabal :: ModuleName -> ModuleName

# Documentation

data RelativePos #

Relative positions in a list.

Constructors

SinglePos |
FirstPos |
MiddlePos |
LastPos |

#### Instances

Instances details

Show RelativePos # |
Instance details Defined in Ormolu.Utils Methods showsPrec :: Int -> RelativePos -> ShowS # show :: RelativePos -> String # showList :: [RelativePos] -> ShowS #
Eq RelativePos # |
Instance details Defined in Ormolu.Utils Methods (==) :: RelativePos -> RelativePos -> Bool # (/=) :: RelativePos -> RelativePos -> Bool #

attachRelativePos :: [a] -> [(RelativePos, a)] #

Attach `RelativePos`es to elements of a given list.

combineSrcSpans' :: NonEmpty SrcSpan -> SrcSpan #

Combine all source spans from the given list.

notImplemented :: String -> a #

Placeholder for things that are not yet implemented.

showOutputable :: Outputable o => o -> String #

Pretty-print an `Outputable` thing.

splitDocString :: Bool -> HsDocString -> [Text] #

Split and normalize a doc string. The result is a list of lines that make up the comment.

incSpanLine :: Int -> SrcSpan -> SrcSpan #

Increment line number in a `SrcSpan`.

separatedByBlank :: (a -> SrcSpan) -> a -> a -> Bool #

Do two declarations have a blank between them?

separatedByBlankNE :: (a -> SrcSpan) -> NonEmpty a -> NonEmpty a -> Bool #

Do two declaration groups have a blank between them?

onTheSameLine :: SrcSpan -> SrcSpan -> Bool #

Return `True` if one span ends on the same line the second one starts.

groupBy' :: (a -> a -> Bool) -> [a] -> [NonEmpty a] #

A generalisation of `groupBy` to functions which aren't equivalences - a group ends when comparison fails with the previous element, rather than the first of the group.

matchAddEpAnn :: AnnKeywordId -> AddEpAnn -> Maybe EpaLocation #

Check whether the given `AnnKeywordId` or its Unicode variant is in an `AddEpAnn`, and return the `EpaLocation` if so.

textToStringBuffer :: Text -> StringBuffer #

Convert `Text` to a `StringBuffer` by making a copy.

ghcModuleNameToCabal :: ModuleName -> ModuleName #

Convert GHC's `ModuleName` into the one used by Cabal.