--------------------------------------------------
I have written a parser that is reading the code and outputs a file like this (it can handle special characters and variables that are not strings, but let's keep it simple here):
----------------b.hs------------------------------
main = do
writeFile "inputOfChemPack" string
string = "This is the actual input file\nFormatted like this\nwith some " ++ variable ++ " "
variable = "foo"
--------------------------------------------------
Now... this file can be compiled and it does exactly what I want: it prints a file like this:
--------inputOfChemPack-----
This is the actual input file
Formatted like this
with some foo
--------------------------------------
Now the big question... right now I am doing this with some bash scripts (run the parser on the file and then compile its output)... but... is it possible to automatize this using my parser as a sort of preprocessor?
the "dream" would be to make an extension that just applies the parser automatically before compilation, such as:
-----------------a.hs-----------------------------
{-# extensionName #-}
main = do
writeFile "inputOfChemPack" string
string = {{{+
This is the actual input file
Formatted like this
with some %variable
+}}}
variable = "foo"
--------------------------------------------------
$ ghci a.hs
GHCi, version 7.6.3:
http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( a.hs, interpreted )
Ok, modules loaded: Main.
*Main> string
"This is the actual input file\nFormatted like this\nwith some foo"
I have been browsing stuffs about quasiquotation and preprocessors, but I have the feeling that is a quite simple task compared to those solutions.
Any ideas? How can I solve this problem?
Thank you
Alessio