Any example of a custom PreProcessor in Haskell?

One of the most important things to do is setting your BuildType in your . Cabal file to Custom. If it stays at Simple Cabal will completely ignore the Setup.

Hs file.

One of the most important things to do is setting your BuildType in your . Cabal file to Custom. If it stays at Simple Cabal will completely ignore the Setup.

Hs file. Build-Type: Custom Here is an example Custom preprocessor from my package, It first runs cpphs and then runs hsc2hs #! /usr/bin/env runhaskell > {-# LANGUAGE BangPatterns #-} > import Distribution.

Simple > import Distribution.Simple. PreProcess > import Distribution.Simple. Utils > import Distribution.

PackageDescription > import Distribution.Simple. LocalBuildInfo > import Data. Char > import System.

Exit > import System. IO > import System. Directory > import System.FilePath.

Windows > main = let hooks = simpleUserHooks > xpp = ("xpphs", ppXpp) > in defaultMainWithHooks hooks { hookedPreProcessors = xpp:knownSuffixHandlers } > > ppXpp :: BuildInfo -> LocalBuildInfo -> PreProcessor > ppXpp build local = > PreProcessor { > platformIndependent = True, > runPreProcessor = mkSimplePreProcessor $ \inFile outFile verbosity -> > do info verbosity (inFile++" is being preprocessed to "++outFile) > let hscFile = replaceExtension inFile "hsc" > runSimplePreProcessor (ppCpp build local) inFile hscFile verbosity > handle source hClose handle > let newsource = unlines $ process $ lines source > writeFile hscFile newsource > runSimplePreProcessor (ppHsc2hs build local) hscFile outFile verbosity > removeFile hscFile > return () > } This preprocessor will automatically be called by Cabal when any file with the extension . Xpphs is found. In your case just register the preprocessor with a .

Hs extension. (I'm not sure if Cabal allows this. But if it doesn't you can simply rename the files with the injection point to a .

Xh or something. This would actually be better since you don't process every file in your project then).

Thanks! I finally figured out a solution which uses preBuild hook to generate the module using a template file as input. And then import this module where it supposed to be.

– claude Sep 10 at 9:30 Ah yeah, that would work too. Cabal has so many hooks :) – Phyx Sep 10 at 10:00.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions