diff options
| author | aarne <unknown> | 2004-03-31 12:30:34 +0000 |
|---|---|---|
| committer | aarne <unknown> | 2004-03-31 12:30:34 +0000 |
| commit | 3f9b4e7855cf4594708a9fbad194c89540d2cf1e (patch) | |
| tree | 33dcbbd6d2e6e5f6290a25f65b4b9f90253fd34b /src/GF/Infra | |
| parent | 6719aedde34c3a4f0ccb78931968c6fe490b3282 (diff) | |
Added support for cf and ebnf formats
Diffstat (limited to 'src/GF/Infra')
| -rw-r--r-- | src/GF/Infra/Comments.hs | 29 | ||||
| -rw-r--r-- | src/GF/Infra/ReadFiles.hs | 22 |
2 files changed, 43 insertions, 8 deletions
diff --git a/src/GF/Infra/Comments.hs b/src/GF/Infra/Comments.hs new file mode 100644 index 000000000..442728b80 --- /dev/null +++ b/src/GF/Infra/Comments.hs @@ -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 diff --git a/src/GF/Infra/ReadFiles.hs b/src/GF/Infra/ReadFiles.hs index 06205e350..4172ee32e 100644 --- a/src/GF/Infra/ReadFiles.hs +++ b/src/GF/Infra/ReadFiles.hs @@ -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 |
