[Haskell-cafe] preprocessing and Parsec

Maurizio Vitale mrz.vtl at gmail.com
Mon Mar 30 14:18:02 UTC 2015


 I'm implementing a parser for a language that has a preprocessor.
It has `include, `ifdef..`else..`endif, `define and uses of the `defined
fragments, which are also prefixed by '`'.

I can think of two ways of doing this: a preprocess :: Stream->Stream (for
String, Text, ByteString)
or processing preprocessor directives as part of the"whitespace skipping"
at begin of file and after each token.

The first one seems cleaner/easier (and also allow parsers not to require a
(restricted) IO monad for reading files). The second one, seems to make
easier to give nice error messages (in the separate preprocessor way, you
can add something like #line to tell where inclusions came from, but you
cannot easily do this for macro replacement). My eventual goal is to give
clang-like error messages with macro expansion backtrace.

Any recommendations? pointers to examples of parsec-based parsers that have
a pre-processing step?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150330/6c5216d4/attachment.html>

More information about the Haskell-Cafe mailing list