ghc-exactprint- ExactPrint for GHC

Safe HaskellNone



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.



data AnnotationF next where Source #

The main constructor. Marks that a specific AnnKeywordId could appear with an optional String which is used when printing.
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.
Special constructor which marks the end of file marker.
A AnnKeywordId which is precisely located but not inside the current context. This is usually used to reassociated located RdrName which are more naturally associated with their parent than in their own annotation.
The dual of MarkOutside. If we wish to mark a non-separating comma or semi-colon then we must use this constructor.
Some syntax elements allow an arbritary number of puncuation marks without reflection in the AST. This construction greedily takes all of the specified AnnKeywordId.
Some syntax elements have repeated AnnKeywordId which are seperated by different AnnKeywordId. Thus using MarkMany is unsuitable and instead we provide an index to specify which specific instance to choose each time.
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.
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 in Annotation.
It is important to know precisely where layout rules apply. This constructor wraps a computation to indicate that LayoutRules apply to the corresponding construct.
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.


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 => Located 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 
Functor AnnotationF Source # 
Instance details

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 #

withSortKey :: forall m. MonadFree AnnotationF m => [(SrcSpan, Annotated ())] -> m () Source #

ifInContext :: forall m. MonadFree AnnotationF m => Set AstContext -> Annotated () -> Annotated () -> m () Source #

withAST :: Data a => Located a -> Annotated () -> Annotated () Source #

Main driver point for annotations.

withLocated :: Data a => Located a -> (SrcSpan -> a -> Annotated ()) -> Annotated () Source #

withSortKeyContextsHelper :: Monad m => (Annotated () -> m ()) -> ListContexts -> [(SrcSpan, Annotated ())] -> m () Source #