ast-plugin

Last updated: 2016-11-13 17:12:59 +0000

Upstream URL: git clone http://chriswarbo.net/git/ast-plugin.git

Repo

View repository

View issue tracker

Contents of follows


Dump Haskell ASTs

This project provides a plugin for the Glasgow Haskell Compiler (GHC) which dumps out Abstract Syntax Trees (ASTs) of Haskell code to stdout.

To get these ASTs, we want to use GHC because it has features like "dependency chasing", unique renaming, support for CPP, TemplateHaskell, etc. and it works for pretty much all Haskell code ever written (simply because most Haskell programmers don't target anything else). Other approaches, eg. standalone parsers like haskell-src-exts, would require us to re-implement a lot of these features ourselves.

There are many ways to use GHC:

One disadvantage to writing GHC plugins is that they're currently limited to using GHC's "Core" intermediate language. This is a slightly simplified version of Haskell, so the ASTs we get don't correspond exactly to the Haskell code written in our .hs files. There are proposals to add "source plugins" to GHC, but for now Core is often "close enough" to be useful.

Usage

See the GHC documentation for using compiler plugins. It is highly recommended that you use this plugin via Cabal2DB since that provides convenient scripts for setting up the GHC environment.