Added support for cf and ebnf formats

This commit is contained in:
aarne
2004-03-31 12:30:34 +00:00
parent f0cbb89778
commit 8d828c46d5
17 changed files with 280 additions and 31 deletions

29
src/GF/Infra/Comments.hs Normal file
View File

@@ -0,0 +1,29 @@
module Comments where
-- comment removal : line tails prefixed by -- as well as chunks in {- ... -}
remComments :: String -> String
remComments s =
case s of
'"':s2 -> '"':pass remComments s2 -- comment marks in quotes not removed!
'{':'-':cs -> readNested cs
'-':'-':cs -> readTail cs
c:cs -> c : remComments cs
[] -> []
where
readNested t =
case t of
'"':s2 -> '"':pass readNested s2
'-':'}':cs -> remComments cs
_:cs -> readNested cs
[] -> []
readTail t =
case t of
'\n':cs -> '\n':remComments cs
_:cs -> readTail cs
[] -> []
pass f t =
case t of
'"':s2 -> '"': f s2
c:s2 -> c:pass f s2
_ -> t

View File

@@ -27,15 +27,15 @@ import List
type ModName = String
type ModEnv = [(ModName,ModTime)]
getAllFiles :: [InitPath] -> ModEnv -> FileName -> IOE [FullPath]
getAllFiles ps env file = do
getAllFiles :: Options -> [InitPath] -> ModEnv -> FileName -> IOE [FullPath]
getAllFiles opts ps env file = do
-- read module headers from all files recursively
ds0 <- getImports ps file
let ds = [((snd m,map fst ms),p) | ((m,ms),p) <- ds0]
ioeIO $ putStrLn $ "all modules:" +++ show (map (fst . fst) ds)
-- get a topological sorting of files: returns file names --- deletes paths
-- get a topological sorting of files: returns file names --- deletes paths
ds1 <- ioeErr $ either
return
(\ms -> Bad $ "circular modules" +++
@@ -44,12 +44,15 @@ getAllFiles ps env file = do
-- associate each file name with its path --- more optimal: save paths in ds1
let paths = [(f,p) | ((f,_),p) <- ds]
let pds1 = [(p,f) | f <- ds1, Just p <- [lookup f paths]]
if oElem fromSource opts
then return [gfFile (prefixPathName p f) | (p,f) <- pds1]
else do
ds2 <- ioeIO $ mapM (selectFormat env) pds1
ds2 <- ioeIO $ mapM (selectFormat env) pds1
let ds4 = needCompile (map fst ds0) ds2
return ds4
let ds4 = needCompile opts (map fst ds0) ds2
return ds4
-- to decide whether to read gf or gfc, or if in env; returns full file path
@@ -77,8 +80,9 @@ selectFormat env (p,f) = do
return $ (f, (p,stat))
needCompile :: [ModuleHeader] -> [(ModName,(InitPath,CompStatus))] -> [FullPath]
needCompile headers sfiles0 = paths $ res $ mark $ iter changed where
needCompile :: Options ->
[ModuleHeader] -> [(ModName,(InitPath,CompStatus))] -> [FullPath]
needCompile opts headers sfiles0 = paths $ res $ mark $ iter changed where
deps = [(snd m,map fst ms) | (m,ms) <- headers]
typ m = maybe MTyOther id $ lookup m [(m,t) | ((t,m),_) <- headers]
@@ -117,10 +121,12 @@ needCompile headers sfiles0 = paths $ res $ mark $ iter changed where
-- if a compilable file depends on a resource, read gfr instead of gfc/env
-- but don't read gfr if already in env (by CSEnvR)
-- Also read res if the option "retain" is present
res cs = map mkRes cs where
mkRes x@(f,(path,st)) | elem st [CSRead,CSEnv] = case typ f of
MTyResource | not (null [m | (m,(_,CSComp)) <- cs,
Just ms <- [lookup m allDeps], elem f ms])
|| oElem retainOpers opts
-> (f,(path,CSRes))
_ -> x
mkRes x = x