ghc-exactprint-0.6.3.3: ExactPrint for GHC
Safe HaskellNone
LanguageHaskell2010

Language.Haskell.GHC.ExactPrint.Annotater

Description

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

Documentation

annotate :: (Annotate ast, Data (SrcSpanLess ast), HasSrcSpan ast) => ast -> Annotated () Source #

Construct a syntax tree which represent which KeywordIds must appear where.

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 located RdrName 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 different AnnKeywordId. 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 in Annotation.
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.

Constructors

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 

Instances

Instances details
Functor AnnotationF Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.AnnotateTypes

Methods

fmap :: (a -> b) -> AnnotationF a -> AnnotationF b #

(<$) :: a -> AnnotationF b -> AnnotationF a #

class Data ast => Annotate ast where Source #

Methods

markAST :: SrcSpan -> ast -> Annotated () Source #

Instances

Instances details
Annotate DocDecl Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate HsIPName Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate RdrName Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate HsDocString Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate Safety Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> Safety -> Annotated () Source #

Annotate CExportSpec Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate CCallConv Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate CType Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> CType -> Annotated () Source #

Annotate StringLiteral Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate WarningTxt Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate OverlapMode Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate ModuleName Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate FastString Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate [ExprLStmt GhcPs] Source #

Used for declarations that need to be aligned together, e.g. in a do or let .. in statement/expr

Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate [LHsDerivingClause GhcPs] Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate [LHsType GhcPs] Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate [LHsSigType GhcPs] Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate [LConDeclField GhcPs] Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate [LIE GhcPs] Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> [LIE GhcPs] -> Annotated () Source #

Annotate body => Annotate [Located (Match GhcPs (Located body))] Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> [Located (Match GhcPs (Located body))] -> Annotated () Source #

Annotate [Located (StmtLR GhcPs GhcPs (LHsCmd GhcPs))] Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (Maybe Role) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsModule GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsTupArg GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsCmdTop GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (SpliceDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (TyClDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (FamilyResultSig GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (FamilyDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (InjectivityAnn GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsDerivingClause GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (StandaloneKindSig GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (ConDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (TyFamInstEqn GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (TyFamInstDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (DataFamInstDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (ClsInstDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (InstDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (DerivDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (DerivStrategy GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (DefaultDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (ForeignDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (RuleDecls GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (RuleDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (RuleBndr GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (WarnDecls GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (WarnDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (AnnDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (RoleAnnotDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsRecUpdField GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsLocalBinds GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsBind GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (IPBind GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (Sig GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsTyVarBndr GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsType GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (ConDeclField GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (FieldOcc GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (AmbiguousFieldOcc GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsLit GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsOverLit GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (FunDep (Located RdrName)) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsExpr GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsCmd GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsSplice GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (ImportDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (IEWrappedName RdrName) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (IE GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> IE GhcPs -> Annotated () Source #

Annotate (Pat GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate name => Annotate (BooleanFormula (Located name)) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

(Data ast, Annotate ast) => Annotate (Located ast) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> Located ast -> Annotated () Source #

Annotate (SourceText, FastString) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate body => Annotate (Match GhcPs (Located body)) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> Match GhcPs (Located body) -> Annotated () Source #

Annotate body => Annotate (GRHS GhcPs (Located body)) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> GRHS GhcPs (Located body) -> Annotated () Source #

Annotate body => Annotate (Stmt GhcPs (Located body)) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> Stmt GhcPs (Located body) -> Annotated () Source #

Annotate (ParStmtBlock GhcPs GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsRecField GhcPs (LHsExpr GhcPs)) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate (HsRecField GhcPs (Located (Pat GhcPs))) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Annotate arg => Annotate (HsImplicitBndrs GhcPs (Located arg)) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

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