Fw: [Haskell-cafe] IO within parser

Well the docs ( http://legacy.cs.uu.nl/daan/download/parsec/parsec.html ) hint that setInput and getInput are good for this. I can certainly how they *would* be - if I knew how to pull in files within the parse. Actually I use those functions to do multiple recursive passes but of course you already have the output from the first pass in the parser there. runParser only *looks* like it takes input from a file. Actually it just parses the string you give it and uses the filename arg for error messages only. You still need a way to pull the data into the string from the file.
(Note: I accidentally sent this to Andrew instead of the list originally)
----- Original Message ----
From: Andrew Coppin
I've been struggling with writing a parser that needs to parse include files within source files. So far I cannot get this to work (in reality to get work done I wrote a kludge that returns a list of include filenames to be run later in a pure IO function. I realized that this just amounted to creating my own half-assed monad system so I really don't want to use this approach). I have read the tutorials I could find on monad transformers but I still don't see what's going on. I'm using the Parsec parser library. Here's an simple example of what I've tried. I also tried using liftIO and got a message about needing to add an instance of MonadIO. This made more sense but the type of liftIO is baffling
The fun part is that Parsec already has a feature for include files... (I can't remember where the heck it is or how you use it though.) _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel and lay it on us. ____________________________________________________________________________________ Choose the right car based on your needs. Check out Yahoo! Autos new Car Finder tool. http://autos.yahoo.com/carfinder/

Hello Gregory, Sunday, August 12, 2007, 9:32:04 AM, you wrote:
I've been struggling with writing a parser that needs to parse include files within source files.
Parsec can't accomplish with without using unsafePerformIO because it's monad is pure. it's algorithmically impossible to have any i/o actions inside it. there was plans to rewrite Parsec in monad-transformer way and afair it was even one of GSOC projects -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (2)
-
Bulat Ziganshin
-
Gregory Propf