X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fmain%2FGetImports.hs;h=249e1e14f111cb2c604df47c79f696932c430d8f;hb=ef5b4b146aa172d8ac10f39b5eb3d7a0f948d8f1;hp=84d6831c62d013e66cb4adf278af13014cde1e04;hpb=9e4bf486821e06cd3813d3aada6cd8e3acff05a4;p=ghc-hetmet.git diff --git a/ghc/compiler/main/GetImports.hs b/ghc/compiler/main/GetImports.hs index 84d6831..249e1e1 100644 --- a/ghc/compiler/main/GetImports.hs +++ b/ghc/compiler/main/GetImports.hs @@ -1,5 +1,5 @@ ----------------------------------------------------------------------------- --- $Id: GetImports.hs,v 1.7 2001/05/29 01:07:00 sof Exp $ +-- $Id: GetImports.hs,v 1.11 2004/11/26 16:20:57 simonmar Exp $ -- -- GHC Driver program -- @@ -18,7 +18,7 @@ import Char -- getImportsFromFile is careful to close the file afterwards, otherwise -- we can end up with a large number of open handles before the garbage -- collector gets around to closing them. -getImportsFromFile :: String -> IO ([ModuleName], [ModuleName], ModuleName) +getImportsFromFile :: String -> IO ([Module], [Module], Module) getImportsFromFile filename = do hdl <- openFile filename ReadMode modsrc <- hGetContents hdl @@ -27,11 +27,11 @@ getImportsFromFile filename hClose hdl return (srcimps,imps,mod_name) -getImports :: String -> ([ModuleName], [ModuleName], ModuleName) +getImports :: String -> ([Module], [Module], Module) getImports s = case f [{-accum source imports-}] [{-accum normal imports-}] Nothing (clean s) of - (si, ni, Nothing) -> (si, ni, mkModuleName "Main") + (si, ni, Nothing) -> (si, ni, mkModule "Main") (si, ni, Just me) -> (si, ni, me) where -- Only pick up the name following 'module' the first time. @@ -59,8 +59,8 @@ getImports s f si ni me (w:ws) = f si ni me ws f si ni me [] = (nub si, nub ni, me) - mkMN str = mkModuleName (takeWhile isModId (reverse str)) - isModId c = isAlphaNum c || c `elem` "'_" + mkMN str = mkModule (takeWhile isModId (reverse str)) + isModId c = isAlphaNum c || c `elem` "'._" -- remove literals and comments from a string, producing a @@ -83,6 +83,10 @@ clean s keep acc ('-':'-':cs) = cons acc (linecomment cs) keep acc ('{':'-':'#':' ':cs) = cons acc (cons "#-{" (keep "" cs)) keep acc ('{':'-':cs) = cons acc (runcomment (0::Int) cs) -- -} + keep acc ('{':cs) = cons acc (keep "" cs) + keep acc (';':cs) = cons acc (keep "" cs) + -- treat ';' and '{' as word separators so that stuff + -- like "{import A;" and ";;;;import B;" are handled correctly. keep acc (c:cs) = keep (c:acc) cs cons [] xs = xs