[add '-E' option to run a file through the preprocessor (m4 or cpp)
John Meacham <john@repetae.net>**20090811154326
 Ignore-this: 737d8e72b74d7e7c567466b1dc5dc221
] hunk ./src/Ho/Build.hs 5
+    preprocess,
hunk ./src/Ho/Build.hs 619
+collectFileOpts fn s = opt where
+    Just opt = fileOptions opts `mplus` Just options
+    popts = parseOptions $ if "shl." `isPrefixOf` reverse fn  then unlit fn s else s
+    opts' = concat [ words as | (x,as) <- popts, x `elem` ["OPTIONS","JHC_OPTIONS","OPTIONS_JHC"]]
+    opts = opts' ++ [ "--noprelude" | ("NOPRELUDE",_) <- popts] ++ langs
+    langs = catMaybes $ map (flip lookup langmap) $ concat [ words (map (\c -> if c == ',' then ' ' else toLower c) as) | ("LANGUAGE",as) <- popts ]
hunk ./src/Ho/Build.hs 626
-
-
-parseHsSource :: String -> LBS.ByteString -> IO HsModule
-parseHsSource fn lbs = do
-    let f s = opt where
-            Just opt = fileOptions opts `mplus` Just options
-            popts = parseOptions $ if "shl." `isPrefixOf` reverse fn  then unlit fn s else s
-            opts' = concat [ words as | (x,as) <- popts, x `elem` ["OPTIONS","JHC_OPTIONS","OPTIONS_JHC"]]
-            opts = opts' ++ [ "--noprelude" | ("NOPRELUDE",_) <- popts] ++ langs
-            langs = catMaybes $ map (flip lookup langmap) $ concat [ words (map (\c -> if c == ',' then ' ' else toLower c) as) | ("LANGUAGE",as) <- popts ]
+preprocess :: FilePath -> LBS.ByteString -> IO LBS.ByteString
+preprocess fn lbs = do
hunk ./src/Ho/Build.hs 629
-        initialOpts = f (LBSU.toString $ LBS.take 2048 lbs)
+        initialOpts = collectFileOpts fn (LBSU.toString $ LBS.take 2048 lbs)
hunk ./src/Ho/Build.hs 639
+    return lbs'
+
+
+parseHsSource :: String -> LBS.ByteString -> IO HsModule
+parseHsSource fn lbs = do
+    lbs' <- preprocess fn lbs
hunk ./src/Ho/Build.hs 655
-    case runParserWithMode (parseModeOptions $ f s) { parseFilename = fn } parse  s'  of
+    case runParserWithMode (parseModeOptions $ collectFileOpts fn s) { parseFilename = fn } parse  s'  of
hunk ./src/Main.hs 5
-import Control.Monad.Writer
hunk ./src/Main.hs 6
+import Control.Monad.Writer
hunk ./src/Main.hs 9
+import List as L
hunk ./src/Main.hs 11
+import System.Mem
+import qualified Data.ByteString.Lazy as LBS
hunk ./src/Main.hs 16
-import List as L
-import System.Mem
hunk ./src/Main.hs 17
-import Doc.PPrint
-import Util.Util
hunk ./src/Main.hs 19
+import Doc.PPrint
hunk ./src/Main.hs 24
-import E.Lint
hunk ./src/Main.hs 29
+import E.Lint
hunk ./src/Main.hs 39
+import FrontEnd.HsSyn
hunk ./src/Main.hs 52
-import Ho.Library
hunk ./src/Main.hs 53
-import FrontEnd.HsSyn
+import Ho.Library
hunk ./src/Main.hs 58
-import Support.FreeVars
hunk ./src/Main.hs 59
+import Support.FreeVars
hunk ./src/Main.hs 64
+import Util.Util
hunk ./src/Main.hs 66
-import qualified Version.Config as VC
hunk ./src/Main.hs 72
-import qualified Grin.Simplify
hunk ./src/Main.hs 73
+import qualified Grin.Simplify
+import qualified IO
hunk ./src/Main.hs 78
-import qualified IO
+import qualified Version.Config as VC
hunk ./src/Main.hs 114
+        Preprocess      -> forM_ (optArgs o) $ \fn -> do
+            LBS.readFile fn >>= preprocess fn >>= LBS.putStr
hunk ./src/Options.hs 132
-data Mode = BuildHl String -- ^ Build the specified hl-file given a description file.
-          | Interactive    -- ^ Run interactively.
-          | Version        -- ^ Print version and die.
-          | VersionCtx     -- ^ Print version context and die.
-          | ShowHelp       -- ^ Show help message and die.
-          | ShowConfig     -- ^ Show configuration info.
-          | CompileHo      -- ^ Compile ho
-          | CompileHoGrin  -- ^ Compile ho and grin
-          | CompileExe     -- ^ Compile executable
-          | ShowHo String  -- ^ Show ho-file.
-          | ListLibraries  -- ^ List libraries
+data Mode = BuildHl String  -- ^ Build the specified hl-file given a description file.
+          | Interactive     -- ^ Run interactively.
+          | Version         -- ^ Print version and die.
+          | VersionCtx      -- ^ Print version context and die.
+          | ShowHelp        -- ^ Show help message and die.
+          | ShowConfig      -- ^ Show configuration info.
+          | CompileHo       -- ^ Compile ho
+          | CompileHoGrin   -- ^ Compile ho and grin
+          | CompileExe      -- ^ Compile executable
+          | ShowHo String   -- ^ Show ho-file.
+          | ListLibraries   -- ^ List libraries
hunk ./src/Options.hs 144
+          | Preprocess      -- ^ Filter through preprocessor
hunk ./src/Options.hs 233
-    , Option ['C'] []            (NoArg  (optMode_s CompileHoGrin))    "Typecheck, compile ho and grin"
hunk ./src/Options.hs 234
+    , Option ['E'] []            (NoArg  (optMode_s Preprocess))       "preprocess the input and print result to stdout"