Hi, ParsecT with m=IO? Your 'do' block would become: do i <- getInput included <- liftIO readI -- import Control.Monad.Trans for liftIO setInput included a <- my_str setInput i b <- my_str return $ a ++ " //\n\n " ++ b where readI = readFile "experiment.hs" Maybe I'm misunderstanding the problem. Greetings, Daniel On Thursday 18 June 2009 13:58:53 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.
Appending an example program, using unsafePerformIO.
Thanx for reading.
Greetings, Leonard Siebeneicher
--- Begin: experiment.hs --- import Text.ParserCombinators.Parsec import System.IO.Unsafe
my_str :: Parser String my_str = many1 anyToken
wrap_input :: Parser String -> Parser String wrap_input p = do i <- getInput setInput readI a <- my_str setInput i b <- my_str return $ a ++ " //\n\n " ++ b where {- Aaaah ... any solution without unsafePerformIO? -} readI = unsafePerformIO (readFile "experiment.hs")
main = case parse (wrap_input my_str) "" "eintest" of Left err -> putStrLn "Error raised" Right ostr -> putStrLn ostr --- End: experiment.hs ---
___ Thinking about a special type like
data MyInclude = PlainText String
| IncludeFile String
the parser could generate [MyInclude] data, but it does not work generally.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe