ApiAnnotation

ghc-7.10.3: 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
  - = AnnAs
  - | AnnAt
  - | AnnBang
  - | AnnBackquote
  - | AnnBy
  - | AnnCase
  - | AnnClass
  - | AnnClose
  - | AnnCloseC
  - | AnnCloseP
  - | AnnCloseS
  - | AnnColon
  - | AnnComma
  - | AnnCommaTuple
  - | AnnDarrow
  - | AnnData
  - | AnnDcolon
  - | AnnDefault
  - | AnnDeriving
  - | AnnDo
  - | AnnDot
  - | AnnDotdot
  - | AnnElse
  - | AnnEqual
  - | AnnExport
  - | AnnFamily
  - | AnnForall
  - | AnnForeign
  - | AnnFunId
  - | AnnGroup
  - | AnnHeader
  - | AnnHiding
  - | AnnIf
  - | AnnImport
  - | AnnIn
  - | AnnInfix
  - | AnnInstance
  - | AnnLam
  - | AnnLarrow
  - | AnnLet
  - | AnnMdo
  - | AnnMinus
  - | AnnModule
  - | AnnNewtype
  - | AnnName
  - | AnnOf
  - | AnnOpen
  - | AnnOpenC
  - | AnnOpenP
  - | AnnOpenPE
  - | AnnOpenPTE
  - | AnnOpenS
  - | AnnPackageName
  - | AnnPattern
  - | AnnProc
  - | AnnQualified
  - | AnnRarrow
  - | AnnRec
  - | AnnRole
  - | AnnSafe
  - | AnnSemi
  - | AnnSimpleQuote
  - | AnnStatic
  - | AnnThen
  - | AnnThIdSplice
  - | AnnThIdTySplice
  - | AnnThTyQuote
  - | AnnTilde
  - | AnnTildehsh
  - | AnnType
  - | AnnUnit
  - | AnnUsing
  - | AnnVal
  - | AnnValStr
  - | AnnVbar
  - | AnnWhere
  - | Annlarrowtail
  - | Annrarrowtail
  - | AnnLarrowtail
  - | AnnRarrowtail
  - | AnnEofPos
- data AnnotationComment
  - = AnnDocCommentNext String
  - | AnnDocCommentPrev String
  - | AnnDocCommentNamed String
  - | AnnDocSection Int String
  - | AnnDocOptions String
  - | AnnDocOptionsOld String
  - | AnnLineComment String
  - | AnnBlockComment String
- 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

AnnAs |
AnnAt |
AnnBang | `!`
AnnBackquote | '`'
AnnBy |
AnnCase | case or lambda case
AnnClass |
AnnClose | '#)' or '#-}' etc
AnnCloseC | '}'
AnnCloseP | ')'
AnnCloseS | ']'
AnnColon |
AnnComma | as a list separator
AnnCommaTuple | in a RdrName for a tuple
AnnDarrow | '=>'
AnnData |
AnnDcolon | '::'
AnnDefault |
AnnDeriving |
AnnDo |
AnnDot | `.`
AnnDotdot | '..'
AnnElse |
AnnEqual |
AnnExport |
AnnFamily |
AnnForall |
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 | '<-'
AnnLet |
AnnMdo |
AnnMinus | `-`
AnnModule |
AnnNewtype |
AnnName | where a name loses its location in the AST, this carries it
AnnOf |
AnnOpen | '(#' or '{-# LANGUAGE' etc
AnnOpenC | '{'
AnnOpenP | '('
AnnOpenPE | '$('
AnnOpenPTE | '$$('
AnnOpenS | '['
AnnPackageName |
AnnPattern |
AnnProc |
AnnQualified |
AnnRarrow | '->'
AnnRec |
AnnRole |
AnnSafe |
AnnSemi | ';'
AnnSimpleQuote | '''
AnnStatic | `static`
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 | `-<`
Annrarrowtail | '->'
AnnLarrowtail | `-<<`
AnnRarrowtail | `>>-`
AnnEofPos |

Instances

Eq AnnKeywordId |
Data AnnKeywordId |
Ord AnnKeywordId |
Show AnnKeywordId |
Outputable AnnKeywordId |

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)
AnnDocOptionsOld String | doc options declared "-- # ..."-style
AnnLineComment String | comment starting by "--"
AnnBlockComment String | comment in {- -}

Instances

Eq AnnotationComment |
Data AnnotationComment |
Ord AnnotationComment |
Show AnnotationComment |
Outputable AnnotationComment |

type LRdrName = Located RdrName

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