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


-- | ExactPrint for GHC
--   
--   Using the API Annotations available from GHC 7.10.2, this library
--   provides a means to round trip any code that can be compiled by GHC,
--   currently excluding lhs files.
--   
--   It does this with a phased approach
--   
--   <ul>
--   <li>Delta - converts GHC API Annotations into relative offsets,
--   indexed by SrcSpan</li>
--   <li>Transform - functions to facilitate changes to the AST, adjusting
--   the annotations generated in the Delta phase to suit the changes.</li>
--   <li>Print - converts an AST and its annotations to properly formatted
--   source text.</li>
--   <li>Pretty - adds annotations to an AST (fragment) so that the output
--   can be parsed back to the same AST.</li>
--   </ul>
--   
--   Note: requires GHC 7.10.2 or later
@package ghc-exactprint
@version 0.6.2

module Language.Haskell.GHC.ExactPrint.Types

-- | This structure holds a complete set of annotations for an AST
type Anns = Map AnnKey Annotation
emptyAnns :: Anns
data Annotation
Ann :: !DeltaPos -> ![(Comment, DeltaPos)] -> ![(Comment, DeltaPos)] -> ![(KeywordId, DeltaPos)] -> !Maybe [SrcSpan] -> !Maybe AnnKey -> Annotation

-- | Offset used to get to the start of the SrcSpan, from whatever the
--   prior output was, including all annPriorComments (field below).
[annEntryDelta] :: Annotation -> !DeltaPos

-- | Comments coming after the last non-comment output of the preceding
--   element but before the SrcSpan being annotated by this Annotation. If
--   these are changed then annEntryDelta (field above) must also change to
--   match.
[annPriorComments] :: Annotation -> ![(Comment, DeltaPos)]

-- | Comments coming after the last output for the element subject to this
--   Annotation. These will only be added by AST transformations, and care
--   must be taken not to disturb layout of following elements.
[annFollowingComments] :: Annotation -> ![(Comment, DeltaPos)]

-- | Annotations associated with this element.
[annsDP] :: Annotation -> ![(KeywordId, DeltaPos)]

-- | Captures the sort order of sub elements. This is needed when the
--   sub-elements have been split (as in a HsLocalBind which holds separate
--   binds and sigs) or for infix patterns where the order has been
--   re-arranged. It is captured explicitly so that after the Delta phase a
--   SrcSpan is used purely as an index into the annotations, allowing
--   transformations of the AST including the introduction of new Located
--   items or re-arranging existing ones.
[annSortKey] :: Annotation -> !Maybe [SrcSpan]

-- | Occasionally we must calculate a SrcSpan for an unlocated list of
--   elements which we must remember for the Print phase. e.g. the
--   statements in a HsLet or HsDo. These must be managed as a group
--   because they all need eo be vertically aligned for the Haskell layout
--   rules, and this guarantees this property in the presence of AST edits.
[annCapturedSpan] :: Annotation -> !Maybe AnnKey
annNone :: Annotation

-- | The different syntactic elements which are not represented in the AST.
data KeywordId

-- | A normal keyword
G :: AnnKeywordId -> KeywordId

-- | A separating comma
AnnSemiSep :: KeywordId

-- | Visible type application annotation
AnnTypeApp :: KeywordId
AnnComment :: Comment -> KeywordId

-- | Used to pass information from Delta to Print when we have to work out
--   details from the original SrcSpan.
AnnString :: String -> KeywordId

-- | A Haskell comment. The <tt>AnnKeywordId</tt> is present if it has been
--   converted from an <tt>AnnKeywordId</tt> because the annotation must be
--   interleaved into the stream and does not have a well-defined position
data Comment
Comment :: !String -> !SrcSpan -> !Maybe AnnKeywordId -> Comment

-- | The contents of the comment including separators
[commentContents] :: Comment -> !String

-- | Needed to uniquely identify two comments with the same contents
[commentIdentifier] :: Comment -> !SrcSpan

-- | We sometimes turn syntax into comments in order to process them
--   properly.
[commentOrigin] :: Comment -> !Maybe AnnKeywordId
type Pos = (Int, Int)

-- | A relative positions, row then column
newtype DeltaPos
DP :: (Int, Int) -> DeltaPos
deltaRow :: DeltaPos -> Int
deltaColumn :: DeltaPos -> Int

-- | For every <tt>Located a</tt>, use the <tt>SrcSpan</tt> and constructor
--   name of a as the key, to store the standard annotation. These are used
--   to maintain context in the AP and EP monads
data AnnKey
AnnKey :: SrcSpan -> AnnConName -> AnnKey

-- | Make an unwrapped <tt>AnnKey</tt> for the <tt>LHsDecl</tt> case, a
--   normal one otherwise.
mkAnnKey :: Constraints a => a -> AnnKey
data AnnConName
CN :: String -> AnnConName
[unConName] :: AnnConName -> String
annGetConstr :: Data a => a -> AnnConName
data Rigidity
NormalLayout :: Rigidity
RigidLayout :: Rigidity
data AstContext
LambdaExpr :: AstContext
CaseAlt :: AstContext
NoPrecedingSpace :: AstContext
HasHiding :: AstContext
AdvanceLine :: AstContext
NoAdvanceLine :: AstContext
Intercalate :: AstContext
InIE :: AstContext
PrefixOp :: AstContext
PrefixOpDollar :: AstContext
InfixOp :: AstContext
ListStart :: AstContext
ListItem :: AstContext
TopLevel :: AstContext
NoDarrow :: AstContext
AddVbar :: AstContext
Deriving :: AstContext
Parens :: AstContext
ExplicitNeverActive :: AstContext
InGadt :: AstContext
InRecCon :: AstContext
InClassDecl :: AstContext
InSpliceDecl :: AstContext
LeftMost :: AstContext
InTypeApp :: AstContext
CtxOnly :: AstContext
CtxFirst :: AstContext
CtxMiddle :: AstContext
CtxLast :: AstContext
CtxPos :: Int -> AstContext
FollowingLine :: AstContext
type AstContextSet = ACS' AstContext
defaultACS :: AstContextSet
data ACS' a
ACS :: !Map a Int -> ACS' a

-- | how many levels each AstContext should propagate down the AST. Removed
--   when it hits zero
[acs] :: ACS' a -> !Map a Int
data ListContexts
LC :: !Set AstContext -> ListContexts
[lcOnly, lcInitial, lcMiddle, lcLast] :: ListContexts -> !Set AstContext
type Constraints a = (Data a, Data (SrcSpanLess a), HasSrcSpan a)
type GhcPs = GhcPs
type GhcRn = GhcRn
type GhcTc = GhcTc

-- | Marks the start column of a layout block.
newtype LayoutStartCol
LayoutStartCol :: Int -> LayoutStartCol
[getLayoutStartCol] :: LayoutStartCol -> Int
declFun :: (forall a. Data a => Located a -> b) -> LHsDecl GhcPs -> b
instance GHC.Show.Show Language.Haskell.GHC.ExactPrint.Types.ListContexts
instance GHC.Classes.Eq Language.Haskell.GHC.ExactPrint.Types.ListContexts
instance GHC.Show.Show Language.Haskell.GHC.ExactPrint.Types.AstContext
instance GHC.Classes.Ord Language.Haskell.GHC.ExactPrint.Types.AstContext
instance GHC.Classes.Eq Language.Haskell.GHC.ExactPrint.Types.AstContext
instance GHC.Show.Show a => GHC.Show.Show (Language.Haskell.GHC.ExactPrint.Types.ACS' a)
instance GHC.Show.Show Language.Haskell.GHC.ExactPrint.Types.Rigidity
instance GHC.Classes.Ord Language.Haskell.GHC.ExactPrint.Types.Rigidity
instance GHC.Classes.Eq Language.Haskell.GHC.ExactPrint.Types.Rigidity
instance GHC.Classes.Eq Language.Haskell.GHC.ExactPrint.Types.Annotation
instance Data.Data.Data Language.Haskell.GHC.ExactPrint.Types.KeywordId
instance GHC.Classes.Ord Language.Haskell.GHC.ExactPrint.Types.KeywordId
instance GHC.Classes.Eq Language.Haskell.GHC.ExactPrint.Types.KeywordId
instance Data.Data.Data Language.Haskell.GHC.ExactPrint.Types.AnnKey
instance GHC.Classes.Ord Language.Haskell.GHC.ExactPrint.Types.AnnKey
instance GHC.Classes.Eq Language.Haskell.GHC.ExactPrint.Types.AnnKey
instance Data.Data.Data Language.Haskell.GHC.ExactPrint.Types.AnnConName
instance GHC.Classes.Ord Language.Haskell.GHC.ExactPrint.Types.AnnConName
instance GHC.Classes.Eq Language.Haskell.GHC.ExactPrint.Types.AnnConName
instance GHC.Num.Num Language.Haskell.GHC.ExactPrint.Types.LayoutStartCol
instance GHC.Classes.Eq Language.Haskell.GHC.ExactPrint.Types.LayoutStartCol
instance Data.Data.Data Language.Haskell.GHC.ExactPrint.Types.DeltaPos
instance GHC.Classes.Ord Language.Haskell.GHC.ExactPrint.Types.DeltaPos
instance GHC.Classes.Eq Language.Haskell.GHC.ExactPrint.Types.DeltaPos
instance GHC.Show.Show Language.Haskell.GHC.ExactPrint.Types.DeltaPos
instance GHC.Classes.Ord Language.Haskell.GHC.ExactPrint.Types.Comment
instance Data.Data.Data Language.Haskell.GHC.ExactPrint.Types.Comment
instance GHC.Classes.Eq Language.Haskell.GHC.ExactPrint.Types.Comment
instance GHC.Base.Semigroup (Language.Haskell.GHC.ExactPrint.Types.ACS' Language.Haskell.GHC.ExactPrint.Types.AstContext)
instance GHC.Base.Monoid (Language.Haskell.GHC.ExactPrint.Types.ACS' Language.Haskell.GHC.ExactPrint.Types.AstContext)
instance GHC.Show.Show a => Outputable.Outputable (Language.Haskell.GHC.ExactPrint.Types.ACS' a)
instance GHC.Show.Show Language.Haskell.GHC.ExactPrint.Types.Annotation
instance Outputable.Outputable Language.Haskell.GHC.ExactPrint.Types.Annotation
instance GHC.Show.Show Language.Haskell.GHC.ExactPrint.Types.KeywordId
instance Outputable.Outputable Language.Haskell.GHC.ExactPrint.Types.KeywordId
instance GHC.Show.Show Language.Haskell.GHC.ExactPrint.Types.AnnKey
instance Outputable.Outputable Language.Haskell.GHC.ExactPrint.Types.AnnKey
instance GHC.Show.Show Language.Haskell.GHC.ExactPrint.Types.AnnConName
instance Outputable.Outputable Language.Haskell.GHC.ExactPrint.Types.AnnConName
instance GHC.Show.Show Language.Haskell.GHC.ExactPrint.Types.LayoutStartCol
instance Outputable.Outputable Language.Haskell.GHC.ExactPrint.Types.DeltaPos
instance GHC.Show.Show Language.Haskell.GHC.ExactPrint.Types.Comment
instance Outputable.Outputable Language.Haskell.GHC.ExactPrint.Types.Comment

module Language.Haskell.GHC.ExactPrint.Lookup

-- | Maps <tt>AnnKeywordId</tt> to the corresponding String representation.
--   There is no specific mapping for the following constructors.
--   <tt>AnnOpen</tt>, <tt>AnnClose</tt>, <tt>AnnVal</tt>,
--   <tt>AnnPackageName</tt>, <tt>AnnHeader</tt>, <tt>AnnFunId</tt>,
--   <tt>AnnInfix</tt>
keywordToString :: KeywordId -> String


-- | <tt>annotate</tt> is a function which given a GHC AST fragment,
--   constructs a syntax tree which indicates which annotations belong to
--   each specific part of the fragment.
--   
--   <a>Delta</a> and <a>Print</a> provide two interpreters for this
--   structure. You should probably use those unless you know what you're
--   doing!
--   
--   The functor <a>AnnotationF</a> has a number of constructors which
--   correspond to different sitations which annotations can arise. It is
--   hoped that in future versions of GHC these can be simplified by making
--   suitable modifications to the AST.
module Language.Haskell.GHC.ExactPrint.AnnotateTypes

-- | <ul>
--   <li><i><a>MarkPrim</a></i> The main constructor. Marks that a specific
--   AnnKeywordId could appear with an optional String which is used when
--   printing.</li>
--   <li><i><a>MarkPPOptional</a></i> Used to flag elements, such as
--   optional braces, that are not used in the pretty printer. This
--   functions identically to <a>MarkPrim</a> for the other
--   interpreters.</li>
--   <li><i><a>MarkEOF</a></i> Special constructor which marks the end of
--   file marker.</li>
--   <li><i><a>MarkExternal</a></i> TODO</li>
--   <li><i><a>MarkOutside</a></i> A <tt>AnnKeywordId</tt> which is
--   precisely located but not inside the current context. This is usually
--   used to reassociated located <tt>RdrName</tt> which are more naturally
--   associated with their parent than in their own annotation.</li>
--   <li><i><a>MarkInside</a></i> The dual of MarkOutside. If we wish to
--   mark a non-separating comma or semi-colon then we must use this
--   constructor.</li>
--   <li><i><a>MarkMany</a></i> Some syntax elements allow an arbritary
--   number of puncuation marks without reflection in the AST. This
--   construction greedily takes all of the specified
--   <tt>AnnKeywordId</tt>.</li>
--   <li><i><a>MarkOffsetPrim</a></i> Some syntax elements have repeated
--   <tt>AnnKeywordId</tt> which are seperated by different
--   <tt>AnnKeywordId</tt>. Thus using MarkMany is unsuitable and instead
--   we provide an index to specify which specific instance to choose each
--   time.</li>
--   <li><i><a>WithAST</a></i> TODO</li>
--   <li><i><a>CountAnns</a></i> Sometimes the AST does not reflect the
--   concrete source code and the only way to tell what the concrete source
--   was is to count a certain kind of <tt>AnnKeywordId</tt>.</li>
--   <li><i><a>WithSortKey</a></i> There are many places where the
--   syntactic ordering of elements is thrown away by the AST. This
--   constructor captures the original ordering and reflects any changes in
--   ordered as specified by the <tt>annSortKey</tt> field in
--   <tt>Annotation</tt>.</li>
--   <li><i><a>SetLayoutFlag</a></i> It is important to know precisely
--   where layout rules apply. This constructor wraps a computation to
--   indicate that LayoutRules apply to the corresponding construct.</li>
--   <li><i><a>StoreOriginalSrcSpan</a></i> TODO</li>
--   <li><i><tt>GetSrcSpanFromKw</tt></i> TODO</li>
--   <li><i><tt>StoreString</tt></i> TODO</li>
--   <li><i><a>AnnotationsToComments</a></i> Used when the AST is
--   sufficiently vague that there is no other option but to convert a
--   fragment of source code into a comment. This means it is impossible to
--   edit such a fragment but means that processing files with such
--   fragments is still possible.</li>
--   </ul>
data AnnotationF next
[MarkPrim] :: AnnKeywordId -> Maybe String -> next -> AnnotationF next
[MarkPPOptional] :: AnnKeywordId -> Maybe String -> next -> AnnotationF next
[MarkEOF] :: next -> AnnotationF next
[MarkExternal] :: SrcSpan -> AnnKeywordId -> String -> next -> AnnotationF next
[MarkInstead] :: AnnKeywordId -> KeywordId -> next -> AnnotationF next
[MarkOutside] :: AnnKeywordId -> KeywordId -> next -> AnnotationF next
[MarkInside] :: AnnKeywordId -> next -> AnnotationF next
[MarkMany] :: AnnKeywordId -> next -> AnnotationF next
[MarkManyOptional] :: AnnKeywordId -> next -> AnnotationF next
[MarkOffsetPrim] :: AnnKeywordId -> Int -> Maybe String -> next -> AnnotationF next
[MarkOffsetPrimOptional] :: AnnKeywordId -> Int -> Maybe String -> next -> AnnotationF next
[WithAST] :: (Data a, Data (SrcSpanLess a), HasSrcSpan a) => a -> Annotated b -> next -> AnnotationF next
[CountAnns] :: AnnKeywordId -> (Int -> next) -> AnnotationF next
[WithSortKey] :: [(SrcSpan, Annotated ())] -> next -> AnnotationF next
[SetLayoutFlag] :: Rigidity -> Annotated () -> next -> AnnotationF next
[MarkAnnBeforeAnn] :: AnnKeywordId -> AnnKeywordId -> next -> AnnotationF next
[StoreOriginalSrcSpan] :: SrcSpan -> AnnKey -> (AnnKey -> next) -> AnnotationF next
[GetSrcSpanForKw] :: SrcSpan -> AnnKeywordId -> (SrcSpan -> next) -> AnnotationF next
[AnnotationsToComments] :: [AnnKeywordId] -> next -> AnnotationF next
[SetContextLevel] :: Set AstContext -> Int -> Annotated () -> next -> AnnotationF next
[UnsetContext] :: AstContext -> Annotated () -> next -> AnnotationF next
[IfInContext] :: Set AstContext -> Annotated () -> Annotated () -> next -> AnnotationF next
[WithSortKeyContexts] :: ListContexts -> [(SrcSpan, Annotated ())] -> next -> AnnotationF next
[TellContext] :: Set AstContext -> next -> AnnotationF next
type Annotated = FreeT AnnotationF Identity
markEOF :: forall m_aHMR. MonadFree AnnotationF m_aHMR => m_aHMR ()
markPrim :: forall m_aIDp. MonadFree AnnotationF m_aIDp => AnnKeywordId -> Maybe String -> m_aIDp ()
markPPOptional :: forall m_aIEw. MonadFree AnnotationF m_aIEw => AnnKeywordId -> Maybe String -> m_aIEw ()
markInstead :: forall m_aIFD. MonadFree AnnotationF m_aIFD => AnnKeywordId -> KeywordId -> m_aIFD ()
markOutside :: forall m_aIGK. MonadFree AnnotationF m_aIGK => AnnKeywordId -> KeywordId -> m_aIGK ()
markInside :: forall m_aIHR. MonadFree AnnotationF m_aIHR => AnnKeywordId -> m_aIHR ()
markExternal :: forall m_aIIV. MonadFree AnnotationF m_aIIV => SrcSpan -> AnnKeywordId -> String -> m_aIIV ()
markMany :: forall m_aIK5. MonadFree AnnotationF m_aIK5 => AnnKeywordId -> m_aIK5 ()
markManyOptional :: forall m_aIL9. MonadFree AnnotationF m_aIL9 => AnnKeywordId -> m_aIL9 ()
markOffsetPrim :: forall m_aIMd. MonadFree AnnotationF m_aIMd => AnnKeywordId -> Int -> Maybe String -> m_aIMd ()
markOffsetPrimOptional :: forall m_aINn. MonadFree AnnotationF m_aINn => AnnKeywordId -> Int -> Maybe String -> m_aINn ()
countAnns :: forall m_aIOx. MonadFree AnnotationF m_aIOx => AnnKeywordId -> m_aIOx Int
storeOriginalSrcSpan :: forall m_aIPC. MonadFree AnnotationF m_aIPC => SrcSpan -> AnnKey -> m_aIPC AnnKey
getSrcSpanForKw :: forall m_aIQK. MonadFree AnnotationF m_aIQK => SrcSpan -> AnnKeywordId -> m_aIQK SrcSpan
annotationsToComments :: forall m_aIRS. MonadFree AnnotationF m_aIRS => [AnnKeywordId] -> m_aIRS ()
withSortKey :: forall m_aISW. MonadFree AnnotationF m_aISW => [(SrcSpan, Annotated ())] -> m_aISW ()
setContextLevel :: forall m_aIU0. MonadFree AnnotationF m_aIU0 => Set AstContext -> Int -> Annotated () -> m_aIU0 ()
unsetContext :: forall m_aIVa. MonadFree AnnotationF m_aIVa => AstContext -> Annotated () -> m_aIVa ()
ifInContext :: forall m_aIWh. MonadFree AnnotationF m_aIWh => Set AstContext -> Annotated () -> Annotated () -> m_aIWh ()
withSortKeyContexts :: forall m_aIXr. MonadFree AnnotationF m_aIXr => ListContexts -> [(SrcSpan, Annotated ())] -> m_aIXr ()
tellContext :: forall m_aIYy. MonadFree AnnotationF m_aIYy => Set AstContext -> m_aIYy ()
markAnnBeforeAnn :: forall m_aIZC. MonadFree AnnotationF m_aIZC => AnnKeywordId -> AnnKeywordId -> m_aIZC ()
setContext :: Set AstContext -> Annotated () -> Annotated ()
setLayoutFlag :: Annotated () -> Annotated ()
setRigidFlag :: Annotated () -> Annotated ()
inContext :: Set AstContext -> Annotated () -> Annotated ()

-- | Main driver point for annotations.
withAST :: (Data a, Data (SrcSpanLess a), HasSrcSpan a) => a -> Annotated () -> Annotated ()
mark :: AnnKeywordId -> Annotated ()
markOptional :: AnnKeywordId -> Annotated ()
markWithString :: AnnKeywordId -> String -> Annotated ()
markWithStringOptional :: AnnKeywordId -> String -> Annotated ()
markOffsetWithString :: AnnKeywordId -> Int -> String -> Annotated ()
markOffset :: AnnKeywordId -> Int -> Annotated ()
markOffsetOptional :: AnnKeywordId -> Int -> Annotated ()
markTrailingSemi :: Annotated ()
withLocated :: (Data a, Data (SrcSpanLess a), HasSrcSpan a) => a -> (SrcSpan -> a -> Annotated ()) -> Annotated ()
markListIntercalateWithFun :: (t -> Annotated ()) -> [t] -> Annotated ()
markListIntercalateWithFunLevel :: (t -> Annotated ()) -> Int -> [t] -> Annotated ()
markListIntercalateWithFunLevelCtx :: (t -> Annotated ()) -> Int -> AstContext -> [t] -> Annotated ()
markListWithContextsFunction :: ListContexts -> (t -> Annotated ()) -> [t] -> Annotated ()
withSortKeyContextsHelper :: Monad m => (Annotated () -> m ()) -> ListContexts -> [(SrcSpan, Annotated ())] -> m ()
applyListAnnotations :: [(SrcSpan, Annotated ())] -> Annotated ()
applyListAnnotationsContexts :: ListContexts -> [(SrcSpan, Annotated ())] -> Annotated ()
applyListAnnotationsLayout :: [(SrcSpan, Annotated ())] -> Annotated ()
listContexts :: ListContexts
listContexts' :: ListContexts
markAnnOpen :: SourceText -> String -> Annotated ()
markSourceText :: SourceText -> String -> Annotated ()
markExternalSourceText :: SrcSpan -> SourceText -> String -> Annotated ()
sourceTextToString :: SourceText -> String -> String
instance GHC.Base.Functor Language.Haskell.GHC.ExactPrint.AnnotateTypes.AnnotationF

module Language.Haskell.GHC.ExactPrint.Utils
ss2pos :: SrcSpan -> Pos
ss2posEnd :: SrcSpan -> Pos

-- | Apply the delta to the current position, taking into account the
--   current column offset if advancing to a new line
undelta :: Pos -> DeltaPos -> LayoutStartCol -> Pos

-- | Checks whether a SrcSpan has zero length.
isPointSrcSpan :: SrcSpan -> Bool

-- | Convert the start of the second <tt>Pos</tt> to be an offset from the
--   first. The assumption is the reference starts before the second
--   <tt>Pos</tt>
pos2delta :: Pos -> Pos -> DeltaPos

-- | Create a delta from the current position to the start of the given
--   <tt>SrcSpan</tt>.
ss2delta :: Pos -> SrcSpan -> DeltaPos

-- | Add together two <tt>DeltaPos</tt> taking into account newlines
--   
--   <pre>
--   DP (0, 1) `addDP` DP (0, 2) == DP (0, 3)
--   DP (0, 9) `addDP` DP (1, 5) == DP (1, 5)
--   DP (1, 4) `addDP` DP (1, 3) == DP (2, 3)
--   </pre>
addDP :: DeltaPos -> DeltaPos -> DeltaPos
spanLength :: SrcSpan -> Int

-- | A good delta has no negative values.
isGoodDelta :: DeltaPos -> Bool
mkComment :: String -> SrcSpan -> Comment

-- | Makes a comment which originates from a specific keyword.
mkKWComment :: AnnKeywordId -> SrcSpan -> Comment

-- | Calculates the distance from the start of a string to the end of a
--   string.
dpFromString :: String -> DeltaPos
comment2dp :: (Comment, DeltaPos) -> (KeywordId, DeltaPos)
extractComments :: ApiAnns -> [Comment]
srcSpanStartLine :: SrcSpan -> Int
srcSpanEndLine :: SrcSpan -> Int
srcSpanStartColumn :: SrcSpan -> Int
srcSpanEndColumn :: SrcSpan -> Int
rdrName2String :: RdrName -> String
isSymbolRdrName :: RdrName -> Bool
tokComment :: Located AnnotationComment -> Comment
isListComp :: HsStmtContext name -> Bool
isGadt :: [LConDecl name] -> Bool
isExactName :: Data name => name -> Bool
getAnnotationEP :: (Data a, Data (SrcSpanLess a), HasSrcSpan a) => a -> Anns -> Maybe Annotation

-- | The "true entry" is the distance from the last concrete element to the
--   start of the current element.
annTrueEntryDelta :: Annotation -> DeltaPos

-- | Take an annotation and a required "true entry" and calculate an
--   equivalent one relative to the last comment in the annPriorComments.
annCommentEntryDelta :: Annotation -> DeltaPos -> DeltaPos

-- | Return the DP of the first item that generates output, either a
--   comment or the entry DP
annLeadingCommentEntryDelta :: Annotation -> DeltaPos

-- | Given a list of items and a list of keys, returns a list of items
--   ordered by their position in the list of keys.
orderByKey :: [(SrcSpan, a)] -> [SrcSpan] -> [(SrcSpan, a)]

-- | Put the provided context elements into the existing set with fresh
--   level counts
setAcs :: Set AstContext -> AstContextSet -> AstContextSet

-- | Put the provided context elements into the existing set with given
--   level counts setAcsWithLevel :: Set.Set AstContext -&gt; Int -&gt;
--   AstContextSet -&gt; AstContextSet setAcsWithLevel ctxt level (ACS a) =
--   ACS a' where upd s (k,v) = Map.insert k v s a' = foldl' upd a $ zip
--   (Set.toList ctxt) (repeat level)
setAcsWithLevel :: Ord a => Set a -> Int -> ACS' a -> ACS' a

-- | Remove the provided context element from the existing set unsetAcs ::
--   AstContext -&gt; AstContextSet -&gt; AstContextSet
unsetAcs :: Ord a => a -> ACS' a -> ACS' a

-- | Are any of the contexts currently active? inAcs :: Set.Set AstContext
--   -&gt; AstContextSet -&gt; Bool
inAcs :: Ord a => Set a -> ACS' a -> Bool

-- | propagate the ACS down a level, dropping all values which hit zero
--   pushAcs :: AstContextSet -&gt; AstContextSet
pushAcs :: ACS' a -> ACS' a

-- | Sometimes we have to pass the context down unchanged. Bump each count
--   up by one so that it is unchanged after a <tt>pushAcs</tt> call.
--   bumpAcs :: AstContextSet -&gt; AstContextSet
bumpAcs :: ACS' a -> ACS' a

-- | Provide a version of trace that comes at the end of the line, so it
--   can easily be commented out when debugging different things.
debug :: c -> String -> c

-- | Provide a version of trace for the Pretty module, which can be enabled
--   separately from <a>debug</a> and <a>debugM</a>
debugP :: String -> c -> c
debugM :: Monad m => String -> m ()
warn :: c -> String -> c

-- | Show a GHC.Outputable structure
showGhc :: Outputable a => a -> String

-- | Show a GHC AST with interleaved Annotation information.
showAnnData :: Data a => Anns -> Int -> a -> String
occAttributes :: OccName -> String
showSDoc_ :: SDoc -> String
showSDocDebug_ :: SDoc -> String
ghead :: String -> [a] -> a
glast :: String -> [a] -> a
gtail :: String -> [a] -> [a]
gfromJust :: String -> Maybe a -> a


-- | This module is currently under heavy development, and no promises are
--   made about API stability. Use with care.
--   
--   We welcome any feedback / contributions on this, as it is the main
--   point of the library.
module Language.Haskell.GHC.ExactPrint.Transform

-- | Monad type for updating the AST and managing the annotations at the
--   same time. The W state is used to generate logging information if
--   required.
type Transform = TransformT Identity

-- | Monad transformer version of <a>Transform</a> monad
newtype TransformT m a
TransformT :: RWST () [String] (Anns, Int) m a -> TransformT m a
[unTransformT] :: TransformT m a -> RWST () [String] (Anns, Int) m a

-- | Change inner monad of <a>TransformT</a>.
hoistTransform :: (forall x. m x -> n x) -> TransformT m a -> TransformT n a

-- | Run a transformation in the <a>Transform</a> monad, returning the
--   updated annotations and any logging generated via <a>logTr</a>
runTransform :: Anns -> Transform a -> (a, (Anns, Int), [String])
runTransformT :: Anns -> TransformT m a -> m (a, (Anns, Int), [String])

-- | Run a transformation in the <a>Transform</a> monad, returning the
--   updated annotations and any logging generated via <a>logTr</a>,
--   allocating any new SrcSpans from the provided initial value.
runTransformFrom :: Int -> Anns -> Transform a -> (a, (Anns, Int), [String])

-- | Run a monad transformer stack for the <a>TransformT</a> monad
--   transformer
runTransformFromT :: Int -> Anns -> TransformT m a -> m (a, (Anns, Int), [String])

-- | Log a string to the output of the Monad
logTr :: Monad m => String -> TransformT m ()

-- | Log a representation of the given AST with annotations to the output
--   of the Monad
logDataWithAnnsTr :: Monad m => Data a => String -> a -> TransformT m ()

-- | Access the <a>Anns</a> being modified in this transformation
getAnnsT :: Monad m => TransformT m Anns

-- | Replace the <a>Anns</a> after any changes
putAnnsT :: Monad m => Anns -> TransformT m ()

-- | Change the stored <a>Anns</a>
modifyAnnsT :: Monad m => (Anns -> Anns) -> TransformT m ()

-- | Once we have <a>Anns</a>, a <a>SrcSpan</a> is used purely as part of
--   an <a>AnnKey</a> to index into the <a>Anns</a>. If we need to add new
--   elements to the AST, they need their own <a>SrcSpan</a> for this.
uniqueSrcSpanT :: Monad m => TransformT m SrcSpan

-- | Make a copy of an AST element, replacing the existing SrcSpans with
--   new ones, and duplicating the matching annotations.
cloneT :: (Data a, Monad m) => a -> TransformT m (a, [(SrcSpan, SrcSpan)])

-- | Slightly more general form of cloneT
graftT :: (Data a, Monad m) => Anns -> a -> TransformT m a

-- | <a>Transform</a> monad version of <a>getEntryDP</a>
getEntryDPT :: (Constraints a, Monad m) => a -> TransformT m DeltaPos

-- | <a>Transform</a> monad version of <a>getEntryDP</a>
setEntryDPT :: (Constraints a, Monad m) => a -> DeltaPos -> TransformT m ()

-- | <a>Transform</a> monad version of <a>transferEntryDP</a>
transferEntryDPT :: (Data a, Data b, Monad m) => Located a -> Located b -> TransformT m ()

-- | <a>Transform</a> monad version of <a>setPrecedingLinesDecl</a>
setPrecedingLinesDeclT :: Monad m => LHsDecl GhcPs -> Int -> Int -> TransformT m ()

-- | <a>Transform</a> monad version of <a>setPrecedingLines</a>
setPrecedingLinesT :: (Data a, Monad m) => Located a -> Int -> Int -> TransformT m ()

-- | Create a simple <a>Annotation</a> without comments, and attach it to
--   the first parameter.
addSimpleAnnT :: (Constraints a, Monad m) => a -> DeltaPos -> [(KeywordId, DeltaPos)] -> TransformT m ()

-- | Add a trailing comma annotation, unless there is already one
addTrailingCommaT :: (Data a, Monad m) => Located a -> TransformT m ()

-- | Remove a trailing comma annotation, if there is one one
removeTrailingCommaT :: (Data a, Monad m) => Located a -> TransformT m ()

-- | Used to integrate a <tt>Transform</tt> into other Monad stacks
class (Monad m) => HasTransform m
liftT :: HasTransform m => Transform a -> m a

-- | Provide a means to get and process the immediate child declartions of
--   a given AST element.
class (Data t) => HasDecls t

-- | Return the <a>HsDecl</a>s that are directly enclosed in the given
--   syntax phrase. They are always returned in the wrapped <a>HsDecl</a>
--   form, even if orginating in local decls. This is safe, as annotations
--   never attach to the wrapper, only to the wrapped item.
hsDecls :: (HasDecls t, Monad m) => t -> TransformT m [LHsDecl GhcPs]

-- | Replace the directly enclosed decl list by the given decl list. Runs
--   in the <a>Transform</a> monad to be able to update list order
--   annotations, and rebalance comments and other layout changes as
--   needed.
--   
--   For example, a call on replaceDecls for a wrapped <a>FunBind</a>
--   having no where clause will convert
--   
--   <pre>
--   -- |This is a function
--   foo = x -- comment1
--   </pre>
--   
--   in to
--   
--   <pre>
--   -- |This is a function
--   foo = x -- comment1
--     where
--       nn = 2
--   </pre>
replaceDecls :: (HasDecls t, Monad m) => t -> [LHsDecl GhcPs] -> TransformT m t

-- | Do a transformation on an AST fragment by providing a function to
--   process the general case and one specific for a <a>LHsBind</a>. This
--   is required because a <a>FunBind</a> may have multiple <a>Match</a>
--   items, so we cannot gurantee that <a>replaceDecls</a> after
--   <a>hsDecls</a> is idempotent.
hasDeclsSybTransform :: (Data t2, Monad m) => (forall t. HasDecls t => t -> m t) -> (LHsBind GhcPs -> m (LHsBind GhcPs)) -> t2 -> m t2

-- | A <a>FunBind</a> wraps up one or more <a>Match</a> items.
--   <a>hsDecls</a> cannot return anything for these as there is not
--   meaningful <a>replaceDecls</a> for it. This function provides a
--   version of <a>hsDecls</a> that returns the <a>FunBind</a> decls too,
--   where they are needed for analysis only.
hsDeclsGeneric :: (Data t, Monad m) => t -> TransformT m [LHsDecl GhcPs]

-- | Extract the immediate declarations for a <a>PatBind</a>. This cannot
--   be a member of <a>HasDecls</a> because a <a>FunBind</a> is not
--   idempotent for <a>hsDecls</a> / <a>replaceDecls</a>.
--   <a>hsDeclsPatBind</a> / <a>replaceDeclsPatBind</a> is idempotent.
hsDeclsPatBind :: Monad m => LHsBind GhcPs -> TransformT m [LHsDecl GhcPs]

-- | Extract the immediate declarations for a <a>PatBind</a> wrapped in a
--   <a>ValD</a>. This cannot be a member of <a>HasDecls</a> because a
--   <a>FunBind</a> is not idempotent for <a>hsDecls</a> /
--   <a>replaceDecls</a>. <a>hsDeclsPatBindD</a> /
--   <a>replaceDeclsPatBindD</a> is idempotent.
hsDeclsPatBindD :: Monad m => LHsDecl GhcPs -> TransformT m [LHsDecl GhcPs]

-- | Replace the immediate declarations for a <a>PatBind</a>. This cannot
--   be a member of <a>HasDecls</a> because a <a>FunBind</a> is not
--   idempotent for <a>hsDecls</a> / <a>replaceDecls</a>.
--   <a>hsDeclsPatBind</a> / <a>replaceDeclsPatBind</a> is idempotent.
replaceDeclsPatBind :: Monad m => LHsBind GhcPs -> [LHsDecl GhcPs] -> TransformT m (LHsBind GhcPs)

-- | Replace the immediate declarations for a <a>PatBind</a> wrapped in a
--   <a>ValD</a>. This cannot be a member of <a>HasDecls</a> because a
--   <a>FunBind</a> is not idempotent for <a>hsDecls</a> /
--   <a>replaceDecls</a>. <a>hsDeclsPatBindD</a> /
--   <a>replaceDeclsPatBindD</a> is idempotent.
replaceDeclsPatBindD :: Monad m => LHsDecl GhcPs -> [LHsDecl GhcPs] -> TransformT m (LHsDecl GhcPs)

-- | Apply a transformation to the decls contained in <tt>t</tt>
modifyDeclsT :: (HasDecls t, HasTransform m) => ([LHsDecl GhcPs] -> m [LHsDecl GhcPs]) -> t -> m t

-- | Modify a <a>LHsBind</a> wrapped in a <a>ValD</a>. For a <a>PatBind</a>
--   the declarations are extracted and returned after modification. For a
--   <a>FunBind</a> the supplied <a>SrcSpan</a> is used to identify the
--   specific <a>Match</a> to be transformed, for when there are multiple
--   of them.
modifyValD :: forall m t. HasTransform m => SrcSpan -> Decl -> (Match -> [Decl] -> m ([Decl], Maybe t)) -> m (Decl, Maybe t)

-- | Utility function for extracting decls from <a>HsLocalBinds</a>. Use
--   with care, as this does not necessarily return the declarations in
--   order, the ordering should be done by the calling function from the
--   <a>HsLocalBinds</a> context in the AST.
hsDeclsValBinds :: Monad m => HsLocalBinds GhcPs -> TransformT m [LHsDecl GhcPs]

-- | Utility function for returning decls to <a>HsLocalBinds</a>. Use with
--   care, as this does not manage the declaration order, the ordering
--   should be done by the calling function from the <a>HsLocalBinds</a>
--   context in the AST.
replaceDeclsValbinds :: Monad m => HsLocalBinds GhcPs -> [LHsDecl GhcPs] -> TransformT m (HsLocalBinds GhcPs)

-- | Insert a declaration at the beginning or end of the subdecls of the
--   given AST item
insertAtStart :: HasDecls (Located ast) => Located ast -> LHsDecl GhcPs -> Transform (Located ast)

-- | Insert a declaration at the beginning or end of the subdecls of the
--   given AST item
insertAtEnd :: HasDecls (Located ast) => Located ast -> LHsDecl GhcPs -> Transform (Located ast)

-- | Insert a declaration at a specific location in the subdecls of the
--   given AST item
insertAfter :: HasDecls (Located ast) => Located old -> Located ast -> LHsDecl GhcPs -> Transform (Located ast)

-- | Insert a declaration at a specific location in the subdecls of the
--   given AST item
insertBefore :: HasDecls (Located ast) => Located old -> Located ast -> LHsDecl GhcPs -> Transform (Located ast)

-- | The relatavise phase puts all comments appearing between the end of
--   one AST item and the beginning of the next as <a>annPriorComments</a>
--   for the second one. This function takes two adjacent AST items and
--   moves any <a>annPriorComments</a> from the second one to the
--   <a>annFollowingComments</a> of the first if they belong to it instead.
--   This is typically required before deleting or duplicating either of
--   the AST elements.
balanceComments :: (Data a, Data b, Monad m) => Located a -> Located b -> TransformT m ()

-- | After moving an AST element, make sure any comments that may belong
--   with the following element in fact do. Of necessity this is a
--   heuristic process, to be tuned later. Possibly a variant should be
--   provided with a passed-in decision function.
balanceTrailingComments :: Monad m => (Data a, Data b) => Located a -> Located b -> TransformT m [(Comment, DeltaPos)]

-- | Move any <a>annFollowingComments</a> values from the <a>Annotation</a>
--   associated to the first parameter to that of the second.
moveTrailingComments :: (Data a, Data b) => Located a -> Located b -> Transform ()

-- | If a list has been re-ordered or had items added, capture the new
--   order in the appropriate <a>annSortKey</a> attached to the
--   <a>Annotation</a> for the first parameter.
captureOrder :: Data a => Located a -> [Located b] -> Anns -> Anns

-- | If a list has been re-ordered or had items added, capture the new
--   order in the appropriate <a>annSortKey</a> item of the supplied
--   <a>AnnKey</a>
captureOrderAnnKey :: AnnKey -> [Located b] -> Anns -> Anns

-- | Test whether a given <a>SrcSpan</a> was generated by
--   <a>uniqueSrcSpanT</a>
isUniqueSrcSpan :: SrcSpan -> Bool

-- | Left bias pair union
mergeAnns :: Anns -> Anns -> Anns

-- | Combine a list of annotations
mergeAnnList :: [Anns] -> Anns

-- | Unwrap a HsDecl and call setPrecedingLines on it ++AZ++ TODO: get rid
--   of this, it is a synonym only
setPrecedingLinesDecl :: LHsDecl GhcPs -> Int -> Int -> Anns -> Anns

-- | Adjust the entry annotations to provide an <tt>n</tt> line preceding
--   gap
setPrecedingLines :: Data a => Located a -> Int -> Int -> Anns -> Anns

-- | Return the true entry <a>DeltaPos</a> from the annotation for a given
--   AST element. This is the <a>DeltaPos</a> ignoring any comments.
getEntryDP :: Constraints a => Anns -> a -> DeltaPos

-- | Set the true entry <a>DeltaPos</a> from the annotation for a given AST
--   element. This is the <a>DeltaPos</a> ignoring any comments.
setEntryDP :: Constraints a => a -> DeltaPos -> Anns -> Anns

-- | Take the annEntryDelta associated with the first item and associate it
--   with the second. Also transfer any comments occuring before it.
transferEntryDP :: (Data a, Data b) => Located a -> Located b -> Anns -> Anns
addTrailingComma :: Data a => Located a -> DeltaPos -> Anns -> Anns

-- | Convert a <a>LSig</a> into a <a>LHsDecl</a>
wrapSig :: LSig GhcPs -> LHsDecl GhcPs

-- | Convert a <a>LHsBind</a> into a <a>LHsDecl</a>
wrapDecl :: LHsBind GhcPs -> LHsDecl GhcPs

-- | Pure function to convert a <a>LSig</a> to a <a>LHsBind</a>. This does
--   nothing to any annotations that may be attached to either of the
--   elements. It is used as a utility function in <a>replaceDecls</a>
decl2Sig :: LHsDecl name -> [LSig name]

-- | Pure function to convert a <a>LHsDecl</a> to a <a>LHsBind</a>. This
--   does nothing to any annotations that may be attached to either of the
--   elements. It is used as a utility function in <a>replaceDecls</a>
decl2Bind :: LHsDecl name -> [LHsBind name]
instance Control.Monad.Trans.Class.MonadTrans Language.Haskell.GHC.ExactPrint.Transform.TransformT
instance GHC.Base.Monad m => Control.Monad.State.Class.MonadState (Language.Haskell.GHC.ExactPrint.Types.Anns, GHC.Types.Int) (Language.Haskell.GHC.ExactPrint.Transform.TransformT m)
instance GHC.Base.Monad m => Control.Monad.Writer.Class.MonadWriter [GHC.Base.String] (Language.Haskell.GHC.ExactPrint.Transform.TransformT m)
instance GHC.Base.Monad m => Control.Monad.Reader.Class.MonadReader () (Language.Haskell.GHC.ExactPrint.Transform.TransformT m)
instance GHC.Base.Functor m => GHC.Base.Functor (Language.Haskell.GHC.ExactPrint.Transform.TransformT m)
instance GHC.Base.Monad m => GHC.Base.Applicative (Language.Haskell.GHC.ExactPrint.Transform.TransformT m)
instance GHC.Base.Monad m => GHC.Base.Monad (Language.Haskell.GHC.ExactPrint.Transform.TransformT m)
instance GHC.Base.Monad m => Language.Haskell.GHC.ExactPrint.Transform.HasTransform (Language.Haskell.GHC.ExactPrint.Transform.TransformT m)
instance Language.Haskell.GHC.ExactPrint.Transform.HasDecls GHC.ParsedSource
instance Language.Haskell.GHC.ExactPrint.Transform.HasDecls (HsExpr.LMatch Language.Haskell.GHC.ExactPrint.Types.GhcPs (HsExpr.LHsExpr Language.Haskell.GHC.ExactPrint.Types.GhcPs))
instance Language.Haskell.GHC.ExactPrint.Transform.HasDecls (HsExpr.LHsExpr Language.Haskell.GHC.ExactPrint.Types.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Transform.HasDecls (HsExpr.LStmt Language.Haskell.GHC.ExactPrint.Types.GhcPs (HsExpr.LHsExpr Language.Haskell.GHC.ExactPrint.Types.GhcPs))
instance Control.Monad.Fail.MonadFail m => Control.Monad.Fail.MonadFail (Language.Haskell.GHC.ExactPrint.Transform.TransformT m)


-- | This module provides support for CPP, interpreter directives and line
--   pragmas.
module Language.Haskell.GHC.ExactPrint.Preprocess

-- | Remove GHC style line pragams (<tt>{--}</tt>) and convert them into
--   comments.
stripLinePragmas :: String -> (String, [Comment])

-- | Replacement for original <tt>getRichTokenStream</tt> which will return
--   the tokens for a file processed by CPP. See bug
--   <a>http://ghc.haskell.org/trac/ghc/ticket/8265</a>
getCppTokensAsComments :: GhcMonad m => CppOptions -> FilePath -> m [Comment]
getPreprocessedSrcDirect :: GhcMonad m => CppOptions -> FilePath -> m (String, DynFlags)
readFileGhc :: FilePath -> IO String
data CppOptions
CppOptions :: [String] -> [FilePath] -> [FilePath] -> CppOptions

-- | CPP #define macros
[cppDefine] :: CppOptions -> [String]

-- | CPP Includes directory
[cppInclude] :: CppOptions -> [FilePath]

-- | CPP pre-include file
[cppFile] :: CppOptions -> [FilePath]
defaultCppOptions :: CppOptions


-- | <a>annotate</a> is a function which given a GHC AST fragment,
--   constructs a syntax tree which indicates which annotations belong to
--   each specific part of the fragment.
--   
--   <a>Delta</a> and <a>Print</a> provide two interpreters for this
--   structure. You should probably use those unless you know what you're
--   doing!
--   
--   The functor <a>AnnotationF</a> has a number of constructors which
--   correspond to different sitations which annotations can arise. It is
--   hoped that in future versions of GHC these can be simplified by making
--   suitable modifications to the AST.
module Language.Haskell.GHC.ExactPrint.Annotater

-- | Construct a syntax tree which represent which KeywordIds must appear
--   where.
annotate :: (Annotate ast, Data (SrcSpanLess ast), HasSrcSpan ast) => ast -> Annotated ()

-- | <ul>
--   <li><i><a>MarkPrim</a></i> The main constructor. Marks that a specific
--   AnnKeywordId could appear with an optional String which is used when
--   printing.</li>
--   <li><i><a>MarkPPOptional</a></i> Used to flag elements, such as
--   optional braces, that are not used in the pretty printer. This
--   functions identically to <a>MarkPrim</a> for the other
--   interpreters.</li>
--   <li><i><a>MarkEOF</a></i> Special constructor which marks the end of
--   file marker.</li>
--   <li><i><a>MarkExternal</a></i> TODO</li>
--   <li><i><a>MarkOutside</a></i> A <tt>AnnKeywordId</tt> which is
--   precisely located but not inside the current context. This is usually
--   used to reassociated located <tt>RdrName</tt> which are more naturally
--   associated with their parent than in their own annotation.</li>
--   <li><i><a>MarkInside</a></i> The dual of MarkOutside. If we wish to
--   mark a non-separating comma or semi-colon then we must use this
--   constructor.</li>
--   <li><i><a>MarkMany</a></i> Some syntax elements allow an arbritary
--   number of puncuation marks without reflection in the AST. This
--   construction greedily takes all of the specified
--   <tt>AnnKeywordId</tt>.</li>
--   <li><i><a>MarkOffsetPrim</a></i> Some syntax elements have repeated
--   <tt>AnnKeywordId</tt> which are seperated by different
--   <tt>AnnKeywordId</tt>. Thus using MarkMany is unsuitable and instead
--   we provide an index to specify which specific instance to choose each
--   time.</li>
--   <li><i><a>WithAST</a></i> TODO</li>
--   <li><i><a>CountAnns</a></i> Sometimes the AST does not reflect the
--   concrete source code and the only way to tell what the concrete source
--   was is to count a certain kind of <tt>AnnKeywordId</tt>.</li>
--   <li><i><a>WithSortKey</a></i> There are many places where the
--   syntactic ordering of elements is thrown away by the AST. This
--   constructor captures the original ordering and reflects any changes in
--   ordered as specified by the <tt>annSortKey</tt> field in
--   <tt>Annotation</tt>.</li>
--   <li><i><a>SetLayoutFlag</a></i> It is important to know precisely
--   where layout rules apply. This constructor wraps a computation to
--   indicate that LayoutRules apply to the corresponding construct.</li>
--   <li><i><a>StoreOriginalSrcSpan</a></i> TODO</li>
--   <li><i><tt>GetSrcSpanFromKw</tt></i> TODO</li>
--   <li><i><tt>StoreString</tt></i> TODO</li>
--   <li><i><a>AnnotationsToComments</a></i> Used when the AST is
--   sufficiently vague that there is no other option but to convert a
--   fragment of source code into a comment. This means it is impossible to
--   edit such a fragment but means that processing files with such
--   fragments is still possible.</li>
--   </ul>
data AnnotationF next
[MarkPrim] :: AnnKeywordId -> Maybe String -> next -> AnnotationF next
[MarkPPOptional] :: AnnKeywordId -> Maybe String -> next -> AnnotationF next
[MarkEOF] :: next -> AnnotationF next
[MarkExternal] :: SrcSpan -> AnnKeywordId -> String -> next -> AnnotationF next
[MarkInstead] :: AnnKeywordId -> KeywordId -> next -> AnnotationF next
[MarkOutside] :: AnnKeywordId -> KeywordId -> next -> AnnotationF next
[MarkInside] :: AnnKeywordId -> next -> AnnotationF next
[MarkMany] :: AnnKeywordId -> next -> AnnotationF next
[MarkManyOptional] :: AnnKeywordId -> next -> AnnotationF next
[MarkOffsetPrim] :: AnnKeywordId -> Int -> Maybe String -> next -> AnnotationF next
[MarkOffsetPrimOptional] :: AnnKeywordId -> Int -> Maybe String -> next -> AnnotationF next
[WithAST] :: (Data a, Data (SrcSpanLess a), HasSrcSpan a) => a -> Annotated b -> next -> AnnotationF next
[CountAnns] :: AnnKeywordId -> (Int -> next) -> AnnotationF next
[WithSortKey] :: [(SrcSpan, Annotated ())] -> next -> AnnotationF next
[SetLayoutFlag] :: Rigidity -> Annotated () -> next -> AnnotationF next
[MarkAnnBeforeAnn] :: AnnKeywordId -> AnnKeywordId -> next -> AnnotationF next
[StoreOriginalSrcSpan] :: SrcSpan -> AnnKey -> (AnnKey -> next) -> AnnotationF next
[GetSrcSpanForKw] :: SrcSpan -> AnnKeywordId -> (SrcSpan -> next) -> AnnotationF next
[AnnotationsToComments] :: [AnnKeywordId] -> next -> AnnotationF next
[SetContextLevel] :: Set AstContext -> Int -> Annotated () -> next -> AnnotationF next
[UnsetContext] :: AstContext -> Annotated () -> next -> AnnotationF next
[IfInContext] :: Set AstContext -> Annotated () -> Annotated () -> next -> AnnotationF next
[WithSortKeyContexts] :: ListContexts -> [(SrcSpan, Annotated ())] -> next -> AnnotationF next
[TellContext] :: Set AstContext -> next -> AnnotationF next
type Annotated = FreeT AnnotationF Identity
class Data ast => Annotate ast
markAST :: Annotate ast => SrcSpan -> ast -> Annotated ()
withSortKeyContextsHelper :: Monad m => (Annotated () -> m ()) -> ListContexts -> [(SrcSpan, Annotated ())] -> m ()
instance Data.Data.Data Language.Haskell.GHC.ExactPrint.Annotater.WildCardAnon
instance GHC.Show.Show Language.Haskell.GHC.ExactPrint.Annotater.WildCardAnon
instance Data.Data.Data Language.Haskell.GHC.ExactPrint.Annotater.ResTyGADTHook
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate Language.Haskell.GHC.ExactPrint.Annotater.WildCardAnon
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.ConDecl HsExtension.GhcPs)
instance Outputable.Outputable Language.Haskell.GHC.ExactPrint.Annotater.ResTyGADTHook
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate Language.Haskell.GHC.ExactPrint.Annotater.ResTyGADTHook
instance (Data.Data.Data ast, Language.Haskell.GHC.ExactPrint.Annotater.Annotate ast) => Language.Haskell.GHC.ExactPrint.Annotater.Annotate (SrcLoc.Located ast)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsSyn.HsModule HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate BasicTypes.WarningTxt
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate BasicTypes.StringLiteral
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (BasicTypes.SourceText, FastString.FastString)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate [HsImpExp.LIE HsExtension.GhcPs]
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsImpExp.IE HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsImpExp.IEWrappedName RdrName.RdrName)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate RdrName.RdrName
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsImpExp.ImportDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate Module.ModuleName
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.HsDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.RoleAnnotDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (GHC.Maybe.Maybe CoAxiom.Role)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.SpliceDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.RuleDecls HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.RuleDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.RuleBndr HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.AnnDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.WarnDecls HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.WarnDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate FastString.FastString
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.ForeignDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate ForeignCall.CExportSpec
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate ForeignCall.CCallConv
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate ForeignCall.Safety
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.DerivDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.DerivStrategy HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.DefaultDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.InstDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate BasicTypes.OverlapMode
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.ClsInstDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.TyFamInstDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.DataFamInstDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsBinds.HsBind HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsBinds.IPBind HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate HsTypes.HsIPName
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate body => Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsExpr.Match HsExtension.GhcPs (SrcLoc.Located body))
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate body => Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsExpr.GRHS HsExtension.GhcPs (SrcLoc.Located body))
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsBinds.Sig HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate [HsTypes.LHsSigType HsExtension.GhcPs]
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate name => Language.Haskell.GHC.ExactPrint.Annotater.Annotate (BooleanFormula.BooleanFormula (SrcLoc.Located name))
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsTypes.HsTyVarBndr HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsTypes.HsType HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsExpr.HsSplice HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsTypes.ConDeclField HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsTypes.FieldOcc HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate HsDoc.HsDocString
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsPat.Pat HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate [HsTypes.LConDeclField HsExtension.GhcPs]
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsLit.HsOverLit HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate arg => Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsTypes.HsImplicitBndrs HsExtension.GhcPs (SrcLoc.Located arg))
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate body => Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsExpr.Stmt HsExtension.GhcPs (SrcLoc.Located body))
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsExpr.ParStmtBlock HsExtension.GhcPs HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsBinds.HsLocalBinds HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate body => Language.Haskell.GHC.ExactPrint.Annotater.Annotate [SrcLoc.Located (HsExpr.Match HsExtension.GhcPs (SrcLoc.Located body))]
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsExpr.HsExpr HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsLit.HsLit HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsPat.HsRecUpdField HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsTypes.AmbiguousFieldOcc HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate [HsExpr.ExprLStmt HsExtension.GhcPs]
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsExpr.HsTupArg HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsExpr.HsCmdTop HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsExpr.HsCmd HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate [SrcLoc.Located (HsExpr.StmtLR HsExtension.GhcPs HsExtension.GhcPs (HsExpr.LHsCmd HsExtension.GhcPs))]
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.TyClDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate [HsDecls.LHsDerivingClause HsExtension.GhcPs]
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.HsDerivingClause HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.FamilyDecl HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.FamilyResultSig HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.InjectivityAnn HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.TyFamInstEqn HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsDecls.TyFamDefltEqn HsExtension.GhcPs)
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate HsDecls.DocDecl
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate [HsTypes.LHsType HsExtension.GhcPs]
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsPat.HsRecField HsExtension.GhcPs (HsPat.LPat HsExtension.GhcPs))
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (HsPat.HsRecField HsExtension.GhcPs (HsExpr.LHsExpr HsExtension.GhcPs))
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate (Class.FunDep (SrcLoc.Located RdrName.RdrName))
instance Language.Haskell.GHC.ExactPrint.Annotater.Annotate ForeignCall.CType


-- | <a>annotate</a> is a function which given a GHC AST fragment,
--   constructs a syntax tree which indicates which annotations belong to
--   each specific part of the fragment.
--   
--   <a>Delta</a> and <a>Print</a> provide two interpreters for this
--   structure. You should probably use those unless you know what you're
--   doing!
--   
--   The functor <a>AnnotationF</a> has a number of constructors which
--   correspond to different sitations which annotations can arise. It is
--   hoped that in future versions of GHC these can be simplified by making
--   suitable modifications to the AST.
module Language.Haskell.GHC.ExactPrint.Annotate

-- | Construct a syntax tree which represent which KeywordIds must appear
--   where.
annotate :: (Annotate ast, Data (SrcSpanLess ast), HasSrcSpan ast) => ast -> Annotated ()

-- | <ul>
--   <li><i><a>MarkPrim</a></i> The main constructor. Marks that a specific
--   AnnKeywordId could appear with an optional String which is used when
--   printing.</li>
--   <li><i><a>MarkPPOptional</a></i> Used to flag elements, such as
--   optional braces, that are not used in the pretty printer. This
--   functions identically to <a>MarkPrim</a> for the other
--   interpreters.</li>
--   <li><i><a>MarkEOF</a></i> Special constructor which marks the end of
--   file marker.</li>
--   <li><i><a>MarkExternal</a></i> TODO</li>
--   <li><i><a>MarkOutside</a></i> A <tt>AnnKeywordId</tt> which is
--   precisely located but not inside the current context. This is usually
--   used to reassociated located <tt>RdrName</tt> which are more naturally
--   associated with their parent than in their own annotation.</li>
--   <li><i><a>MarkInside</a></i> The dual of MarkOutside. If we wish to
--   mark a non-separating comma or semi-colon then we must use this
--   constructor.</li>
--   <li><i><a>MarkMany</a></i> Some syntax elements allow an arbritary
--   number of puncuation marks without reflection in the AST. This
--   construction greedily takes all of the specified
--   <tt>AnnKeywordId</tt>.</li>
--   <li><i><a>MarkOffsetPrim</a></i> Some syntax elements have repeated
--   <tt>AnnKeywordId</tt> which are seperated by different
--   <tt>AnnKeywordId</tt>. Thus using MarkMany is unsuitable and instead
--   we provide an index to specify which specific instance to choose each
--   time.</li>
--   <li><i><a>WithAST</a></i> TODO</li>
--   <li><i><a>CountAnns</a></i> Sometimes the AST does not reflect the
--   concrete source code and the only way to tell what the concrete source
--   was is to count a certain kind of <tt>AnnKeywordId</tt>.</li>
--   <li><i><a>WithSortKey</a></i> There are many places where the
--   syntactic ordering of elements is thrown away by the AST. This
--   constructor captures the original ordering and reflects any changes in
--   ordered as specified by the <tt>annSortKey</tt> field in
--   <tt>Annotation</tt>.</li>
--   <li><i><a>SetLayoutFlag</a></i> It is important to know precisely
--   where layout rules apply. This constructor wraps a computation to
--   indicate that LayoutRules apply to the corresponding construct.</li>
--   <li><i><a>StoreOriginalSrcSpan</a></i> TODO</li>
--   <li><i><tt>GetSrcSpanFromKw</tt></i> TODO</li>
--   <li><i><tt>StoreString</tt></i> TODO</li>
--   <li><i><a>AnnotationsToComments</a></i> Used when the AST is
--   sufficiently vague that there is no other option but to convert a
--   fragment of source code into a comment. This means it is impossible to
--   edit such a fragment but means that processing files with such
--   fragments is still possible.</li>
--   </ul>
data AnnotationF next
[MarkPrim] :: AnnKeywordId -> Maybe String -> next -> AnnotationF next
[MarkPPOptional] :: AnnKeywordId -> Maybe String -> next -> AnnotationF next
[MarkEOF] :: next -> AnnotationF next
[MarkExternal] :: SrcSpan -> AnnKeywordId -> String -> next -> AnnotationF next
[MarkInstead] :: AnnKeywordId -> KeywordId -> next -> AnnotationF next
[MarkOutside] :: AnnKeywordId -> KeywordId -> next -> AnnotationF next
[MarkInside] :: AnnKeywordId -> next -> AnnotationF next
[MarkMany] :: AnnKeywordId -> next -> AnnotationF next
[MarkManyOptional] :: AnnKeywordId -> next -> AnnotationF next
[MarkOffsetPrim] :: AnnKeywordId -> Int -> Maybe String -> next -> AnnotationF next
[MarkOffsetPrimOptional] :: AnnKeywordId -> Int -> Maybe String -> next -> AnnotationF next
[WithAST] :: (Data a, Data (SrcSpanLess a), HasSrcSpan a) => a -> Annotated b -> next -> AnnotationF next
[CountAnns] :: AnnKeywordId -> (Int -> next) -> AnnotationF next
[WithSortKey] :: [(SrcSpan, Annotated ())] -> next -> AnnotationF next
[SetLayoutFlag] :: Rigidity -> Annotated () -> next -> AnnotationF next
[MarkAnnBeforeAnn] :: AnnKeywordId -> AnnKeywordId -> next -> AnnotationF next
[StoreOriginalSrcSpan] :: SrcSpan -> AnnKey -> (AnnKey -> next) -> AnnotationF next
[GetSrcSpanForKw] :: SrcSpan -> AnnKeywordId -> (SrcSpan -> next) -> AnnotationF next
[AnnotationsToComments] :: [AnnKeywordId] -> next -> AnnotationF next
[SetContextLevel] :: Set AstContext -> Int -> Annotated () -> next -> AnnotationF next
[UnsetContext] :: AstContext -> Annotated () -> next -> AnnotationF next
[IfInContext] :: Set AstContext -> Annotated () -> Annotated () -> next -> AnnotationF next
[WithSortKeyContexts] :: ListContexts -> [(SrcSpan, Annotated ())] -> next -> AnnotationF next
[TellContext] :: Set AstContext -> next -> AnnotationF next
type Annotated = FreeT AnnotationF Identity
class Data ast => Annotate ast
markAST :: Annotate ast => SrcSpan -> ast -> Annotated ()
withSortKeyContextsHelper :: Monad m => (Annotated () -> m ()) -> ListContexts -> [(SrcSpan, Annotated ())] -> m ()


-- | This module inverts the process performed by <a>Delta</a>. Given
--   <a>Anns</a> and a corresponding AST we produce a source file based on
--   this information.
module Language.Haskell.GHC.ExactPrint.Print

-- | Print an AST with a map of potential modified <a>Anns</a>. The usual
--   way to generate such a map is by using one of the parsers in
--   <a>Language.Haskell.GHC.ExactPrint.Parsers</a>.
exactPrint :: Annotate ast => Located ast -> Anns -> String

-- | The additional option to specify the rigidity and printing
--   configuration.
exactPrintWithOptions :: (Annotate ast, Monoid b, Monad m) => PrintOptions m b -> Located ast -> Anns -> m b
data PrintOptions m a

-- | Options which can be used to print as a normal String.
stringOptions :: PrintOptions Identity String

-- | Helper to create a <a>PrintOptions</a>
printOptions :: (forall ast. (Data ast, HasSrcSpan ast) => ast -> a -> m a) -> (String -> m a) -> (String -> m a) -> Rigidity -> PrintOptions m a
instance GHC.Base.Monoid w => GHC.Base.Semigroup (Language.Haskell.GHC.ExactPrint.Print.EPWriter w)
instance GHC.Base.Monoid w => GHC.Base.Monoid (Language.Haskell.GHC.ExactPrint.Print.EPWriter w)


-- | This module adds default annotations to an AST fragment that does not
--   have them, to be able to exactprint it in a way that preserves the
--   orginal AST when re-parsed.
module Language.Haskell.GHC.ExactPrint.Pretty

-- | Add any missing annotations so that the full AST element will
--   exactprint properly when done.
addAnnotationsForPretty :: Annotate a => [Comment] -> Located a -> Anns -> Anns
instance GHC.Show.Show Language.Haskell.GHC.ExactPrint.Pretty.PrettyOptions
instance GHC.Base.Semigroup Language.Haskell.GHC.ExactPrint.Pretty.PrettyWriter
instance GHC.Base.Monoid Language.Haskell.GHC.ExactPrint.Pretty.PrettyWriter


-- | This module converts <a>ApiAnns</a> into <a>Anns</a> by traversing a
--   structure created by the <a>Annotate</a> module.
--   
--   <h2>Structure of an Annotation</h2>
--   
--   As a rule of thumb, every located element in the GHC AST will have a
--   corresponding entry in <a>Anns</a>. An <a>Annotation</a> contains 6
--   fields which can be modifed to change how the AST is printed.
--   
--   <h2>Layout Calculation</h2>
--   
--   In order to properly place syntax nodes and comments properly after
--   refactoring them (in such a way that the indentation level changes),
--   their position (encoded in the <tt>addEntryDelta</tt> field) is not
--   expressed as absolute but relative to their context. As further
--   motivation, consider the simple let-into-where-block refactoring,
--   from:
--   
--   <pre>
--   foo = do
--     let bar = do
--           x
--           -- comment
--           y
--     bar
--   </pre>
--   
--   to
--   
--   <pre>
--   foo = do
--     bar
--    where
--     bar = do
--       x
--       -- comment
--       y
--   </pre>
--   
--   Notice how the column of <tt>x</tt>, <tt>y</tt> and the comment change
--   due to this refactoring but certain relative positions (e.g. the
--   comment starting at the same column as <tt>x</tt>) remain unchanged.
--   
--   Now, what does "context" mean exactly? Here we reference the
--   "indentation level" as used in the haskell report (see chapter 2.7:
--   <a>https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-210002.7</a>):
--   <tt>addEntryDelta</tt> is mostly relative to the current (inner-most)
--   indentation level. But in order to get better results, for the purpose
--   of defining relative positions a the offside-rule is modified
--   slightly: Normally it fires (only) at the first elements after
--   where<i>let</i>do/of, introducing a new indentation level. In
--   addition, the rule here fires also at the "<tt>let</tt>" keyword (when
--   it is part of a "<tt>let-in</tt>" construct) and at the "<tt>if</tt>"
--   keyword.
--   
--   The effect of this additional applications of the offside-rule is that
--   any elements (more or less directly) following the "<tt>let</tt>"
--   ("<tt>if</tt>"") keyword have a position relative to the
--   "<tt>let</tt>" ("<tt>if</tt>") keyword position, even when the regular
--   offside-rule does apply not yet/not anymore. This affects two concrete
--   things: Comments directly following "<tt>let</tt>"/"<tt>if</tt>", and
--   the respective follow-up keywords: "<tt>in</tt>" or
--   "<tt>then</tt>"/"<tt>else</tt>".
--   
--   Due to this additional indentation level, it is possible to
--   observe/obtain negative delta-positions; consider:
--   
--   <pre>
--   foo = let x = 1
--     in x
--   </pre>
--   
--   Here, the <tt>in</tt> keyword has an <a>annEntryDelta</a> of <tt>DP
--   (1, -4)</tt> as it appears one line below the previous elements and 4
--   columns <i>left</i> relative to the start of the <tt>let</tt> keyword.
--   
--   In general, the element that defines such an indentation level (i.e.
--   the first element after a where<i>let</i>do/of) will have an
--   <a>annEntryDelta</a> relative to the previous inner-most indentation
--   level; in other words: a new indentation level becomes relevant only
--   after the construct introducing the element received its
--   <a>annEntryDelta</a> position. (Otherwise these elements always would
--   have a zero horizontal position - relative to itself.)
--   
--   (This affects comments, too: A comment preceding the first element of
--   a layout block will have a position relative to the outer block, not
--   of the newly introduced layout block.)
--   
--   For example, in the following expression the statement corresponding
--   to <tt>baz</tt> will be given a <a>annEntryDelta</a> of <tt>DP (1,
--   2)</tt> as it appears 1 line and 2 columns after the <tt>do</tt>
--   keyword. On the other hand, <tt>bar</tt> will be given a
--   <a>annEntryDelta</a> of <tt>DP (1,0)</tt> as it appears 1 line further
--   than <tt>baz</tt> but in the same column as the start of the layout
--   block.
--   
--   <pre>
--   foo = do
--     baz
--     bar
--   </pre>
--   
--   A useful way to think of these rules is that the <a>DeltaPos</a> is
--   relative to the further left an expression could have been placed. In
--   the previous example, we could have placed <tt>baz</tt> anywhere on
--   the line as its position determines where the other statements must
--   be. <tt>bar</tt> could have not been placed any further left without
--   resulting in a syntax error which is why the relative column is 0.
--   
--   <h3>annTrueEntryDelta</h3>
--   
--   A very useful function is <a>annTrueEntryDelta</a> which calculates
--   the offset from the last syntactic element (ignoring comments). This
--   is different to <a>annEntryDelta</a> which does not ignore comments.
module Language.Haskell.GHC.ExactPrint.Delta

-- | Transform concrete annotations into relative annotations which are
--   more useful when transforming an AST.
relativiseApiAnns :: (Data (SrcSpanLess ast), Annotate ast, HasSrcSpan ast) => ast -> ApiAnns -> Anns

-- | Exactly the same as <a>relativiseApiAnns</a> but with the possibilty
--   to inject comments. This is typically used if the source has been
--   preprocessed by e.g. CPP, and the parts stripped out of the original
--   source are re-added as comments so they are not lost for round
--   tripping.
relativiseApiAnnsWithComments :: (Data (SrcSpanLess ast), Annotate ast, HasSrcSpan ast) => [Comment] -> ast -> ApiAnns -> Anns
relativiseApiAnnsWithOptions :: (Data (SrcSpanLess ast), Annotate ast, HasSrcSpan ast) => DeltaOptions -> [Comment] -> ast -> ApiAnns -> Anns
data DeltaOptions
deltaOptions :: Rigidity -> DeltaOptions
normalLayout :: DeltaOptions
instance GHC.Base.Semigroup Language.Haskell.GHC.ExactPrint.Delta.DeltaWriter
instance GHC.Base.Monoid Language.Haskell.GHC.ExactPrint.Delta.DeltaWriter


-- | This module rexposes wrapped parsers from the GHC API. Along with
--   returning the parse result, the corresponding annotations are also
--   returned such that it is then easy to modify the annotations and print
--   the result.
module Language.Haskell.GHC.ExactPrint.Parsers
type Parser a = DynFlags -> FilePath -> String -> Either (SrcSpan, String) (Anns, a)

-- | Provides a safe way to consume a properly initialised set of
--   <tt>DynFlags</tt>.
--   
--   <pre>
--   myParser fname expr = withDynFlags (\d -&gt; parseExpr d fname expr)
--   </pre>
withDynFlags :: (DynFlags -> a) -> IO a
data CppOptions
CppOptions :: [String] -> [FilePath] -> [FilePath] -> CppOptions

-- | CPP #define macros
[cppDefine] :: CppOptions -> [String]

-- | CPP Includes directory
[cppInclude] :: CppOptions -> [FilePath]

-- | CPP pre-include file
[cppFile] :: CppOptions -> [FilePath]
defaultCppOptions :: CppOptions

-- | This entry point will also work out which language extensions are
--   required and perform CPP processing if necessary.
--   
--   <pre>
--   parseModule = parseModuleWithCpp defaultCppOptions
--   </pre>
--   
--   Note: <a>ParsedSource</a> is a synonym for <a>Located</a>
--   (<a>HsModule</a> <a>GhcPs</a>)
parseModule :: FilePath -> IO (Either (SrcSpan, String) (Anns, ParsedSource))

-- | This entry point will work out which language extensions are required
--   but will _not_ perform CPP processing. In contrast to
--   <tt>parseModoule</tt> the input source is read from the provided
--   string; the <a>FilePath</a> parameter solely exists to provide a name
--   in source location annotations.
parseModuleFromString :: FilePath -> String -> IO (Either (SrcSpan, String) (Anns, ParsedSource))
parseModuleWithOptions :: DeltaOptions -> FilePath -> IO (Either (SrcSpan, String) (Anns, ParsedSource))

-- | Parse a module with specific instructions for the C pre-processor.
parseModuleWithCpp :: CppOptions -> DeltaOptions -> FilePath -> IO (Either (SrcSpan, String) (Anns, ParsedSource))
parseExpr :: Parser (LHsExpr GhcPs)
parseImport :: Parser (LImportDecl GhcPs)
parseType :: Parser (LHsType GhcPs)
parseDecl :: Parser (LHsDecl GhcPs)
parsePattern :: Parser (LPat GhcPs)
parseStmt :: Parser (ExprLStmt GhcPs)

-- | Wrapper function which returns Annotations along with the parsed
--   element.
parseWith :: (Data (SrcSpanLess w), Annotate w, HasSrcSpan w) => DynFlags -> FilePath -> P w -> String -> Either (SrcSpan, String) (Anns, w)

-- | Internal function. Default runner of GHC.Ghc action in IO.
ghcWrapper :: Ghc a -> IO a

-- | Internal function. Initializes DynFlags value for parsing.
--   
--   Passes "-hide-all-packages" to the GHC API to prevent parsing of
--   package environment files. However this only works if there is no
--   invocation of <tt>setSessionDynFlags</tt> before calling
--   <a>initDynFlags</a>. See ghc tickets 15541.
initDynFlags :: GhcMonad m => FilePath -> m DynFlags

-- | Requires GhcMonad constraint because there is no pure variant of
--   <tt>parseDynamicFilePragma</tt>. Yet, in constrast to
--   <a>initDynFlags</a>, it does not (try to) read the file at filepath,
--   but solely depends on the module source in the input string.
--   
--   Passes "-hide-all-packages" to the GHC API to prevent parsing of
--   package environment files. However this only works if there is no
--   invocation of <tt>setSessionDynFlags</tt> before calling
--   <a>initDynFlagsPure</a>. See ghc tickets 15541.
initDynFlagsPure :: GhcMonad m => FilePath -> String -> m DynFlags

-- | Internal part of <a>parseModuleFromString</a>.
parseModuleFromStringInternal :: DynFlags -> FilePath -> String -> Either (SrcSpan, String) (Anns, ParsedSource)

-- | Low level function which is used in the internal tests. It is advised
--   to use <a>parseModule</a> or <a>parseModuleWithCpp</a> instead of this
--   function.
parseModuleApiAnnsWithCpp :: CppOptions -> FilePath -> IO (Either (SrcSpan, String) (ApiAnns, [Comment], DynFlags, ParsedSource))

-- | Internal function. Exposed if you want to muck with DynFlags before
--   parsing.
parseModuleApiAnnsWithCppInternal :: GhcMonad m => CppOptions -> DynFlags -> FilePath -> m (Either (SrcSpan, String) (ApiAnns, [Comment], DynFlags, ParsedSource))

-- | Internal function. Exposed if you want to muck with DynFlags before
--   parsing. Or after parsing.
postParseTransform :: Either a (ApiAnns, [Comment], DynFlags, ParsedSource) -> DeltaOptions -> Either a (Anns, ParsedSource)


-- | <tt>ghc-exactprint</tt> is a library to manage manipulating Haskell
--   source files. There are four components.
module Language.Haskell.GHC.ExactPrint

-- | Transform concrete annotations into relative annotations which are
--   more useful when transforming an AST.
relativiseApiAnns :: (Data (SrcSpanLess ast), Annotate ast, HasSrcSpan ast) => ast -> ApiAnns -> Anns

-- | Exactly the same as <a>relativiseApiAnns</a> but with the possibilty
--   to inject comments. This is typically used if the source has been
--   preprocessed by e.g. CPP, and the parts stripped out of the original
--   source are re-added as comments so they are not lost for round
--   tripping.
relativiseApiAnnsWithComments :: (Data (SrcSpanLess ast), Annotate ast, HasSrcSpan ast) => [Comment] -> ast -> ApiAnns -> Anns

-- | This structure holds a complete set of annotations for an AST
type Anns = Map AnnKey Annotation

-- | A Haskell comment. The <tt>AnnKeywordId</tt> is present if it has been
--   converted from an <tt>AnnKeywordId</tt> because the annotation must be
--   interleaved into the stream and does not have a well-defined position
data Comment
data Annotation
Ann :: !DeltaPos -> ![(Comment, DeltaPos)] -> ![(Comment, DeltaPos)] -> ![(KeywordId, DeltaPos)] -> !Maybe [SrcSpan] -> !Maybe AnnKey -> Annotation

-- | Offset used to get to the start of the SrcSpan, from whatever the
--   prior output was, including all annPriorComments (field below).
[annEntryDelta] :: Annotation -> !DeltaPos

-- | Comments coming after the last non-comment output of the preceding
--   element but before the SrcSpan being annotated by this Annotation. If
--   these are changed then annEntryDelta (field above) must also change to
--   match.
[annPriorComments] :: Annotation -> ![(Comment, DeltaPos)]

-- | Comments coming after the last output for the element subject to this
--   Annotation. These will only be added by AST transformations, and care
--   must be taken not to disturb layout of following elements.
[annFollowingComments] :: Annotation -> ![(Comment, DeltaPos)]

-- | Annotations associated with this element.
[annsDP] :: Annotation -> ![(KeywordId, DeltaPos)]

-- | Captures the sort order of sub elements. This is needed when the
--   sub-elements have been split (as in a HsLocalBind which holds separate
--   binds and sigs) or for infix patterns where the order has been
--   re-arranged. It is captured explicitly so that after the Delta phase a
--   SrcSpan is used purely as an index into the annotations, allowing
--   transformations of the AST including the introduction of new Located
--   items or re-arranging existing ones.
[annSortKey] :: Annotation -> !Maybe [SrcSpan]

-- | Occasionally we must calculate a SrcSpan for an unlocated list of
--   elements which we must remember for the Print phase. e.g. the
--   statements in a HsLet or HsDo. These must be managed as a group
--   because they all need eo be vertically aligned for the Haskell layout
--   rules, and this guarantees this property in the presence of AST edits.
[annCapturedSpan] :: Annotation -> !Maybe AnnKey

-- | For every <tt>Located a</tt>, use the <tt>SrcSpan</tt> and constructor
--   name of a as the key, to store the standard annotation. These are used
--   to maintain context in the AP and EP monads
data AnnKey
AnnKey :: SrcSpan -> AnnConName -> AnnKey

-- | This entry point will also work out which language extensions are
--   required and perform CPP processing if necessary.
--   
--   <pre>
--   parseModule = parseModuleWithCpp defaultCppOptions
--   </pre>
--   
--   Note: <a>ParsedSource</a> is a synonym for <a>Located</a>
--   (<a>HsModule</a> <a>GhcPs</a>)
parseModule :: FilePath -> IO (Either (SrcSpan, String) (Anns, ParsedSource))

-- | Add any missing annotations so that the full AST element will
--   exactprint properly when done.
addAnnotationsForPretty :: Annotate a => [Comment] -> Located a -> Anns -> Anns

-- | Print an AST with a map of potential modified <a>Anns</a>. The usual
--   way to generate such a map is by using one of the parsers in
--   <a>Language.Haskell.GHC.ExactPrint.Parsers</a>.
exactPrint :: Annotate ast => Located ast -> Anns -> String
