G'day,
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?
Thanks,
Maurizio