|
|
# GHC 7.10 GHC-API Changes and proposed changes
|
|
|
# Developments in the GHC API
|
|
|
|
|
|
|
|
|
There are a number of changes in GHC 7.10 that will make it easier for
|
|
|
This page summarises changes to the GHC API that will make it easier for
|
|
|
tool writers to use the GHC API.
|
|
|
|
|
|
|
|
|
These include
|
|
|
|
|
|
1. More parser entrypoints, to explicitly parse fragments \[Andrew Gibiansky\]
|
|
|
1. More parser entrypoints, to explicitly parse fragments (Andrew Gibiansky)
|
|
|
|
|
|
>
|
|
|
> The following parsers are now provided
|
|
|
|
|
|
> >
|
|
|
> > parseModule, parseImport, parseStatement, parseDeclaration,
|
|
|
> > parseExpression, parseTypeSignature, parseFullStmt, parseStmt,
|
|
|
> > parseIdentifier, parseType, parseHeader
|
|
|
> > `parseModule`, `parseImport`, `parseStatement`, `parseDeclaration`,
|
|
|
> > `parseExpression`, `parseTypeSignature`, `parseFullStmt`, `parseStmt`,
|
|
|
> > `parseIdentifier`, `parseType`, `parseHeader`
|
|
|
|
|
|
1. No more landmines in the AST \[Alan Zimmerman\]
|
|
|
1. No more landmines in the AST (Alan Zimmerman).
|
|
|
|
|
|
>
|
|
|
> In the past it was difficult to work with the GHC AST as any generic
|
|
|
> traversals had to carefully tiptoe around an assortment of panic and
|
|
|
> undefined expressions. These have now been removed, allowing
|
|
|
> standard traversal libraries to be used.
|
|
|
|
|
|
1. Introduce an annotation structure to the ParsedSource to record the location of uncaptured keywords \[Alan Zimmerman\]
|
|
|
> In the past it was difficult to work with the GHC AST as any generic traversals had to carefully tiptoe around an assortment of panic and undefined expressions. These have now been removed, by uses of `PostRn`, `PostTc`, etc, allowing standard traversal libraries to be used. See module `hsSyn/PlaceHolder`.
|
|
|
|
|
|
>
|
|
|
> At the moment the location of let / in / if / then / else / do
|
|
|
> etc is not captured in the AST. This makes it difficult to
|
|
|
> parse some source, transform the AST, and then output it again
|
|
|
> preserving the original layout.
|
|
|
> The relevant commit is `7d3f2dfc7a45d741224c521e0f2a616a89f9506f`
|
|
|
|
|
|
1. Introduce an annotation structure to the `ParsedSource` to record the location of un-captured keywords (Alan Zimmerman).
|
|
|
|
|
|
>
|
|
|
> The current proposal, which can be seen at \[1\] and a proof of
|
|
|
> concept implementation at \[2\] returns a structure keyed to each AST
|
|
|
> element containing simply the specific SrcSpan's not already
|
|
|
> captured in the AST.
|
|
|
> Ticket: [\#9628](https://gitlab.haskell.org//ghc/ghc/issues/9628). Wiki page: [GhcAstAnnotations](ghc-ast-annotations)
|
|
|
|
|
|
>
|
|
|
> This is the analogue of the Language.Haskell.Exts.Annotated.Syntax
|
|
|
> from haskell-src-exts, except a custom SrcSpanInfo structure is
|
|
|
> provided for each AST element constructor, and it is not embedded
|
|
|
> within the AST.
|
|
|
> At the moment the location of let / in / if / then / else / do etc is not captured in the AST. This makes it difficult to parse some source, transform the AST, and then output it again preserving the original layout.
|
|
|
|
|
|
> \[1\][GhcAstAnnotations](ghc-ast-annotations)
|
|
|
>
|
|
|
> The [current proposal](ghc-ast-annotations), and a [ proof of concept implementation](https://phabricator.haskell.org/D297) returns a structure keyed to each AST element containing simply the specific SrcSpan's not already captured in the AST.
|
|
|
|
|
|
> \[2\][ https://phabricator.haskell.org/D297](https://phabricator.haskell.org/D297) |
|
|
\ No newline at end of file |
|
|
>
|
|
|
> This is the analogue of the `Language.Haskell.Exts.Annotated.Syntax` from `haskell-src-exts`, except a custom `SrcSpanInfo` structure is provided for each AST element constructor, and it is not embedded within the AST. |