Changeset 4914 for src/Main.hs

Show
Ignore:
Timestamp:
06/22/05 20:57:31 (4 years ago)
Author:
autrijus
svk:copy_cache_prev:
6641
Message:

* 01-sanity/07-test.t is now working!

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Main.hs

    r4913 r4914  
    2929import Pugs.Trans 
    3030import Pugs.Embed 
     31import Pugs.Prim.Eval (requireInc) 
    3132import qualified Data.Map as Map 
    3233import Data.IORef 
     
    7475 
    7576run ("-C":backend:"-e":prog:_)           = doCompileDump backend "-e" prog 
    76 run ("-C":backend:file:_)                = readFile file >>= doCompileDump backend file 
     77run ("-C":backend:file:_)                = slurpFile file >>= doCompileDump backend file 
    7778 
    7879run ("-B":backend:"-e":prog:_)           = doCompileRun backend "-e" prog 
    79 run ("-B":backend:file:_)                = readFile file >>= doCompileRun backend file 
     80run ("-B":backend:file:_)                = slurpFile file >>= doCompileRun backend file 
    8081 
    8182run ("--external":mod:"-e":prog:_)    = doExternal mod "-e" prog 
     
    312313    writeFile "a.pir" pir 
    313314    evalParrotFile "a.pir" 
     315 
     316slurpFile :: FilePath -> IO String 
     317slurpFile file = do 
     318    prog <- readFile file 
     319    libs <- getLibs 
     320    file <- expandInc libs prog 
     321    -- writeFile "ZZZ" file 
     322    return file 
     323    where 
     324    expandInc :: [FilePath] -> String -> IO String 
     325    expandInc incs str = case breakOnGlue "\nuse " str of 
     326        Nothing -> return str 
     327        Just (pre, post) -> do 
     328            let (mod, (_:rest)) = span isAlphaNum (dropWhile isSpace post) 
     329            mod'    <- includeInc incs mod 
     330            rest'   <- expandInc incs rest 
     331            return $ pre ++ mod' ++ rest' 
     332    includeInc :: [FilePath] -> String -> IO String 
     333    includeInc _ ('v':_) = return [] 
     334    includeInc incs name = do 
     335        let name' = concat (intersperse "/" names) ++ ".pm" 
     336            names = split "::" name 
     337        pathName    <- requireInc incs name' (errMsg name incs) 
     338        readFile pathName 
     339    errMsg file incs = "Can't locate " ++ file ++ " in @*INC (@*INC contains: " ++ unwords incs ++ ")." 
     340