ghc-exactprint-0.5.0.0: ExactPrint for GHC

Safe HaskellNone
LanguageHaskell2010

Language.Haskell.GHC.ExactPrint.Annotate

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 => Located 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.
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 
MarkEOF :: next -> AnnotationF next 
MarkExternal :: SrcSpan -> AnnKeywordId -> String -> next -> AnnotationF next 
MarkOutside :: AnnKeywordId -> KeywordId -> next -> AnnotationF next 
MarkInside :: AnnKeywordId -> next -> AnnotationF next 
MarkMany :: AnnKeywordId -> next -> AnnotationF next 
MarkOffsetPrim :: 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 
StoreOriginalSrcSpan :: AnnKey -> (AnnKey -> next) -> AnnotationF next 
GetSrcSpanForKw :: AnnKeywordId -> (SrcSpan -> next) -> AnnotationF next 
StoreString :: String -> SrcSpan -> next -> AnnotationF next 
AnnotationsToComments :: [AnnKeywordId] -> next -> AnnotationF next 

class Data ast => Annotate ast where Source

Methods

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

Instances

Annotate DocDecl Source 
Annotate HsIPName Source 
Annotate HsLit Source 
Annotate RdrName Source 
Annotate HsDocString Source 
Annotate Safety Source 
Annotate CExportSpec Source 
Annotate CCallConv Source 
Annotate CType Source 
Annotate WarningTxt Source 
Annotate OverlapMode Source 
Annotate Name Source 
Annotate FastString Source 
Annotate ModuleName Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate [ExprLStmt name] Source

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

(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate [LHsType name] Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate [LConDeclField name] Source 
(DataId name, Annotate name) => Annotate [LIE name] Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name, Annotate body) => Annotate [Located (Match name (Located body))] Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate [Located (StmtLR name name (LHsCmd name))] Source 
Annotate (Maybe Role) Source 
Annotate (HsModule RdrName) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (HsTupArg name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (HsCmdTop name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (HsDecl name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (SpliceDecl name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (TyClDecl name) Source 
(DataId name, Annotate name, OutputableBndr name, HasOccName name) => Annotate (FamilyDecl name) Source 
(DataId name, Annotate name, OutputableBndr name, HasOccName name) => Annotate (ConDecl name) Source 
(DataId name, Annotate name, OutputableBndr name, HasOccName name) => Annotate (TyFamInstEqn name) Source 
(DataId name, Annotate name, OutputableBndr name, HasOccName name) => Annotate (TyFamDefltEqn name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (TyFamInstDecl name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (DataFamInstDecl name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (ClsInstDecl name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (InstDecl name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (DerivDecl name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (DefaultDecl name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (ForeignDecl name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (RuleDecls name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (RuleDecl name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (RuleBndr name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (VectDecl name) Source 
Annotate name => Annotate (WarnDecls name) Source 
Annotate name => Annotate (WarnDecl name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (AnnDecl name) Source 
Annotate name => Annotate (RoleAnnotDecl name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (HsLocalBinds name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (HsBind name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (IPBind name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (Sig name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (HsQuasiQuote name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (HsTyVarBndr name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (HsType name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (ConDeclField name) Source 
DataId name => Annotate (HsOverLit name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (HsExpr name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (HsCmd name) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (HsSplice name) Source 
(DataId name, Annotate name, OutputableBndr name, HasOccName name) => Annotate (Pat name) Source 
(DataId name, Annotate name) => Annotate (FunDep (Located name)) Source 
(DataId name, Annotate name) => Annotate (ImportDecl name) Source 
(DataId name, Annotate name) => Annotate (IE name) Source 
Annotate name => Annotate (BooleanFormula (Located name)) Source 
Annotate (SourceText, FastString) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name, Annotate body) => Annotate (Match name (Located body)) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name, Annotate body) => Annotate (GRHS name (Located body)) Source 
(DataId name, OutputableBndr name, Annotate name, HasOccName name, Annotate body) => Annotate (Stmt name (Located body)) Source 
(DataId name, OutputableBndr name, HasOccName name, Annotate name) => Annotate (ParStmtBlock name name) Source 
(Annotate name, DataId name, OutputableBndr name, HasOccName name) => Annotate (HsRecField name (LHsExpr name)) Source 
(Annotate name, DataId name, OutputableBndr name, HasOccName name) => Annotate (HsRecField name (LPat name)) Source 
(DataId name, Annotate arg) => Annotate (HsWithBndrs name (Located arg)) Source