-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A formatter for Haskell source code
--   
--   A formatter for Haskell source code.
@package ormolu
@version 0.1.2.0


-- | Configuration options used by the tool.
module Ormolu.Config

-- | Ormolu configuration.
data Config region
Config :: ![DynOption] -> !Bool -> !Bool -> !Bool -> !region -> Config region

-- | Dynamic options to pass to GHC parser
[cfgDynOptions] :: Config region -> ![DynOption]

-- | Do formatting faster but without automatic detection of defects
[cfgUnsafe] :: Config region -> !Bool

-- | Output information useful for debugging
[cfgDebug] :: Config region -> !Bool

-- | Checks if re-formatting the result is idempotent
[cfgCheckIdempotence] :: Config region -> !Bool

-- | Region selection
[cfgRegion] :: Config region -> !region

-- | Region selection as the combination of start and end line numbers.
data RegionIndices
RegionIndices :: !Maybe Int -> !Maybe Int -> RegionIndices

-- | Start line of the region to format
[regionStartLine] :: RegionIndices -> !Maybe Int

-- | End line of the region to format
[regionEndLine] :: RegionIndices -> !Maybe Int

-- | Region selection as the length of the literal prefix and the literal
--   suffix.
data RegionDeltas
RegionDeltas :: !Int -> !Int -> RegionDeltas

-- | Prefix length in number of lines
[regionPrefixLength] :: RegionDeltas -> !Int

-- | Suffix length in number of lines
[regionSuffixLength] :: RegionDeltas -> !Int

-- | Default <tt><a>Config</a> <a>RegionIndices</a></tt>.
defaultConfig :: Config RegionIndices

-- | Convert <a>RegionIndices</a> into <a>RegionDeltas</a>.
regionIndicesToDeltas :: Int -> RegionIndices -> RegionDeltas

-- | A wrapper for dynamic options.
newtype DynOption
DynOption :: String -> DynOption
[unDynOption] :: DynOption -> String

-- | Convert <a>DynOption</a> to <tt><a>Located</a> <a>String</a></tt>.
dynOptionToLocatedStr :: DynOption -> Located String
instance GHC.Base.Functor Ormolu.Config.Config
instance GHC.Show.Show region => GHC.Show.Show (Ormolu.Config.Config region)
instance GHC.Classes.Eq region => GHC.Classes.Eq (Ormolu.Config.Config region)
instance GHC.Show.Show Ormolu.Config.DynOption
instance GHC.Classes.Ord Ormolu.Config.DynOption
instance GHC.Classes.Eq Ormolu.Config.DynOption
instance GHC.Show.Show Ormolu.Config.RegionDeltas
instance GHC.Classes.Eq Ormolu.Config.RegionDeltas
instance GHC.Show.Show Ormolu.Config.RegionIndices
instance GHC.Classes.Eq Ormolu.Config.RegionIndices


-- | Ormolu-specific representation of GHC annotations.
module Ormolu.Parser.Anns

-- | Ormolu-specific representation of GHC annotations.
newtype Anns
Anns :: Map RealSrcSpan [AnnKeywordId] -> Anns

-- | Empty <a>Anns</a>.
emptyAnns :: Anns

-- | Create <a>Anns</a> from <a>PState</a>.
mkAnns :: PState -> Anns

-- | Lookup <a>AnnKeywordId</a>s corresponding to a given <a>SrcSpan</a>.
lookupAnns :: SrcSpan -> Anns -> [AnnKeywordId]
instance GHC.Classes.Eq Ormolu.Parser.Anns.Anns


-- | A module for parsing of pragmas from comments.
module Ormolu.Parser.Pragma

-- | Ormolu's representation of pragmas.
data Pragma

-- | Language pragma
PragmaLanguage :: [String] -> Pragma

-- | GHC options pragma
PragmaOptionsGHC :: String -> Pragma

-- | Haddock options pragma
PragmaOptionsHaddock :: String -> Pragma

-- | Extract a pragma from a comment if possible, or return <a>Nothing</a>
--   otherwise.
parsePragma :: String -> Maybe Pragma
instance GHC.Classes.Eq Ormolu.Parser.Pragma.Pragma
instance GHC.Show.Show Ormolu.Parser.Pragma.Pragma


-- | A module for dealing with shebangs.
module Ormolu.Parser.Shebang

-- | A wrapper for a shebang.
newtype Shebang
Shebang :: Located String -> Shebang

-- | Extract shebangs from the beginning of a comment stream.
extractShebangs :: [Located String] -> ([Shebang], [Located String])

-- | Return <a>True</a> if given <a>String</a> is a shebang.
isShebang :: String -> Bool
instance Data.Data.Data Ormolu.Parser.Shebang.Shebang
instance GHC.Classes.Eq Ormolu.Parser.Shebang.Shebang


-- | Build span stream from AST.
module Ormolu.Printer.SpanStream

-- | A stream of <a>RealSrcSpan</a>s in ascending order. This allows us to
--   tell e.g. whether there is another "located" element of AST between
--   current element and comment we're considering for printing.
newtype SpanStream
SpanStream :: [RealSrcSpan] -> SpanStream

-- | Create <a>SpanStream</a> from a data structure containing "located"
--   elements.
mkSpanStream :: Data a => a -> SpanStream
instance GHC.Base.Monoid Ormolu.Printer.SpanStream.SpanStream
instance GHC.Base.Semigroup Ormolu.Printer.SpanStream.SpanStream
instance Data.Data.Data Ormolu.Printer.SpanStream.SpanStream
instance GHC.Show.Show Ormolu.Printer.SpanStream.SpanStream
instance GHC.Classes.Eq Ormolu.Printer.SpanStream.SpanStream


-- | Common definitions for pre- and post- processing.
module Ormolu.Processing.Common

-- | Ormolu state.
data OrmoluState

-- | Enabled
OrmoluEnabled :: OrmoluState

-- | Disabled
OrmoluDisabled :: OrmoluState

-- | Marker for the beginning of the region where Ormolu should be
--   disabled.
startDisabling :: IsString s => s

-- | Marker for the end of the region where Ormolu should be disabled.
endDisabling :: IsString s => s
instance GHC.Show.Show Ormolu.Processing.Common.OrmoluState
instance GHC.Classes.Eq Ormolu.Processing.Common.OrmoluState


-- | Support for CPP.
module Ormolu.Processing.Cpp

-- | State of the CPP processor.
data State

-- | Outside of CPP directives
Outside :: State

-- | In a conditional expression
InConditional :: State

-- | In a continuation (after <tt>\</tt>)
InContinuation :: State

-- | Automatically mask the line when needed and update the <a>State</a>.
processLine :: String -> State -> (String, State)

-- | If the given line is masked, unmask it. Otherwise return the line
--   unchanged.
unmaskLine :: Text -> Text
instance GHC.Show.Show Ormolu.Processing.Cpp.State
instance GHC.Classes.Eq Ormolu.Processing.Cpp.State


-- | Postprocessing for the results of printing.
module Ormolu.Processing.Postprocess

-- | Postprocess output of the formatter.
postprocess :: Int -> Text -> Text


-- | Preprocessing for input source code.
module Ormolu.Processing.Preprocess

-- | Transform given input possibly returning comments extracted from it.
--   This handles LINE pragmas, CPP, shebangs, and the magic comments for
--   enabling/disabling of Ormolu.
preprocess :: FilePath -> String -> RegionDeltas -> (String, String, String, [Located String])


-- | Random utilities used by the code.
module Ormolu.Utils

-- | Relative positions in a list.
data RelativePos
SinglePos :: RelativePos
FirstPos :: RelativePos
MiddlePos :: RelativePos
LastPos :: RelativePos

-- | Attach <a>RelativePos</a>es to elements of a given list.
attachRelativePos :: [a] -> [(RelativePos, a)]

-- | Combine all source spans from the given list.
combineSrcSpans' :: NonEmpty SrcSpan -> SrcSpan

-- | Placeholder for things that are not yet implemented.
notImplemented :: String -> a

-- | Pretty-print an <a>Outputable</a> thing.
showOutputable :: Outputable o => o -> String

-- | Split and normalize a doc string. The result is a list of lines that
--   make up the comment.
splitDocString :: HsDocString -> [Text]

-- | Get <a>LHsType</a> out of <a>LHsTypeArg</a>.
typeArgToType :: LHsTypeArg p -> LHsType p

-- | Get <a>RealSrcSpan</a> out of <a>SrcSpan</a> if the span is “helpful”.
unSrcSpan :: SrcSpan -> Maybe RealSrcSpan

-- | Increment line number in a <a>SrcSpan</a>.
incSpanLine :: Int -> SrcSpan -> SrcSpan

-- | Do two declarations have a blank between them?
separatedByBlank :: (a -> SrcSpan) -> a -> a -> Bool

-- | Do two declaration groups have a blank between them?
separatedByBlankNE :: (a -> SrcSpan) -> NonEmpty a -> NonEmpty a -> Bool

-- | Return <a>True</a> if one span ends on the same line the second one
--   starts.
onTheSameLine :: SrcSpan -> SrcSpan -> Bool

-- | Remove indentation from a given <a>String</a>. Return the input with
--   indentation removed and the detected indentation level.
removeIndentation :: String -> (String, Int)
instance GHC.Show.Show Ormolu.Utils.RelativePos
instance GHC.Classes.Eq Ormolu.Utils.RelativePos


-- | This module helps handle operator chains composed of different
--   operators that may have different precedence and fixities.
module Ormolu.Printer.Operators

-- | Intermediate representation of operator trees. It has two type
--   parameters: <tt>ty</tt> is the type of sub-expressions, while
--   <tt>op</tt> is the type of operators.
data OpTree ty op
OpNode :: ty -> OpTree ty op
OpBranch :: OpTree ty op -> op -> OpTree ty op -> OpTree ty op

-- | Return combined <a>SrcSpan</a>s of all elements in this <a>OpTree</a>.
opTreeLoc :: OpTree (Located a) b -> SrcSpan

-- | Re-associate an <a>OpTree</a> taking into account automagically
--   inferred relative precedence of operators. Users are expected to first
--   construct an initial <a>OpTree</a>, then re-associate it using this
--   function before printing.
reassociateOpTree :: (op -> Maybe RdrName) -> OpTree (Located ty) (Located op) -> OpTree (Located ty) (Located op)
instance GHC.Classes.Ord Ormolu.Printer.Operators.Score
instance GHC.Classes.Eq Ormolu.Printer.Operators.Score


-- | Functions for working with comment stream.
module Ormolu.Parser.CommentStream

-- | A stream of <a>RealLocated</a> <a>Comment</a>s in ascending order with
--   respect to beginning of corresponding spans.
newtype CommentStream
CommentStream :: [RealLocated Comment] -> CommentStream

-- | Create <a>CommentStream</a> from <a>PState</a>. The pragmas and
--   shebangs are removed from the <a>CommentStream</a>. Shebangs are only
--   extracted from the comments that come from the first argument.
mkCommentStream :: String -> [Located String] -> PState -> (Maybe (RealLocated Comment), [Shebang], [([RealLocated Comment], Pragma)], CommentStream)

-- | Pretty-print a <a>CommentStream</a>.
showCommentStream :: CommentStream -> String

-- | A wrapper for a single comment. The <a>Bool</a> indicates whether
--   there were atoms before beginning of the comment in the original
--   input. The <a>NonEmpty</a> list inside contains lines of multiline
--   comment <tt>{- … -}</tt> or just single item/line otherwise.
data Comment
Comment :: Bool -> NonEmpty String -> Comment

-- | Get a collection of lines from a <a>Comment</a>.
unComment :: Comment -> NonEmpty String

-- | Check whether the <a>Comment</a> had some non-whitespace atoms in
--   front of it in the original input.
hasAtomsBefore :: Comment -> Bool

-- | Is this comment multiline-style?
isMultilineComment :: Comment -> Bool
instance GHC.Base.Monoid Ormolu.Parser.CommentStream.CommentStream
instance GHC.Base.Semigroup Ormolu.Parser.CommentStream.CommentStream
instance Data.Data.Data Ormolu.Parser.CommentStream.CommentStream
instance GHC.Classes.Eq Ormolu.Parser.CommentStream.CommentStream
instance Data.Data.Data Ormolu.Parser.CommentStream.Comment
instance GHC.Show.Show Ormolu.Parser.CommentStream.Comment
instance GHC.Classes.Eq Ormolu.Parser.CommentStream.Comment


-- | In most cases import <a>Ormolu.Printer.Combinators</a> instead, these
--   functions are the low-level building blocks and should not be used on
--   their own. The <a>R</a> monad is re-exported from
--   <a>Ormolu.Printer.Combinators</a> as well.
module Ormolu.Printer.Internal

-- | The <a>R</a> monad hosts combinators that allow us to describe how to
--   render AST.
data R a

-- | Run an <a>R</a> monad.
runR :: R () -> SpanStream -> CommentStream -> Anns -> Bool -> Text

-- | Output a fixed <a>Text</a> fragment. The argument may not contain any
--   line breaks. <a>txt</a> is used to output all sorts of “fixed” bits of
--   syntax like keywords and pipes <tt>|</tt> in functional dependencies.
--   
--   To separate various bits of syntax with white space use <a>space</a>
--   instead of <tt><a>txt</a> " "</tt>. To output <a>Outputable</a>
--   Haskell entities like numbers use <a>atom</a>.
txt :: Text -> R ()

-- | Similar to <a>txt</a> but the text inserted this way is assumed to
--   break the “link” between the preceding atom and its pending comments.
interferingTxt :: Text -> R ()

-- | Output <a>Outputable</a> fragment of AST. This can be used to output
--   numeric literals and similar. Everything that doesn't have inner
--   structure but does have an <a>Outputable</a> instance.
atom :: Outputable a => a -> R ()

-- | This primitive <i>does not</i> necessarily output a space. It just
--   ensures that the next thing that will be printed on the same line will
--   be separated by a single space from the previous output. Using this
--   combinator twice results in at most one space.
--   
--   In practice this design prevents trailing white space and makes it
--   hard to output more than one delimiting space in a row, which is what
--   we usually want.
space :: R ()

-- | Output a newline. First time <a>newline</a> is used after some
--   non-<a>newline</a> output it gets inserted immediately. Second use of
--   <a>newline</a> does not output anything but makes sure that the next
--   non-white space output will be prefixed by a newline. Using
--   <a>newline</a> more than twice in a row has no effect. Also, using
--   <a>newline</a> at the very beginning has no effect, this is to avoid
--   leading whitespace.
--   
--   Similarly to <a>space</a>, this design prevents trailing newlines and
--   makes it hard to output more than one blank newline in a row.
newline :: R ()

-- | Return <a>True</a> if we should print record dot syntax.
useRecordDot :: R Bool

-- | Increase indentation level by one indentation step for the inner
--   computation. <a>inci</a> should be used when a part of code must be
--   more indented relative to the parts outside of <a>inci</a> in order
--   for the output to be valid Haskell. When layout is single-line there
--   is no obvious effect, but with multi-line layout correct indentation
--   levels matter.
inci :: R () -> R ()

-- | Set indentation level for the inner computation equal to current
--   column. This makes sure that the entire inner block is uniformly
--   "shifted" to the right.
sitcc :: R () -> R ()

-- | <a>Layout</a> options.
data Layout

-- | Put everything on single line
SingleLine :: Layout

-- | Use multiple lines
MultiLine :: Layout

-- | Set <a>Layout</a> for internal computation.
enterLayout :: Layout -> R () -> R ()

-- | Do one or another thing depending on current <a>Layout</a>.
vlayout :: R a -> R a -> R a

-- | Get current <a>Layout</a>.
getLayout :: R Layout

-- | Make the inner computation use braces around single-line layouts.
useBraces :: R () -> R ()

-- | Make the inner computation omit braces around single-line layouts.
dontUseBraces :: R () -> R ()

-- | Return <a>True</a> if we can use braces in this context.
canUseBraces :: R Bool

-- | Modes for rendering of pending comments.
data CommentPosition

-- | Put the comment on the same line
OnTheSameLine :: CommentPosition

-- | Put the comment on next line
OnNextLine :: CommentPosition

-- | Register a comment line for outputting. It will be inserted right
--   before next newline. When the comment goes after something else on the
--   same line, a space will be inserted between preceding text and the
--   comment when necessary.
registerPendingCommentLine :: CommentPosition -> Text -> R ()

-- | Drop elements that begin before or at the same place as given
--   <a>SrcSpan</a>.
trimSpanStream :: RealSrcSpan -> R ()

-- | Get location of next element in AST.
nextEltSpan :: R (Maybe RealSrcSpan)

-- | Pop a <a>Comment</a> from the <a>CommentStream</a> if given predicate
--   is satisfied and there are comments in the stream.
popComment :: (RealLocated Comment -> Bool) -> R (Maybe (RealLocated Comment))

-- | Get the first enclosing <a>RealSrcSpan</a> that satisfies given
--   predicate.
getEnclosingSpan :: (RealSrcSpan -> Bool) -> R (Maybe RealSrcSpan)

-- | Set <a>RealSrcSpan</a> of enclosing span for the given computation.
withEnclosingSpan :: RealSrcSpan -> R () -> R ()

-- | Get spans on this line so far.
thisLineSpans :: R [RealSrcSpan]

-- | An auxiliary marker for keeping track of last output element.
data SpanMark

-- | Haddock comment
HaddockSpan :: HaddockStyle -> RealSrcSpan -> SpanMark

-- | Non-haddock comment
CommentSpan :: RealSrcSpan -> SpanMark

-- | A statement in a do-block and such span
StatementSpan :: RealSrcSpan -> SpanMark

-- | Project <a>RealSrcSpan</a> from <a>SpanMark</a>.
spanMarkSpan :: SpanMark -> RealSrcSpan

-- | Haddock string style.
data HaddockStyle

-- | <pre>
--   -- |
--   </pre>
Pipe :: HaddockStyle

-- | <pre>
--   -- ^
--   </pre>
Caret :: HaddockStyle

-- | <pre>
--   -- *
--   </pre>
Asterisk :: Int -> HaddockStyle

-- | <pre>
--   -- $
--   </pre>
Named :: String -> HaddockStyle

-- | Set span of last output comment.
setSpanMark :: SpanMark -> R ()

-- | Get span of last output comment.
getSpanMark :: R (Maybe SpanMark)

-- | For a given span return <a>AnnKeywordId</a>s associated with it.
getAnns :: SrcSpan -> R [AnnKeywordId]
instance GHC.Base.Monad Ormolu.Printer.Internal.R
instance GHC.Base.Applicative Ormolu.Printer.Internal.R
instance GHC.Base.Functor Ormolu.Printer.Internal.R
instance GHC.Classes.Eq Ormolu.Printer.Internal.SpitType
instance GHC.Show.Show Ormolu.Printer.Internal.SpitType
instance GHC.Show.Show Ormolu.Printer.Internal.CommentPosition
instance GHC.Classes.Eq Ormolu.Printer.Internal.CommentPosition
instance GHC.Show.Show Ormolu.Printer.Internal.Layout
instance GHC.Classes.Eq Ormolu.Printer.Internal.Layout
instance GHC.Show.Show Ormolu.Printer.Internal.RequestedDelimiter
instance GHC.Classes.Eq Ormolu.Printer.Internal.RequestedDelimiter


-- | Helpers for formatting of comments. This is low-level code, use
--   <a>Ormolu.Printer.Combinators</a> unless you know what you are doing.
module Ormolu.Printer.Comments

-- | Output all preceding comments for an element at given location.
spitPrecedingComments :: RealSrcSpan -> R ()

-- | Output all comments following an element at given location.
spitFollowingComments :: RealSrcSpan -> R ()

-- | Output all remaining comments in the comment stream.
spitRemainingComments :: R ()

-- | Output a <a>Comment</a> immediately. This is a low-level printing
--   function.
spitCommentNow :: RealSrcSpan -> Comment -> R ()

-- | Output a <a>Comment</a> at the end of correct line or after it
--   depending on <a>CommentPosition</a>. Used for comments that may
--   potentially follow on the same line as something we just rendered, but
--   not immediately after it.
spitCommentPending :: CommentPosition -> RealSrcSpan -> Comment -> R ()


-- | Printing combinators. The definitions here are presented in such an
--   order so you can just go through the Haddocks and by the end of the
--   file you should have a pretty good idea how to program rendering
--   logic.
module Ormolu.Printer.Combinators

-- | The <a>R</a> monad hosts combinators that allow us to describe how to
--   render AST.
data R a

-- | Run an <a>R</a> monad.
runR :: R () -> SpanStream -> CommentStream -> Anns -> Bool -> Text

-- | For a given span return <a>AnnKeywordId</a>s associated with it.
getAnns :: SrcSpan -> R [AnnKeywordId]

-- | Get the first enclosing <a>RealSrcSpan</a> that satisfies given
--   predicate.
getEnclosingSpan :: (RealSrcSpan -> Bool) -> R (Maybe RealSrcSpan)

-- | Output a fixed <a>Text</a> fragment. The argument may not contain any
--   line breaks. <a>txt</a> is used to output all sorts of “fixed” bits of
--   syntax like keywords and pipes <tt>|</tt> in functional dependencies.
--   
--   To separate various bits of syntax with white space use <a>space</a>
--   instead of <tt><a>txt</a> " "</tt>. To output <a>Outputable</a>
--   Haskell entities like numbers use <a>atom</a>.
txt :: Text -> R ()

-- | Output <a>Outputable</a> fragment of AST. This can be used to output
--   numeric literals and similar. Everything that doesn't have inner
--   structure but does have an <a>Outputable</a> instance.
atom :: Outputable a => a -> R ()

-- | This primitive <i>does not</i> necessarily output a space. It just
--   ensures that the next thing that will be printed on the same line will
--   be separated by a single space from the previous output. Using this
--   combinator twice results in at most one space.
--   
--   In practice this design prevents trailing white space and makes it
--   hard to output more than one delimiting space in a row, which is what
--   we usually want.
space :: R ()

-- | Output a newline. First time <a>newline</a> is used after some
--   non-<a>newline</a> output it gets inserted immediately. Second use of
--   <a>newline</a> does not output anything but makes sure that the next
--   non-white space output will be prefixed by a newline. Using
--   <a>newline</a> more than twice in a row has no effect. Also, using
--   <a>newline</a> at the very beginning has no effect, this is to avoid
--   leading whitespace.
--   
--   Similarly to <a>space</a>, this design prevents trailing newlines and
--   makes it hard to output more than one blank newline in a row.
newline :: R ()

-- | Increase indentation level by one indentation step for the inner
--   computation. <a>inci</a> should be used when a part of code must be
--   more indented relative to the parts outside of <a>inci</a> in order
--   for the output to be valid Haskell. When layout is single-line there
--   is no obvious effect, but with multi-line layout correct indentation
--   levels matter.
inci :: R () -> R ()

-- | Indent the inner expression if the first argument is <a>True</a>.
inciIf :: Bool -> R () -> R ()

-- | Enter a <a>Located</a> entity. This combinator handles outputting
--   comments and sets layout (single-line vs multi-line) for the inner
--   computation. Roughly, the rule for using <a>located</a> is that every
--   time there is a <a>Located</a> wrapper, it should be “discharged” with
--   a corresponding <a>located</a> invocation.
located :: Located a -> (a -> R ()) -> R ()

-- | A version of <a>located</a> with arguments flipped.
located' :: (a -> R ()) -> Located a -> R ()

-- | Set layout according to combination of given <a>SrcSpan</a>s for a
--   given. Use this only when you need to set layout based on e.g.
--   combined span of several elements when there is no corresponding
--   <a>Located</a> wrapper provided by GHC AST. It is relatively rare that
--   this one is needed.
--   
--   Given empty list this function will set layout to single line.
switchLayout :: [SrcSpan] -> R () -> R ()

-- | <a>Layout</a> options.
data Layout

-- | Put everything on single line
SingleLine :: Layout

-- | Use multiple lines
MultiLine :: Layout

-- | Do one or another thing depending on current <a>Layout</a>.
vlayout :: R a -> R a -> R a

-- | Get current <a>Layout</a>.
getLayout :: R Layout

-- | Insert a space if enclosing layout is single-line, or newline if it's
--   multiline.
--   
--   <pre>
--   breakpoint = vlayout space newline
--   </pre>
breakpoint :: R ()

-- | Similar to <a>breakpoint</a> but outputs nothing in case of
--   single-line layout.
--   
--   <pre>
--   breakpoint' = vlayout (return ()) newline
--   </pre>
breakpoint' :: R ()

-- | Render a collection of elements inserting a separator between them.
sep :: R () -> (a -> R ()) -> [a] -> R ()

-- | Render a collection of elements layout-sensitively using given
--   printer, inserting semicolons if necessary and respecting
--   <a>useBraces</a> and <a>dontUseBraces</a> combinators.
--   
--   <pre>
--   useBraces $ sepSemi txt ["foo", "bar"]
--     == vlayout (txt "{ foo; bar }") (txt "foo\nbar")
--   </pre>
--   
--   <pre>
--   dontUseBraces $ sepSemi txt ["foo", "bar"]
--     == vlayout (txt "foo; bar") (txt "foo\nbar")
--   </pre>
sepSemi :: (a -> R ()) -> [a] -> R ()

-- | Return <a>True</a> if we can use braces in this context.
canUseBraces :: R Bool

-- | Make the inner computation use braces around single-line layouts.
useBraces :: R () -> R ()

-- | Make the inner computation omit braces around single-line layouts.
dontUseBraces :: R () -> R ()

-- | <a>BracketStyle</a> controlling how closing bracket is rendered.
data BracketStyle

-- | Normal
N :: BracketStyle

-- | Shifted one level
S :: BracketStyle

-- | Set indentation level for the inner computation equal to current
--   column. This makes sure that the entire inner block is uniformly
--   "shifted" to the right.
sitcc :: R () -> R ()

-- | Surround given entity by backticks.
backticks :: R () -> R ()

-- | Surround given entity by banana brackets (i.e., from arrow notation.)
banana :: R () -> R ()

-- | Surround given entity by curly braces <tt>{</tt> and <tt>}</tt>.
braces :: BracketStyle -> R () -> R ()

-- | Surround given entity by square brackets <tt>[</tt> and <tt>]</tt>.
brackets :: BracketStyle -> R () -> R ()

-- | Surround given entity by parentheses <tt>(</tt> and <tt>)</tt>.
parens :: BracketStyle -> R () -> R ()

-- | Surround given entity by <tt>(# </tt> and <tt> #)</tt>.
parensHash :: BracketStyle -> R () -> R ()

-- | Braces as used for pragmas: <tt>{-#</tt> and <tt>#-}</tt>.
pragmaBraces :: R () -> R ()

-- | Surround the body with a pragma name and <a>pragmaBraces</a>.
pragma :: Text -> R () -> R ()

-- | Print <tt>,</tt>.
comma :: R ()

-- | Delimiting combination with <a>comma</a>. To be used with <a>sep</a>.
commaDel :: R ()

-- | Print <tt>=</tt>. Do not use <tt><a>txt</a> "="</tt>.
equals :: R ()

-- | An auxiliary marker for keeping track of last output element.
data SpanMark

-- | Haddock comment
HaddockSpan :: HaddockStyle -> RealSrcSpan -> SpanMark

-- | Non-haddock comment
CommentSpan :: RealSrcSpan -> SpanMark

-- | A statement in a do-block and such span
StatementSpan :: RealSrcSpan -> SpanMark

-- | Project <a>RealSrcSpan</a> from <a>SpanMark</a>.
spanMarkSpan :: SpanMark -> RealSrcSpan

-- | Haddock string style.
data HaddockStyle

-- | <pre>
--   -- |
--   </pre>
Pipe :: HaddockStyle

-- | <pre>
--   -- ^
--   </pre>
Caret :: HaddockStyle

-- | <pre>
--   -- *
--   </pre>
Asterisk :: Int -> HaddockStyle

-- | <pre>
--   -- $
--   </pre>
Named :: String -> HaddockStyle

-- | Set span of last output comment.
setSpanMark :: SpanMark -> R ()

-- | Get span of last output comment.
getSpanMark :: R (Maybe SpanMark)
instance GHC.Show.Show Ormolu.Printer.Combinators.BracketStyle
instance GHC.Classes.Eq Ormolu.Printer.Combinators.BracketStyle


-- | Pretty-printing of language pragmas.
module Ormolu.Printer.Meat.Pragma

-- | Print a collection of <a>Pragma</a>s with their associated comments.
p_pragmas :: [([RealLocated Comment], Pragma)] -> R ()
instance GHC.Classes.Ord Ormolu.Printer.Meat.Pragma.PragmaTy
instance GHC.Classes.Eq Ormolu.Printer.Meat.Pragma.PragmaTy
instance GHC.Classes.Ord Ormolu.Printer.Meat.Pragma.LanguagePragmaClass
instance GHC.Classes.Eq Ormolu.Printer.Meat.Pragma.LanguagePragmaClass


-- | Rendering of commonly useful bits.
module Ormolu.Printer.Meat.Common

-- | Data and type family style.
data FamilyStyle

-- | Declarations in type classes
Associated :: FamilyStyle

-- | Top-level declarations
Free :: FamilyStyle
p_hsmodName :: ModuleName -> R ()
p_ieWrappedName :: IEWrappedName RdrName -> R ()

-- | Render a <tt><a>Located</a> <a>RdrName</a></tt>.
p_rdrName :: Located RdrName -> R ()

-- | Whether given name should not have parentheses around it. This is used
--   to detect e.g. tuples for which annotations will indicate parentheses,
--   but the parentheses are already part of the symbol, so no extra layer
--   of parentheses should be added. It also detects the [] literal.
doesNotNeedExtraParens :: RdrName -> Bool
p_qualName :: ModuleName -> OccName -> R ()

-- | A helper for formatting infix constructions in lhs of definitions.
p_infixDefHelper :: Bool -> Bool -> R () -> [R ()] -> R ()

-- | Print a Haddock.
p_hsDocString :: HaddockStyle -> Bool -> LHsDocString -> R ()

-- | Print anchor of named doc section.
p_hsDocName :: String -> R ()


-- | Rendering of types.
module Ormolu.Printer.Meat.Type
p_hsType :: HsType GhcPs -> R ()
p_hsTypePostDoc :: HsType GhcPs -> R ()

-- | Return <a>True</a> if at least one argument in <a>HsType</a> has a doc
--   string attached to it.
hasDocStrings :: HsType GhcPs -> Bool
p_hsContext :: HsContext GhcPs -> R ()
p_hsTyVarBndr :: HsTyVarBndr GhcPs -> R ()

-- | Render several <tt>forall</tt>-ed variables.
p_forallBndrs :: Data a => ForallVisFlag -> (a -> R ()) -> [Located a] -> R ()
p_conDeclFields :: [LConDeclField GhcPs] -> R ()
tyVarsToTypes :: LHsQTyVars GhcPs -> [LHsType GhcPs]

module Ormolu.Printer.Meat.Declaration.Default
p_defaultDecl :: DefaultDecl GhcPs -> R ()


-- | Rendering of import and export lists.
module Ormolu.Printer.Meat.ImportExport
p_hsmodExports :: [LIE GhcPs] -> R ()
p_hsmodImport :: Bool -> ImportDecl GhcPs -> R ()

module Ormolu.Printer.Meat.Declaration.Warning
p_warnDecls :: WarnDecls GhcPs -> R ()
p_moduleWarning :: WarningTxt -> R ()


-- | Rendering of data/type families.
module Ormolu.Printer.Meat.Declaration.TypeFamily
p_famDecl :: FamilyStyle -> FamilyDecl GhcPs -> R ()
p_tyFamInstEqn :: TyFamInstEqn GhcPs -> R ()


-- | Rendering of type synonym declarations.
module Ormolu.Printer.Meat.Declaration.Type
p_synDecl :: Located RdrName -> LexicalFixity -> LHsQTyVars GhcPs -> LHsType GhcPs -> R ()


-- | Type signature declarations.
module Ormolu.Printer.Meat.Declaration.Signature
p_sigDecl :: Sig GhcPs -> R ()
p_typeAscription :: LHsSigWcType GhcPs -> R ()
p_activation :: Activation -> R ()
p_standaloneKindSig :: StandaloneKindSig GhcPs -> R ()


-- | Rendering of Role annotation declarations.
module Ormolu.Printer.Meat.Declaration.RoleAnnotation
p_roleAnnot :: RoleAnnotDecl GhcPs -> R ()

module Ormolu.Printer.Meat.Declaration.Foreign
p_foreignDecl :: ForeignDecl GhcPs -> R ()


-- | Renedring of data type declarations.
module Ormolu.Printer.Meat.Declaration.Data
p_dataDecl :: FamilyStyle -> Located RdrName -> [LHsType GhcPs] -> LexicalFixity -> HsDataDefn GhcPs -> R ()

module Ormolu.Printer.Meat.Declaration.Value
p_valDecl :: HsBindLR GhcPs GhcPs -> R ()
p_pat :: Pat GhcPs -> R ()
p_hsExpr :: HsExpr GhcPs -> R ()
p_hsSplice :: HsSplice GhcPs -> R ()
p_stringLit :: String -> R ()
instance GHC.Show.Show Ormolu.Printer.Meat.Declaration.Value.Placement
instance GHC.Classes.Eq Ormolu.Printer.Meat.Declaration.Value.Placement

module Ormolu.Printer.Meat.Declaration.Splice
p_spliceDecl :: SpliceDecl GhcPs -> R ()

module Ormolu.Printer.Meat.Declaration.Rule
p_ruleDecls :: RuleDecls GhcPs -> R ()

module Ormolu.Printer.Meat.Declaration.Annotation
p_annDecl :: AnnDecl GhcPs -> R ()


-- | Type class, type family, and data family instance declarations.
module Ormolu.Printer.Meat.Declaration.Instance
p_clsInstDecl :: ClsInstDecl GhcPs -> R ()
p_tyFamInstDecl :: FamilyStyle -> TyFamInstDecl GhcPs -> R ()
p_dataFamInstDecl :: FamilyStyle -> DataFamInstDecl GhcPs -> R ()
p_standaloneDerivDecl :: DerivDecl GhcPs -> R ()


-- | Rendering of type class declarations.
module Ormolu.Printer.Meat.Declaration.Class
p_classDecl :: LHsContext GhcPs -> Located RdrName -> LHsQTyVars GhcPs -> LexicalFixity -> [Located (FunDep (Located RdrName))] -> [LSig GhcPs] -> LHsBinds GhcPs -> [LFamilyDecl GhcPs] -> [LTyFamDefltDecl GhcPs] -> [LDocDecl] -> R ()


-- | Rendering of declarations.
module Ormolu.Printer.Meat.Declaration
p_hsDecls :: FamilyStyle -> [LHsDecl GhcPs] -> R ()

-- | Like <a>p_hsDecls</a> but respects user choices regarding grouping. If
--   the user omits newlines between declarations, we also omit them in
--   most cases, except when said declarations have associated Haddocks.
--   
--   Does some normalization (compress subsequent newlines into a single
--   one)
p_hsDeclsRespectGrouping :: FamilyStyle -> [LHsDecl GhcPs] -> R ()
instance GHC.Show.Show Ormolu.Printer.Meat.Declaration.UserGrouping
instance GHC.Classes.Eq Ormolu.Printer.Meat.Declaration.UserGrouping


-- | A type for result of parsing.
module Ormolu.Parser.Result

-- | A collection of data that represents a parsed module in Ormolu.
data ParseResult
ParseResult :: HsModule GhcPs -> Anns -> Maybe (RealLocated Comment) -> [Shebang] -> [([RealLocated Comment], Pragma)] -> CommentStream -> Bool -> Bool -> Text -> Text -> Int -> ParseResult

-- | <tt>ParsedSource</tt> from GHC
[prParsedSource] :: ParseResult -> HsModule GhcPs

-- | Ormolu-specfic representation of annotations
[prAnns] :: ParseResult -> Anns

-- | Stack header
[prStackHeader] :: ParseResult -> Maybe (RealLocated Comment)

-- | Shebangs found in the input
[prShebangs] :: ParseResult -> [Shebang]

-- | Pragmas and the associated comments
[prPragmas] :: ParseResult -> [([RealLocated Comment], Pragma)]

-- | Comment stream
[prCommentStream] :: ParseResult -> CommentStream

-- | Whether or not record dot syntax is enabled
[prUseRecordDot] :: ParseResult -> Bool

-- | Whether or not ImportQualifiedPost is enabled
[prImportQualifiedPost] :: ParseResult -> Bool

-- | Literal prefix
[prLiteralPrefix] :: ParseResult -> Text

-- | Literal suffix
[prLiteralSuffix] :: ParseResult -> Text

-- | Indentation level, can be non-zero in case of region formatting
[prIndent] :: ParseResult -> Int

-- | Pretty-print a <a>ParseResult</a>.
prettyPrintParseResult :: ParseResult -> String


-- | Manipulations on import lists.
module Ormolu.Imports

-- | Sort and normalize imports.
normalizeImports :: [LImportDecl GhcPs] -> [LImportDecl GhcPs]
instance GHC.Classes.Eq Ormolu.Imports.IEWrappedNameOrd
instance GHC.Classes.Ord Ormolu.Imports.ImportId
instance GHC.Classes.Eq Ormolu.Imports.ImportId
instance GHC.Classes.Ord Ormolu.Imports.IEWrappedNameOrd


-- | Rendering of modules.
module Ormolu.Printer.Meat.Module

-- | Render a module.
p_hsModule :: Maybe (RealLocated Comment) -> [Shebang] -> [([RealLocated Comment], Pragma)] -> Bool -> HsModule GhcPs -> R ()


-- | Pretty-printer for Haskell AST.
module Ormolu.Printer

-- | Render a module.
printModule :: ParseResult -> Text


-- | <a>OrmoluException</a> type and surrounding definitions.
module Ormolu.Exception

-- | Ormolu exception representing all cases when Ormolu can fail.
data OrmoluException

-- | Parsing of original source code failed
OrmoluParsingFailed :: SrcSpan -> String -> OrmoluException

-- | Parsing of formatted source code failed
OrmoluOutputParsingFailed :: SrcSpan -> String -> OrmoluException

-- | Original and resulting ASTs differ
OrmoluASTDiffers :: FilePath -> [SrcSpan] -> OrmoluException

-- | Formatted source code is not idempotent
OrmoluNonIdempotentOutput :: RealSrcLoc -> Text -> Text -> OrmoluException

-- | Some GHC options were not recognized
OrmoluUnrecognizedOpts :: NonEmpty String -> OrmoluException

-- | Inside this wrapper <a>OrmoluException</a> will be caught and
--   displayed nicely using <a>displayException</a>.
withPrettyOrmoluExceptions :: IO a -> IO a
instance GHC.Show.Show Ormolu.Exception.OrmoluException
instance GHC.Classes.Eq Ormolu.Exception.OrmoluException
instance GHC.Exception.Type.Exception Ormolu.Exception.OrmoluException


-- | Parser for Haskell source code.
module Ormolu.Parser

-- | Parse a complete module from string.
parseModule :: MonadIO m => Config RegionDeltas -> FilePath -> String -> m ([Warn], Either (SrcSpan, String) ParseResult)

-- | Extensions that are not enabled automatically and should be activated
--   by user.
manualExts :: [Extension]
instance GHC.Classes.Eq Ormolu.Parser.SeverityOrd
instance GHC.Classes.Ord Ormolu.Parser.SeverityOrd


-- | Diffing GHC ASTs modulo span positions.
module Ormolu.Diff

-- | Result of comparing two <a>ParseResult</a>s.
data Diff

-- | Two parse results are the same
Same :: Diff

-- | Two parse results differ
Different :: [SrcSpan] -> Diff

-- | Return <a>Diff</a> of two <a>ParseResult</a>s.
diffParseResult :: ParseResult -> ParseResult -> Diff

-- | Diff two texts and return the location they start to differ, alongside
--   with excerpts around that location.
diffText :: Text -> Text -> FilePath -> Maybe (RealSrcLoc, Text, Text)
instance GHC.Base.Semigroup Ormolu.Diff.Diff
instance GHC.Base.Monoid Ormolu.Diff.Diff


-- | A formatter for Haskell source code.
module Ormolu

-- | Format a <a>String</a>, return formatted version as <a>Text</a>.
--   
--   The function
--   
--   <ul>
--   <li>Takes <a>String</a> because that's what GHC parser accepts.</li>
--   <li>Needs <a>IO</a> because some functions from GHC that are necessary
--   to setup parsing context require <a>IO</a>. There should be no visible
--   side-effects though.</li>
--   <li>Takes file name just to use it in parse error messages.</li>
--   <li>Throws <a>OrmoluException</a>.</li>
--   </ul>
ormolu :: MonadIO m => Config RegionIndices -> FilePath -> String -> m Text

-- | Load a file and format it. The file stays intact and the rendered
--   version is returned as <a>Text</a>.
--   
--   <pre>
--   ormoluFile cfg path =
--     liftIO (readFile path) &gt;&gt;= ormolu cfg path
--   </pre>
ormoluFile :: MonadIO m => Config RegionIndices -> FilePath -> m Text

-- | Read input from stdin and format it.
--   
--   <pre>
--   ormoluStdin cfg =
--     liftIO (hGetContents stdin) &gt;&gt;= ormolu cfg "&lt;stdin&gt;"
--   </pre>
ormoluStdin :: MonadIO m => Config RegionIndices -> m Text

-- | Ormolu configuration.
data Config region
Config :: ![DynOption] -> !Bool -> !Bool -> !Bool -> !region -> Config region

-- | Dynamic options to pass to GHC parser
[cfgDynOptions] :: Config region -> ![DynOption]

-- | Do formatting faster but without automatic detection of defects
[cfgUnsafe] :: Config region -> !Bool

-- | Output information useful for debugging
[cfgDebug] :: Config region -> !Bool

-- | Checks if re-formatting the result is idempotent
[cfgCheckIdempotence] :: Config region -> !Bool

-- | Region selection
[cfgRegion] :: Config region -> !region

-- | Region selection as the combination of start and end line numbers.
data RegionIndices
RegionIndices :: !Maybe Int -> !Maybe Int -> RegionIndices

-- | Start line of the region to format
[regionStartLine] :: RegionIndices -> !Maybe Int

-- | End line of the region to format
[regionEndLine] :: RegionIndices -> !Maybe Int

-- | Default <tt><a>Config</a> <a>RegionIndices</a></tt>.
defaultConfig :: Config RegionIndices

-- | A wrapper for dynamic options.
newtype DynOption
DynOption :: String -> DynOption
[unDynOption] :: DynOption -> String

-- | Ormolu exception representing all cases when Ormolu can fail.
data OrmoluException

-- | Parsing of original source code failed
OrmoluParsingFailed :: SrcSpan -> String -> OrmoluException

-- | Parsing of formatted source code failed
OrmoluOutputParsingFailed :: SrcSpan -> String -> OrmoluException

-- | Original and resulting ASTs differ
OrmoluASTDiffers :: FilePath -> [SrcSpan] -> OrmoluException

-- | Formatted source code is not idempotent
OrmoluNonIdempotentOutput :: RealSrcLoc -> Text -> Text -> OrmoluException

-- | Some GHC options were not recognized
OrmoluUnrecognizedOpts :: NonEmpty String -> OrmoluException

-- | Inside this wrapper <a>OrmoluException</a> will be caught and
--   displayed nicely using <a>displayException</a>.
withPrettyOrmoluExceptions :: IO a -> IO a
