ghc-exactprint-0.6.2: 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 ModuleName Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate FastString Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate DocDecl Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate HsDocString Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate HsIPName Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate RdrName Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate CCallConv Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate WarningTxt Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate OverlapMode Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

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

Methods

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

Annotate CExportSpec Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate Safety Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> Safety -> 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

Methods

markAST :: SrcSpan -> [Located (StmtLR GhcPs GhcPs (LHsCmd GhcPs))] -> Annotated () Source #

Annotate [LHsDerivingClause GhcPs] Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

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

Methods

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

Annotate [LIE GhcPs] Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate [LConDeclField GhcPs] Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate [LHsSigType GhcPs] Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate [LHsType GhcPs] Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (Maybe Role) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> Maybe Role -> Annotated () Source #

(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 (HsBind GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (HsLocalBinds GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (IPBind GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (Sig GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (AnnDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (ClsInstDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (ConDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (DataFamInstDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (DefaultDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (DerivDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (DerivStrategy GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (FamilyDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (FamilyResultSig GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (ForeignDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (HsDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (HsDerivingClause GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (InjectivityAnn GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (InstDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (RoleAnnotDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (RuleBndr GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (RuleDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (RuleDecls GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (SpliceDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (TyClDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (TyFamDefltEqn GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (TyFamInstDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (TyFamInstEqn GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (WarnDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (WarnDecls GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (HsCmd GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (HsCmdTop GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (HsExpr GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (HsSplice GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (HsTupArg GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (IE GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (IEWrappedName RdrName) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> IEWrappedName RdrName -> Annotated () Source #

Annotate (ImportDecl GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (HsLit GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (HsOverLit GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (HsRecUpdField GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (Pat GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (HsModule GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (AmbiguousFieldOcc GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (ConDeclField GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (FieldOcc GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (HsTyVarBndr GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (HsType GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

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

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> BooleanFormula (Located name) -> Annotated () Source #

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

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> FunDep (Located RdrName) -> Annotated () Source #

Annotate (SourceText, FastString) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> (SourceText, FastString) -> 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 (Match GhcPs (Located body)) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

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

Annotate (ParStmtBlock GhcPs GhcPs) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> ParStmtBlock GhcPs GhcPs -> 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 (HsRecField GhcPs (LHsExpr GhcPs)) Source # 
Instance details

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> HsRecField GhcPs (LHsExpr GhcPs) -> Annotated () Source #

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

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> HsRecField GhcPs (LPat GhcPs) -> Annotated () Source #

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

Defined in Language.Haskell.GHC.ExactPrint.Annotater

Methods

markAST :: SrcSpan -> HsImplicitBndrs GhcPs (Located arg) -> Annotated () Source #

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