What is cpphs? How do I use it? Downloads |
Recent news Contacts |
cpphs is a simplified re-implementation of cpp, the C pre-processor, in Haskell.
Why re-implement cpp? Rightly or wrongly, the C pre-processor is widely used in Haskell source code. It enables conditional compilation for different compilers, different versions of the same compiler, and different OS platforms. It is also occasionally used for its macro language, which can enable certain forms of platform-specific detail-filling, such as the tedious boilerplate generation of instance definitions and FFI declarations. However, there are two problems with cpp, aside from the obvious aesthetic ones:
This version of the C pre-processor is pretty-much feature-complete. It has two modes:
Working Features:
Macro expansion is recursive. Redefinition of a macro or symbol does not generate a warning. Macros can be defined on the command-line with -D just like symbols. Macro/symbol names are permitted to be Haskell identifiers e.g. with the ' character, which is slightly looser than in C, but they still may not include operators.
Numbering of lines in the output is preserved so that any later processor can give meaningful error messages. When a file is #include'd, cpphs inserts #line directives for the same reason. Numbering should be correct even in the presence of line continuations. If you don't want #line directives in the final output, use the --noline option.
Any syntax errors in cpp directives, and any failure to find a #include'd file, gives a message to standard error and halts the program.
Usage: cpphs [ filename | -Dsym | -Dsym=val | -Ipath ]+ [ --nomacro ] [ --noline ]
You can give any number of filenames on the command-line. The results are catenated on standard output.
Options:
There are NO symbols defined by default. (This could easily be changed in the source code though. The search path is searched in order of the -I options, except that the current directory is always searched first. Again, there is no default search path (and again, could easily be changed).
Current version:
cpphs-0.2, release date 2004.05.15
By HTTP:
.tar.gz,
.zip.
Older versions:
cpphs-0.1, release date 2004.04.07
By HTTP:
.tar.gz,
.zip.
To build cpphs, use
hmake cpphs [-package base]or
ghc --make cpphsor
runhugs cpphs
I am interested in hearing your feedback on cpphs. Bug reports especially welcome, since it is so new. You can send Feature requests too, but I won't guarantee to attend to them, especially if they depart from ordinary cpp's behaviour. Please mail
Copyright: © 2004 Malcolm Wallace, except for ParseLib (Copyright © 1995 Graham Hutton and Erik Meijer)
License: The library modules in cpphs are distributed under the terms of the LGPL (see file LICENCE-LGPL for more details). If that's a problem for you, contact me to make other arrangements.
The application module 'cpphs.hs' itself is trivial (since all the functionality is inside the library) and so is placed into the public domain.
This software comes with no warranty. Use at your own risk.