[Haskell-cafe] how to #include files within parsec ... without unsafePerformIO?

Neil Brown nccb2 at kent.ac.uk
Thu Jun 18 08:06:52 EDT 2009

Leonard Siebeneicher wrote:
> Dear reader,
> I wonder whether there is a 'general' working solution to include files
> within a parsec parser. Without the need of unsafePerformIO.
At least in parsec 2, I don't think so.  Our solution was to read in the 
main file, tokenise it (using Alex), preprocess it (using some 
regex-like pattern matching on the token stream) in the IO monad and 
include the new files then (also tokenising and preprocessing them).  
Then after preprocessing we feed the entire resulting token stream to 
Parsec.  Whether a two-phase approach (preprocess then parse) works 
depends on whether your include syntax is simple enough that you can 
spot the includes without parsing.



More information about the Haskell-Cafe mailing list