Changeset 2396 for src/Main.hs
- Timestamp:
- 04/27/05 15:02:41 (4 years ago)
- svk:copy_cache_prev:
- 3914
- Files:
-
- 1 modified
-
src/Main.hs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Main.hs
r2358 r2396 89 89 90 90 dump :: String -> IO () 91 dump = (doParseWith $ \exp _ -> print exp) "-" 92 93 comp :: String -> IO () 94 comp = (doParseWith $ \exp _ -> putStrLn =<< compile "Haskell" exp) "-" 91 dump = (doParseWith $ \env _ -> print $ envBody env) "-" 92 93 dumpGlob :: String -> IO () 94 dumpGlob = (doParseWith $ \env _ -> do 95 glob <- readIORef $ envGlobal env 96 print $ userDefined glob) "-" 97 98 userDefined :: Pad -> Pad 99 userDefined (MkPad pad) = MkPad $ Map.filterWithKey doFilter pad 100 where 101 doFilter (_:'*':_) _ = False 102 doFilter _ _ = True 95 103 96 104 repLoop :: IO () … … 117 125 118 126 doExternal :: String -> FilePath -> String -> IO () 119 doExternal mod = doParseWith $ \e xp_ -> do120 str <- externalize mod exp127 doExternal mod = doParseWith $ \env _ -> do 128 str <- externalize mod $ envBody env 121 129 putStrLn str 122 130 123 131 doCompile :: [Char] -> FilePath -> String -> IO () 124 doCompile backend = doParseWith $ \exp _ -> do 125 str <- compile backend exp 132 doCompile backend = doParseWith $ \env _ -> do 133 glob <- readIORef $ envGlobal env 134 globRef <- newIORef $ userDefined glob 135 str <- compile backend env{ envGlobal = globRef } 126 136 writeFile "dump.ast" str 127 137 128 doParseWith :: ( Pugs.AST.Exp-> FilePath -> IO a) -> FilePath -> String -> IO a138 doParseWith :: (Env -> FilePath -> IO a) -> FilePath -> String -> IO a 129 139 doParseWith f name prog = do 130 140 env <- emptyEnv [] 131 runRule env (f' . envBody)ruleProgram name $ decodeUTF8 prog132 where 133 f' (Val err@(VError _ _))= do141 runRule env f' ruleProgram name $ decodeUTF8 prog 142 where 143 f' Env{ envBody = Val err@(VError _ _) } = do 134 144 hPutStrLn stderr $ pretty err 135 145 exitFailure 136 f' e xp = f expname146 f' env = f env name 137 147 138 148
