ApiAnnotation

ghc-8.4.4: The GHC API

Safe Haskell | None
Language | Haskell2010

ApiAnnotation

Synopsis

- getAnnotation :: ApiAnns -> SrcSpan -> AnnKeywordId -> [SrcSpan]
- getAndRemoveAnnotation :: ApiAnns -> SrcSpan -> AnnKeywordId -> ([SrcSpan], ApiAnns)
- getAnnotationComments :: ApiAnns -> SrcSpan -> [Located AnnotationComment]
- getAndRemoveAnnotationComments :: ApiAnns -> SrcSpan -> ([Located AnnotationComment], ApiAnns)
- type ApiAnns = (Map ApiAnnKey [SrcSpan], Map SrcSpan [Located AnnotationComment])
- type ApiAnnKey = (SrcSpan, AnnKeywordId)
- data AnnKeywordId
  - = AnnAnyclass
  - | AnnAs
  - | AnnAt
  - | AnnBang
  - | AnnBackquote
  - | AnnBy
  - | AnnCase
  - | AnnClass
  - | AnnClose
  - | AnnCloseB
  - | AnnCloseBU
  - | AnnCloseC
  - | AnnCloseQ
  - | AnnCloseQU
  - | AnnCloseP
  - | AnnCloseS
  - | AnnColon
  - | AnnComma
  - | AnnCommaTuple
  - | AnnDarrow
  - | AnnDarrowU
  - | AnnData
  - | AnnDcolon
  - | AnnDcolonU
  - | AnnDefault
  - | AnnDeriving
  - | AnnDo
  - | AnnDot
  - | AnnDotdot
  - | AnnElse
  - | AnnEqual
  - | AnnExport
  - | AnnFamily
  - | AnnForall
  - | AnnForallU
  - | AnnForeign
  - | AnnFunId
  - | AnnGroup
  - | AnnHeader
  - | AnnHiding
  - | AnnIf
  - | AnnImport
  - | AnnIn
  - | AnnInfix
  - | AnnInstance
  - | AnnLam
  - | AnnLarrow
  - | AnnLarrowU
  - | AnnLet
  - | AnnMdo
  - | AnnMinus
  - | AnnModule
  - | AnnNewtype
  - | AnnName
  - | AnnOf
  - | AnnOpen
  - | AnnOpenB
  - | AnnOpenBU
  - | AnnOpenC
  - | AnnOpenE
  - | AnnOpenEQ
  - | AnnOpenEQU
  - | AnnOpenP
  - | AnnOpenPE
  - | AnnOpenPTE
  - | AnnOpenS
  - | AnnPackageName
  - | AnnPattern
  - | AnnProc
  - | AnnQualified
  - | AnnRarrow
  - | AnnRarrowU
  - | AnnRec
  - | AnnRole
  - | AnnSafe
  - | AnnSemi
  - | AnnSimpleQuote
  - | AnnSignature
  - | AnnStatic
  - | AnnStock
  - | AnnThen
  - | AnnThIdSplice
  - | AnnThIdTySplice
  - | AnnThTyQuote
  - | AnnTilde
  - | AnnTildehsh
  - | AnnType
  - | AnnUnit
  - | AnnUsing
  - | AnnVal
  - | AnnValStr
  - | AnnVbar
  - | AnnWhere
  - | Annlarrowtail
  - | AnnlarrowtailU
  - | Annrarrowtail
  - | AnnrarrowtailU
  - | AnnLarrowtail
  - | AnnLarrowtailU
  - | AnnRarrowtail
  - | AnnRarrowtailU
  - | AnnEofPos
- data AnnotationComment
  - = AnnDocCommentNext String
  - | AnnDocCommentPrev String
  - | AnnDocCommentNamed String
  - | AnnDocSection Int String
  - | AnnDocOptions String
  - | AnnLineComment String
  - | AnnBlockComment String
- data IsUnicodeSyntax
  - = UnicodeSyntax
  - | NormalSyntax
- unicodeAnn :: AnnKeywordId -> AnnKeywordId
- data HasE
  - = HasE
  - | NoE
- type LRdrName = Located RdrName

# Documentation

getAnnotation :: ApiAnns -> SrcSpan -> AnnKeywordId -> [SrcSpan] #

Retrieve a list of annotation `SrcSpan`s based on the `SrcSpan` of the annotated AST element, and the known type of the annotation.

getAndRemoveAnnotation :: ApiAnns -> SrcSpan -> AnnKeywordId -> ([SrcSpan], ApiAnns) #

Retrieve a list of annotation `SrcSpan`s based on the `SrcSpan` of the annotated AST element, and the known type of the annotation. The list is removed from the annotations.

getAnnotationComments :: ApiAnns -> SrcSpan -> [Located AnnotationComment] #

Retrieve the comments allocated to the current `SrcSpan`

Note: A given `SrcSpan` may appear in multiple AST elements, beware of duplicates

getAndRemoveAnnotationComments :: ApiAnns -> SrcSpan -> ([Located AnnotationComment], ApiAnns) #

Retrieve the comments allocated to the current `SrcSpan`, and remove them from the annotations

type ApiAnns = (Map ApiAnnKey [SrcSpan], Map SrcSpan [Located AnnotationComment]) #

type ApiAnnKey = (SrcSpan, AnnKeywordId) #

data AnnKeywordId #

API Annotations exist so that tools can perform source to source conversions of Haskell code. They are used to keep track of the various syntactic keywords that are not captured in the existing AST.

The annotations, together with original source comments are made available in the ``pm_annotations`` field of ``ParsedModule``. Comments are only retained if ``Opt_KeepRawTokenStream`` is set in ``DynFlags`` before parsing.

The wiki page describing this feature is https://ghc.haskell.org/trac/ghc/wiki/ApiAnnotations

Note: in general the names of these are taken from the corresponding token, unless otherwise noted See note [Api annotations] above for details of the usage

Constructors

AnnAnyclass |
AnnAs |
AnnAt |
AnnBang | `!`
AnnBackquote | '`'
AnnBy |
AnnCase | case or lambda case
AnnClass |
AnnClose | '#)' or '#-}' etc
AnnCloseB | '|)'
AnnCloseBU | '|)', unicode variant
AnnCloseC | '}'
AnnCloseQ | '|]'
AnnCloseQU | '|]', unicode variant
AnnCloseP | ')'
AnnCloseS | ']'
AnnColon |
AnnComma | as a list separator
AnnCommaTuple | in a RdrName for a tuple
AnnDarrow | '=>'
AnnDarrowU | '=>', unicode variant
AnnData |
AnnDcolon | '::'
AnnDcolonU | '::', unicode variant
AnnDefault |
AnnDeriving |
AnnDo |
AnnDot | `.`
AnnDotdot | '..'
AnnElse |
AnnEqual |
AnnExport |
AnnFamily |
AnnForall |
AnnForallU | Unicode variant
AnnForeign |
AnnFunId | for function name in matches where there are multiple equations for the function.
AnnGroup |
AnnHeader | for CType
AnnHiding |
AnnIf |
AnnImport |
AnnIn |
AnnInfix | 'infix' or 'infixl' or 'infixr'
AnnInstance |
AnnLam |
AnnLarrow | '<-'
AnnLarrowU | '<-', unicode variant
AnnLet |
AnnMdo |
AnnMinus | `-`
AnnModule |
AnnNewtype |
AnnName | where a name loses its location in the AST, this carries it
AnnOf |
AnnOpen | '(#' or '{-# LANGUAGE' etc
AnnOpenB | '(|'
AnnOpenBU | '(|', unicode variant
AnnOpenC | '{'
AnnOpenE | '[e|' or '[e||'
AnnOpenEQ | '[|'
AnnOpenEQU | '[|', unicode variant
AnnOpenP | '('
AnnOpenPE | '$('
AnnOpenPTE | '$$('
AnnOpenS | '['
AnnPackageName |
AnnPattern |
AnnProc |
AnnQualified |
AnnRarrow | '->'
AnnRarrowU | '->', unicode variant
AnnRec |
AnnRole |
AnnSafe |
AnnSemi | ';'
AnnSimpleQuote | '''
AnnSignature |
AnnStatic | `static`
AnnStock |
AnnThen |
AnnThIdSplice | `$`
AnnThIdTySplice | `$$`
AnnThTyQuote | double '''
AnnTilde | '~'
AnnTildehsh | `~#`
AnnType |
AnnUnit | '()' for types
AnnUsing |
AnnVal | e.g. INTEGER
AnnValStr | String value, will need quotes when output
AnnVbar | '|'
AnnWhere |
Annlarrowtail | `-<`
AnnlarrowtailU | `-<`, unicode variant
Annrarrowtail | '->'
AnnrarrowtailU | '->', unicode variant
AnnLarrowtail | `-<<`
AnnLarrowtailU | `-<<`, unicode variant
AnnRarrowtail | `>>-`
AnnRarrowtailU | `>>-`, unicode variant
AnnEofPos |

Instances

Eq AnnKeywordId # |
Instance details Defined in ApiAnnotation Methods (==) :: AnnKeywordId -> AnnKeywordId -> Bool # (/=) :: AnnKeywordId -> AnnKeywordId -> Bool #
Data AnnKeywordId # |
Instance details Defined in ApiAnnotation Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> AnnKeywordId -> c AnnKeywordId Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c AnnKeywordId Source # toConstr :: AnnKeywordId -> Constr Source # dataTypeOf :: AnnKeywordId -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c AnnKeywordId) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AnnKeywordId) Source # gmapT :: (forall b. Data b => b -> b) -> AnnKeywordId -> AnnKeywordId Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> AnnKeywordId -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> AnnKeywordId -> r Source # gmapQ :: (forall d. Data d => d -> u) -> AnnKeywordId -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> AnnKeywordId -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> AnnKeywordId -> m AnnKeywordId Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> AnnKeywordId -> m AnnKeywordId Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> AnnKeywordId -> m AnnKeywordId Source #
Ord AnnKeywordId # |
Instance details Defined in ApiAnnotation Methods compare :: AnnKeywordId -> AnnKeywordId -> Ordering # (<) :: AnnKeywordId -> AnnKeywordId -> Bool # (<=) :: AnnKeywordId -> AnnKeywordId -> Bool # (>) :: AnnKeywordId -> AnnKeywordId -> Bool # (>=) :: AnnKeywordId -> AnnKeywordId -> Bool # max :: AnnKeywordId -> AnnKeywordId -> AnnKeywordId # min :: AnnKeywordId -> AnnKeywordId -> AnnKeywordId #
Show AnnKeywordId # |
Instance details Defined in ApiAnnotation Methods showsPrec :: Int -> AnnKeywordId -> ShowS Source # show :: AnnKeywordId -> String Source # showList :: [AnnKeywordId] -> ShowS Source #
Outputable AnnKeywordId # |
Instance details Defined in ApiAnnotation Methods ppr :: AnnKeywordId -> SDoc # pprPrec :: Rational -> AnnKeywordId -> SDoc #

data AnnotationComment #

Constructors

AnnDocCommentNext String | something beginning '-- |'
AnnDocCommentPrev String | something beginning '-- ^'
AnnDocCommentNamed String | something beginning '-- $'
AnnDocSection Int String | a section heading
AnnDocOptions String | doc options (prune, ignore-exports, etc)
AnnLineComment String | comment starting by "--"
AnnBlockComment String | comment in {- -}

Instances

Eq AnnotationComment # |
Instance details Defined in ApiAnnotation Methods (==) :: AnnotationComment -> AnnotationComment -> Bool # (/=) :: AnnotationComment -> AnnotationComment -> Bool #
Data AnnotationComment # |
Instance details Defined in ApiAnnotation Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> AnnotationComment -> c AnnotationComment Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c AnnotationComment Source # toConstr :: AnnotationComment -> Constr Source # dataTypeOf :: AnnotationComment -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c AnnotationComment) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AnnotationComment) Source # gmapT :: (forall b. Data b => b -> b) -> AnnotationComment -> AnnotationComment Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> AnnotationComment -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> AnnotationComment -> r Source # gmapQ :: (forall d. Data d => d -> u) -> AnnotationComment -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> AnnotationComment -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> AnnotationComment -> m AnnotationComment Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> AnnotationComment -> m AnnotationComment Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> AnnotationComment -> m AnnotationComment Source #
Ord AnnotationComment # |
Instance details Defined in ApiAnnotation Methods compare :: AnnotationComment -> AnnotationComment -> Ordering # (<) :: AnnotationComment -> AnnotationComment -> Bool # (<=) :: AnnotationComment -> AnnotationComment -> Bool # (>) :: AnnotationComment -> AnnotationComment -> Bool # (>=) :: AnnotationComment -> AnnotationComment -> Bool # max :: AnnotationComment -> AnnotationComment -> AnnotationComment # min :: AnnotationComment -> AnnotationComment -> AnnotationComment #
Show AnnotationComment # |
Instance details Defined in ApiAnnotation Methods showsPrec :: Int -> AnnotationComment -> ShowS Source # show :: AnnotationComment -> String Source # showList :: [AnnotationComment] -> ShowS Source #
Outputable AnnotationComment # |
Instance details Defined in ApiAnnotation Methods ppr :: AnnotationComment -> SDoc # pprPrec :: Rational -> AnnotationComment -> SDoc #

data IsUnicodeSyntax #

Certain tokens can have alternate representations when unicode syntax is enabled. This flag is attached to those tokens in the lexer so that the original source representation can be reproduced in the corresponding `ApiAnnotation`

Constructors

UnicodeSyntax |
NormalSyntax |

Instances

Eq IsUnicodeSyntax # |
Instance details Defined in ApiAnnotation Methods (==) :: IsUnicodeSyntax -> IsUnicodeSyntax -> Bool # (/=) :: IsUnicodeSyntax -> IsUnicodeSyntax -> Bool #
Data IsUnicodeSyntax # |
Instance details Defined in ApiAnnotation Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> IsUnicodeSyntax -> c IsUnicodeSyntax Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c IsUnicodeSyntax Source # toConstr :: IsUnicodeSyntax -> Constr Source # dataTypeOf :: IsUnicodeSyntax -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c IsUnicodeSyntax) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IsUnicodeSyntax) Source # gmapT :: (forall b. Data b => b -> b) -> IsUnicodeSyntax -> IsUnicodeSyntax Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IsUnicodeSyntax -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IsUnicodeSyntax -> r Source # gmapQ :: (forall d. Data d => d -> u) -> IsUnicodeSyntax -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> IsUnicodeSyntax -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> IsUnicodeSyntax -> m IsUnicodeSyntax Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> IsUnicodeSyntax -> m IsUnicodeSyntax Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> IsUnicodeSyntax -> m IsUnicodeSyntax Source #
Ord IsUnicodeSyntax # |
Instance details Defined in ApiAnnotation Methods compare :: IsUnicodeSyntax -> IsUnicodeSyntax -> Ordering # (<) :: IsUnicodeSyntax -> IsUnicodeSyntax -> Bool # (<=) :: IsUnicodeSyntax -> IsUnicodeSyntax -> Bool # (>) :: IsUnicodeSyntax -> IsUnicodeSyntax -> Bool # (>=) :: IsUnicodeSyntax -> IsUnicodeSyntax -> Bool # max :: IsUnicodeSyntax -> IsUnicodeSyntax -> IsUnicodeSyntax # min :: IsUnicodeSyntax -> IsUnicodeSyntax -> IsUnicodeSyntax #
Show IsUnicodeSyntax # |
Instance details Defined in ApiAnnotation Methods showsPrec :: Int -> IsUnicodeSyntax -> ShowS Source # show :: IsUnicodeSyntax -> String Source # showList :: [IsUnicodeSyntax] -> ShowS Source #

unicodeAnn :: AnnKeywordId -> AnnKeywordId #

Convert a normal annotation into its unicode equivalent one

data HasE #

Some template haskell tokens have two variants, one with an `e` the other not:

     [| or [e|
     [|| or [e||

This type indicates whether the `e` is present or not.

Constructors

HasE |
NoE |

Instances

Eq HasE # |
Instance details Defined in ApiAnnotation Methods (==) :: HasE -> HasE -> Bool # (/=) :: HasE -> HasE -> Bool #
Data HasE # |
Instance details Defined in ApiAnnotation Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> HasE -> c HasE Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c HasE Source # toConstr :: HasE -> Constr Source # dataTypeOf :: HasE -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c HasE) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HasE) Source # gmapT :: (forall b. Data b => b -> b) -> HasE -> HasE Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> HasE -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> HasE -> r Source # gmapQ :: (forall d. Data d => d -> u) -> HasE -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> HasE -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> HasE -> m HasE Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> HasE -> m HasE Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> HasE -> m HasE Source #
Ord HasE # |
Instance details Defined in ApiAnnotation Methods compare :: HasE -> HasE -> Ordering # (<) :: HasE -> HasE -> Bool # (<=) :: HasE -> HasE -> Bool # (>) :: HasE -> HasE -> Bool # (>=) :: HasE -> HasE -> Bool # max :: HasE -> HasE -> HasE # min :: HasE -> HasE -> HasE #
Show HasE # |
Instance details Defined in ApiAnnotation Methods showsPrec :: Int -> HasE -> ShowS Source # show :: HasE -> String Source # showList :: [HasE] -> ShowS Source #

type LRdrName = Located RdrName #

- `AnnKeywordId` : `AnnOpen`, `AnnClose`,`AnnComma`, `AnnRarrow`,`AnnTildehsh`, `AnnTilde`
- May have `AnnComma` when in a list