HORIZON HASKELLDocslts/ghc-10.0.xaa25b892026-10-10Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · aa25b89 · 2026-10-10

Moduleghc-10.0.0.20260917GHC2024

GHC.Parser.Annotation

  • 54 types
  • 3 classes
  • 56 values

Core Exact Print Annotation types

17 declarations
datadata EpToken (tok :: Symbol)
#

A token stored in the syntax tree. For example, when parsing a let-expression, we store EpToken "let" and EpToken "in". The locations of those tokens can be used to faithfully reproduce (exactprint) the original program text.

Instances6Eq, Data, HasLoc, NoAnn, Outputable, HasHaddock
  • Eq (EpToken tok)Defined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • KnownSymbol tok => Data (EpToken tok)Defined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • HasLoc (EpToken tok)Defined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • NoAnn (EpToken s)Defined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • KnownSymbol tok => Outputable (EpToken tok)Defined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • HasHaddock (LocatedLI [LocatedA (IE GhcPs)])Defined in ghc-10.0.0.20260917 · GHC.Parser.PostProcess.Haddock

    Only for module exports, not module imports.

    module M (a, b, c) where -- use on this [LIE GhcPs] import I (a, b, c) -- do not use here!

    Imports cannot have documentation comments anyway.

datadata EpUniToken (tok :: Symbol) (utok :: Symbol)
#

With UnicodeSyntax, there might be multiple ways to write the same token. For example an arrow could be either -> or →. This choice must be recorded in order to exactprint such tokens, so instead of EpToken "->" we introduce EpUniToken "->" "→".

Instances5Eq, Data, HasLoc, NoAnn, Outputable
datadata EpLayout
#

Layout information for declarations.

Constructors

  • EpExplicitBraces !(EpToken "{") !(EpToken "}")

    Explicit braces written by the user.

    class C a where { foo :: a; bar :: a }
    
  • EpVirtualBraces !Int

    Virtual braces inserted by the layout algorithm.

    class C a where
      foo :: a
      bar :: a
    
  • EpNoLayout

    Empty or compiler-generated blocks do not have layout information associated with them.

Instances1Data
  • Data EpLayoutDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
datadata EpaComment
#

Constructors

Instances10Eq, Data, Show, Semigroup, HasAnnotation, HasLoc, …
datadata EpaCommentTok
#

Constructors

Instances3Eq, Data, Show
datadata 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 EpAnnotation

Instances5Eq, Data, Ord, Show, Outputable
datadata 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.

Instances4Eq, Data, Ord, Show
  • Eq HasEDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • Data HasEDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • Ord HasEDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • Show HasEDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation

In-tree Exact Print Annotations

11 declarations
datadata EpaLocation' a
#

The anchor for an exact print annotation. The Parser inserts the EpaSpan variant, giving the exact location of the original item in the parsed source. This can be replaced by the EpaDelta version, to provide a position for the item relative to the end of the previous item in the source. This is useful when editing an AST prior to exact printing the changed one. The EpaDelta also contains the original SrcSpan for use by tools wanting to manipulate the AST after converting it using ghc-exactprint' makeDeltaAst.

Instances10Semigroup, HasAnnotation, HasLoc, NoAnn, Eq, Data, …
datadata DeltaPos
#

Spacing between output items when exact printing. It captures the spacing from the current print position on the page to the position required for the thing about to be printed. This is either on the same line in which case is is simply the number of spaces to emit, or it is some number of lines down, with a given column offset. The exact printing algorithm keeps track of the column offset pertaining to the current anchor position, so the deltaColumn is the additional spaces to add in this case. See https://gitlab.haskell.org/ghc/ghc/wikis/api-annotations for details.

Constructors

Instances5Eq, Data, Ord, Show, Outputable
  • Eq DeltaPosDefined in ghc-10.0.0.20260917 · GHC.Types.SrcLoc
  • Data DeltaPosDefined in ghc-10.0.0.20260917 · GHC.Types.SrcLoc
  • Ord DeltaPosDefined in ghc-10.0.0.20260917 · GHC.Types.SrcLoc
  • Show DeltaPosDefined in ghc-10.0.0.20260917 · GHC.Types.SrcLoc
  • Outputable DeltaPosDefined in ghc-10.0.0.20260917 · GHC.Types.SrcLoc
datadata EpAnn ann
#

The exact print annotations (EPAs) are kept in the HsSyn AST for the GhcPs phase. They are usually inserted into the AST by the parser, and in case of generated code (e.g. by TemplateHaskell) they are usually initialized using NoAnn type class.

A goal of the annotations is that an AST can be edited, including moving subtrees from one place to another, duplicating them, and so on. This means that each fragment must be self-contained. To this end, each annotated fragment keeps track of the anchor position it was originally captured at, being simply the start span of the topmost element of the ast fragment. This gives us a way to later re-calculate all Located items in this layer of the AST, as well as any annotations captured. The comments associated with the AST fragment are also captured here.

The ann type parameter allows this general structure to be specialised to the specific set of locations of original exact print annotation elements. For example

type SrcSpannAnnA = EpAnn AnnListItem

is a commonly used type alias that specializes the ann type parameter to AnnListItem.

The spacing between the items under the scope of a given EpAnn is normally derived from the original Anchor. But if a sub-element is not in its original position, the required spacing can be captured using an appropriate EpaDelta value for the entry Anchor. This allows us to freely move elements around, and stitch together new AST fragments out of old ones, and have them still printed out in a precise way.

Constructors

Instances166Functor, Eq, Semigroup, HasAnnotation, HasLoc, NoAnn, …
classclass NoAnn a where
#

Methods

  • noAnn :: a

    equivalent of mempty, but does not need Semigroup

Instances48NoAnn, …

Comments in Annotations

datadata EpAnnComments
#

When we are parsing we add comments that belong to a particular AST element, and print them together with the element, interleaving them into the output stream. But when editing the AST to move fragments around it is useful to be able to first separate the comments into those occurring before the AST element and those following it. The EpaCommentsBalanced constructor is used to do this. The GHC parser will only insert the EpaComments form.

Instances4Eq, Data, Semigroup, Outputable
datadata NoComments
#
Instances11Eq, Data, Ord, Show, Semigroup, HasAnnotation, …

Annotations in GenLocated

Annotation data types used in GenLocated

datadata AnnListItem
#

Annotation for items appearing in a list. They can have one or more trailing punctuations items, such as commas or semicolons.

Instances145Eq, Semigroup, NoAnn, Outputable, CollectBinders, HasType, …
datadata AnnList a
#

Annotation for the "container" of a list. This captures surrounding items such as braces if present, and introductory keywords such as where.

Constructors

Instances7Eq, Data, NoAnn, Outputable, HasHaddock, ToHie, …
datadata AnnParen
#

exact print annotation for an item having surrounding "brackets", such as tuples or lists

Constructors

Instances3Data, NoAnn, Outputable
datadata AnnPragma
#

exact print annotation used for capturing the locations of annotations in pragmas.

Instances5Eq, Data, NoAnn, Outputable, ToHie
datadata AnnContext
#

Exact print annotation for the Context data type.

Constructors

Instances7Data, NoAnn, Outputable, ToHie, HasHaddock, …
datadata NameAnn
#

exact print annotations for a RdrName. There are many kinds of adornment that can be attached to a given RdrName. This type captures them, as detailed on the individual constructors.

Constructors

Instances5Eq, Data, NoAnn, Outputable, ToHie
  • Eq NameAnnDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • Data NameAnnDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • NoAnn NameAnnDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • Outputable NameAnnDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • ToHie (Context (Located a)) => ToHie (Context (LocatedN a))Defined in ghc-10.0.0.20260917 · GHC.Iface.Ext.Ast
datadata NameAdornment
#

A NameAnn can capture the locations of surrounding adornments, such as parens or backquotes. This data type identifies what particular pair are being used.

Instances3Eq, Data, Outputable
datadata NoEpAnns
#
Instances16Eq, Data, Ord, NoAnn, Outputable, ToHie, …
datadata AnnSortKey tag
#

Captures the sort order of sub elements for ValBinds, ClassDecl, ClsInstDecl

Constructors

Instances5Eq, Data, Semigroup, Monoid, Outputable
datadata DeclTag
#

Used to track interleaving of class methods, class signatures, associated types and associate type defaults in ClassDecl and ClsInstDecl.

Instances5Eq, Data, Ord, Show, Outputable
  • Eq DeclTagDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • Data DeclTagDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • Ord DeclTagDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • Show DeclTagDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • Outputable DeclTagDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
datadata BindTag
#

Used to track of interleaving of binds and signatures for ValBind

Instances5Eq, Data, Ord, Show, Outputable
  • Eq BindTagDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • Data BindTagDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • Ord BindTagDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • Show BindTagDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation
  • Outputable BindTagDefined in ghc-10.0.0.20260917 · GHC.Parser.Annotation

Trailing annotations in lists

datadata TrailingAnn
#

Captures the location of punctuation occurring between items, normally in a list. It is captured as a trailing annotation.

Constructors

Instances3Eq, Data, Outputable

Utilities for converting between different GenLocated when

we do not care about the annotations.

valuel2l :: (HasLoc a, HasAnnotation b) => a -> b
#

Helper function for converting annotation types. Discards any annotations

classclass HasLoc a where
#

Methods

  • getHasLoc :: a -> SrcSpan

    conveniently calculate locations for things without locations attached

Instances13HasLoc, …

Building up annotations

Querying annotations

Working with locations of annotations

Constructing GenLocated annotation types when we do not care

Working with comments in annotations