<div dir="ltr">G'day,<div><br></div><div> I'm implementing a parser for a language that has a preprocessor.</div><div>It has `include, `ifdef..`else..`endif, `define and uses of the `defined fragments, which are also prefixed by '`'.</div><div><br></div><div>I can think of two ways of doing this: a preprocess :: Stream->Stream (for String, Text, ByteString)</div><div>or processing preprocessor directives as part of the"whitespace skipping" at begin of file and after each token.</div><div><br></div><div>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.</div><div><br></div><div>Any recommendations? pointers to examples of parsec-based parsers that have a pre-processing step?</div><div><br></div><div>Thanks,</div><div><br></div><div>  Maurizio</div></div>