Safe Haskell | None |
---|---|
Language | Haskell2010 |
annotate
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.
Delta and Print provide two interpreters for this structure. You should probably use those unless you know what you're doing!
The functor AnnotationF
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.
Synopsis
- data AnnotationF next where
- 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. MonadFree AnnotationF m => m ()
- markPrim :: forall m. MonadFree AnnotationF m => AnnKeywordId -> Maybe String -> m ()
- markPPOptional :: forall m. MonadFree AnnotationF m => AnnKeywordId -> Maybe String -> m ()
- markInstead :: forall m. MonadFree AnnotationF m => AnnKeywordId -> KeywordId -> m ()
- markOutside :: forall m. MonadFree AnnotationF m => AnnKeywordId -> KeywordId -> m ()
- markInside :: forall m. MonadFree AnnotationF m => AnnKeywordId -> m ()
- markExternal :: forall m. MonadFree AnnotationF m => SrcSpan -> AnnKeywordId -> String -> m ()
- markMany :: forall m. MonadFree AnnotationF m => AnnKeywordId -> m ()
- markManyOptional :: forall m. MonadFree AnnotationF m => AnnKeywordId -> m ()
- markOffsetPrim :: forall m. MonadFree AnnotationF m => AnnKeywordId -> Int -> Maybe String -> m ()
- markOffsetPrimOptional :: forall m. MonadFree AnnotationF m => AnnKeywordId -> Int -> Maybe String -> m ()
- countAnns :: forall m. MonadFree AnnotationF m => AnnKeywordId -> m Int
- storeOriginalSrcSpan :: forall m. MonadFree AnnotationF m => SrcSpan -> AnnKey -> m AnnKey
- getSrcSpanForKw :: forall m. MonadFree AnnotationF m => SrcSpan -> AnnKeywordId -> m SrcSpan
- annotationsToComments :: forall m. MonadFree AnnotationF m => [AnnKeywordId] -> m ()
- withSortKey :: forall m. MonadFree AnnotationF m => [(SrcSpan, Annotated ())] -> m ()
- setContextLevel :: forall m. MonadFree AnnotationF m => Set AstContext -> Int -> Annotated () -> m ()
- unsetContext :: forall m. MonadFree AnnotationF m => AstContext -> Annotated () -> m ()
- ifInContext :: forall m. MonadFree AnnotationF m => Set AstContext -> Annotated () -> Annotated () -> m ()
- withSortKeyContexts :: forall m. MonadFree AnnotationF m => ListContexts -> [(SrcSpan, Annotated ())] -> m ()
- tellContext :: forall m. MonadFree AnnotationF m => Set AstContext -> m ()
- markAnnBeforeAnn :: forall m. MonadFree AnnotationF m => AnnKeywordId -> AnnKeywordId -> m ()
- setContext :: Set AstContext -> Annotated () -> Annotated ()
- setLayoutFlag :: Annotated () -> Annotated ()
- setRigidFlag :: Annotated () -> Annotated ()
- inContext :: Set AstContext -> Annotated () -> Annotated ()
- 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
Documentation
data AnnotationF next where Source #
MarkPrim
- The main constructor. Marks that a specific AnnKeywordId could appear with an optional String which is used when printing.
MarkPPOptional
- Used to flag elements, such as optional braces, that are
not used in the pretty printer. This functions identically to
MarkPrim
for the other interpreters. MarkEOF
- Special constructor which marks the end of file marker.
MarkExternal
- TODO
MarkOutside
- A
AnnKeywordId
which is precisely located but not inside the current context. This is usually used to reassociated locatedRdrName
which are more naturally associated with their parent than in their own annotation. MarkInside
- The dual of MarkOutside. If we wish to mark a non-separating comma or semi-colon then we must use this constructor.
MarkMany
- Some syntax elements allow an arbritary number of puncuation marks
without reflection in the AST. This construction greedily takes all of
the specified
AnnKeywordId
. MarkOffsetPrim
- Some syntax elements have repeated
AnnKeywordId
which are seperated by differentAnnKeywordId
. Thus using MarkMany is unsuitable and instead we provide an index to specify which specific instance to choose each time. WithAST
- TODO
CountAnns
- 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
AnnKeywordId
. WithSortKey
- 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
annSortKey
field inAnnotation
. SetLayoutFlag
- It is important to know precisely where layout rules apply. This constructor wraps a computation to indicate that LayoutRules apply to the corresponding construct.
StoreOriginalSrcSpan
- TODO
GetSrcSpanFromKw
- TODO
StoreString
- TODO
AnnotationsToComments
- 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.
Instances
Functor AnnotationF Source # | |
Defined in Language.Haskell.GHC.ExactPrint.AnnotateTypes fmap :: (a -> b) -> AnnotationF a -> AnnotationF b # (<$) :: a -> AnnotationF b -> AnnotationF a # |
markEOF :: forall m. MonadFree AnnotationF m => m () Source #
markPrim :: forall m. MonadFree AnnotationF m => AnnKeywordId -> Maybe String -> m () Source #
markPPOptional :: forall m. MonadFree AnnotationF m => AnnKeywordId -> Maybe String -> m () Source #
markInstead :: forall m. MonadFree AnnotationF m => AnnKeywordId -> KeywordId -> m () Source #
markOutside :: forall m. MonadFree AnnotationF m => AnnKeywordId -> KeywordId -> m () Source #
markInside :: forall m. MonadFree AnnotationF m => AnnKeywordId -> m () Source #
markExternal :: forall m. MonadFree AnnotationF m => SrcSpan -> AnnKeywordId -> String -> m () Source #
markMany :: forall m. MonadFree AnnotationF m => AnnKeywordId -> m () Source #
markManyOptional :: forall m. MonadFree AnnotationF m => AnnKeywordId -> m () Source #
markOffsetPrim :: forall m. MonadFree AnnotationF m => AnnKeywordId -> Int -> Maybe String -> m () Source #
markOffsetPrimOptional :: forall m. MonadFree AnnotationF m => AnnKeywordId -> Int -> Maybe String -> m () Source #
countAnns :: forall m. MonadFree AnnotationF m => AnnKeywordId -> m Int Source #
storeOriginalSrcSpan :: forall m. MonadFree AnnotationF m => SrcSpan -> AnnKey -> m AnnKey Source #
getSrcSpanForKw :: forall m. MonadFree AnnotationF m => SrcSpan -> AnnKeywordId -> m SrcSpan Source #
annotationsToComments :: forall m. MonadFree AnnotationF m => [AnnKeywordId] -> m () Source #
withSortKey :: forall m. MonadFree AnnotationF m => [(SrcSpan, Annotated ())] -> m () Source #
setContextLevel :: forall m. MonadFree AnnotationF m => Set AstContext -> Int -> Annotated () -> m () Source #
unsetContext :: forall m. MonadFree AnnotationF m => AstContext -> Annotated () -> m () Source #
ifInContext :: forall m. MonadFree AnnotationF m => Set AstContext -> Annotated () -> Annotated () -> m () Source #
withSortKeyContexts :: forall m. MonadFree AnnotationF m => ListContexts -> [(SrcSpan, Annotated ())] -> m () Source #
tellContext :: forall m. MonadFree AnnotationF m => Set AstContext -> m () Source #
markAnnBeforeAnn :: forall m. MonadFree AnnotationF m => AnnKeywordId -> AnnKeywordId -> m () Source #
setContext :: Set AstContext -> Annotated () -> Annotated () Source #
setLayoutFlag :: Annotated () -> Annotated () Source #
setRigidFlag :: Annotated () -> Annotated () Source #
withAST :: (Data a, Data (SrcSpanLess a), HasSrcSpan a) => a -> Annotated () -> Annotated () Source #
Main driver point for annotations.
mark :: AnnKeywordId -> Annotated () Source #
markOptional :: AnnKeywordId -> Annotated () Source #
markWithString :: AnnKeywordId -> String -> Annotated () Source #
markWithStringOptional :: AnnKeywordId -> String -> Annotated () Source #
markOffsetWithString :: AnnKeywordId -> Int -> String -> Annotated () Source #
markOffset :: AnnKeywordId -> Int -> Annotated () Source #
markOffsetOptional :: AnnKeywordId -> Int -> Annotated () Source #
markTrailingSemi :: Annotated () Source #
withLocated :: (Data a, Data (SrcSpanLess a), HasSrcSpan a) => a -> (SrcSpan -> a -> Annotated ()) -> Annotated () Source #
markListIntercalateWithFun :: (t -> Annotated ()) -> [t] -> Annotated () Source #
markListIntercalateWithFunLevelCtx :: (t -> Annotated ()) -> Int -> AstContext -> [t] -> Annotated () Source #
markListWithContextsFunction :: ListContexts -> (t -> Annotated ()) -> [t] -> Annotated () Source #
withSortKeyContextsHelper :: Monad m => (Annotated () -> m ()) -> ListContexts -> [(SrcSpan, Annotated ())] -> m () Source #
applyListAnnotationsContexts :: ListContexts -> [(SrcSpan, Annotated ())] -> Annotated () Source #
markAnnOpen :: SourceText -> String -> Annotated () Source #
markSourceText :: SourceText -> String -> Annotated () Source #
markExternalSourceText :: SrcSpan -> SourceText -> String -> Annotated () Source #
sourceTextToString :: SourceText -> String -> String Source #