Changeset 2396 for src/Main.hs

Show
Ignore:
Timestamp:
04/27/05 15:02:41 (4 years ago)
Author:
autrijus
svk:copy_cache_prev:
3914
Message:

* compiler repaired.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Main.hs

    r2358 r2396  
    8989 
    9090dump :: String -> IO () 
    91 dump = (doParseWith $ \exp _ -> print exp) "-" 
    92  
    93 comp :: String -> IO () 
    94 comp = (doParseWith $ \exp _ -> putStrLn =<< compile "Haskell" exp) "-" 
     91dump = (doParseWith $ \env _ -> print $ envBody env) "-" 
     92 
     93dumpGlob :: String -> IO () 
     94dumpGlob = (doParseWith $ \env _ -> do 
     95    glob <- readIORef $ envGlobal env 
     96    print $ userDefined glob) "-" 
     97 
     98userDefined :: Pad -> Pad 
     99userDefined (MkPad pad) = MkPad $ Map.filterWithKey doFilter pad 
     100    where 
     101    doFilter (_:'*':_) _ = False 
     102    doFilter _ _         = True 
    95103 
    96104repLoop :: IO () 
     
    117125 
    118126doExternal :: String -> FilePath -> String -> IO () 
    119 doExternal mod = doParseWith $ \exp _ -> do 
    120     str <- externalize mod exp 
     127doExternal mod = doParseWith $ \env _ -> do 
     128    str <- externalize mod $ envBody env 
    121129    putStrLn str 
    122130 
    123131doCompile :: [Char] -> FilePath -> String -> IO () 
    124 doCompile backend = doParseWith $ \exp _ -> do 
    125     str <- compile backend exp 
     132doCompile backend = doParseWith $ \env _ -> do 
     133    glob    <- readIORef $ envGlobal env 
     134    globRef <- newIORef $ userDefined glob 
     135    str  <- compile backend env{ envGlobal = globRef } 
    126136    writeFile "dump.ast" str 
    127137 
    128 doParseWith :: (Pugs.AST.Exp -> FilePath -> IO a) -> FilePath -> String -> IO a 
     138doParseWith :: (Env -> FilePath -> IO a) -> FilePath -> String -> IO a 
    129139doParseWith f name prog = do 
    130140    env <- emptyEnv [] 
    131     runRule env (f' . envBody) ruleProgram name $ decodeUTF8 prog 
    132     where 
    133     f' (Val err@(VError _ _)) = do 
     141    runRule env f' ruleProgram name $ decodeUTF8 prog 
     142    where 
     143    f' Env{ envBody = Val err@(VError _ _) } = do 
    134144        hPutStrLn stderr $ pretty err 
    135145        exitFailure 
    136     f' exp = f exp name 
     146    f' env = f env name 
    137147 
    138148