A Haskell pre-processor https://github.com/acowley/hpp

Version on this page:0.4.0
LTS Haskell 8.2:0.4.0
Stackage Nightly 2017-02-25:0.4.0
Latest on Hackage:0.4.0
BSD3 licensed by Anthony Cowley

hpp is a Haskell pre-processor that is also a C90-compatible pre-processor (with the addition of a --cpp flag). It is packaged as both a library and an executable.

To use as a Haskell preprocessor for resolving #ifdef conditionals and macro expansion, an invocation might look like,

hpp -DDEBUG Foo.hs

To use as a C preprocessor, an invocation might look like,

hpp -DDEBUG --cpp foo.c

To have GHC use hpp as the C pre-processor, add this line to the top of a Haskell source file that makes use of the CPP LANGUAGE pragma,

{-# OPTIONS_GHC -cpp -pgmPhpp #-}

Or add this line to your .cabal file:

ghc-options: -pgmPhpp

Note that you will need to ensure that the hpp executable is available in your build environment (e.g. you can add hpp as a build-depends in your .cabal file).



  • Simplify the parsing machinery
  • Don't remove C++-style single-line comments
  • Don't error on unknown cpp directives Previously, a line beginning with "#-}" would cause an error
  • Don't do trigraph replacement by default. Haskell allows "??" in operator names and you can be sure lens uses it!


Address a change wherein GHC 8 will pass -include arguments without a space between "-include" and the file to be included.


Switch to a stream processing model.

This library is designed to have minimal dependencies, so we now have a bespoke implementation of a cross between the pipes and machines libraries included.

This change was done to make some parsing operations easier, believe it or not. For example, most pre-processing is done on a line-by-line basis, but we must also support macro function applications that cross line boundaries. Thus the expansion logic can not merely be given one line at a time from an input file. Previously, a heuristic tried to combine consecutive lines before the parsing stage. Now, the parser itself is able to pull tokens in across lines when necessary.

TL;DR: The upshot is that processing /usr/include/stdio.h on OS X (a surprisingly complicated file!) now uses 78% of the time and 0.38% the memory of previous versions of hpp.


First release!

comments powered byDisqus