[Haskell-cafe] Parsec Preprocessor

Bob Ippolito bob at redivi.com
Sat Mar 29 16:57:22 UTC 2014


You don't need to build your own QuasiQuoter, a number of suitable ones
exist on Hackage already. Just search for interpolation or quasi-quoter and
you'll find something appropriate to use for your application. Using a
pre-processor is almost certainly not going to be simpler.


On Sat, Mar 29, 2014 at 9:15 AM, Alessio Valentini <acuzzio at gmail.com>wrote:

> 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140329/c80bed7e/attachment.html>


More information about the Haskell-Cafe mailing list