[Haskell-cafe] Parsec Preprocessor
Alessio Valentini
acuzzio at gmail.com
Sat Mar 29 16:15:46 UTC 2014
Dear Haskellers
This is gonna be my first post on here : ) .
I am developing some tools to interact with Chemistry packages, and I
basically have to write input files for those programs.
I would like to be able to write those input in a better way inside the hs
code. For example this would be perfect ( {{{+ and +}}} are just labels to
mark the "special syntax"):
--------------a.hs--------------------------------
main = do
writeFile "inputOfChemPack" string
string = {{{+
This is the actual input file
Formatted like this
with some %variable
+}}}
variable = "foo"
--------------------------------------------------
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140329/f2815891/attachment.html>
More information about the Haskell-Cafe
mailing list