work on cf

This commit is contained in:
aarne
2005-11-15 16:56:13 +00:00
parent 1fd1f44fcc
commit 2cea1a25bb
2 changed files with 16 additions and 11 deletions

View File

@@ -5,9 +5,9 @@
-- Stability : (stable) -- Stability : (stable)
-- Portability : (portable) -- Portability : (portable)
-- --
-- > CVS $Date: 2005/11/15 11:43:33 $ -- > CVS $Date: 2005/11/15 17:56:13 $
-- > CVS $Author: aarne $ -- > CVS $Author: aarne $
-- > CVS $Revision: 1.12 $ -- > CVS $Revision: 1.13 $
-- --
-- printing and parsing CF grammars, rules, and trees AR 26/1/2000 -- 9/6/2003 -- printing and parsing CF grammars, rules, and trees AR 26/1/2000 -- 9/6/2003
-- --
@@ -89,11 +89,11 @@ getCFRule mo s = getcf (wrds s) where
clean = filter isAlphaNum -- to form valid identifiers clean = filter isAlphaNum -- to form valid identifiers
wrds = takeWhile (/= ";") . words -- to permit semicolon in the end wrds = takeWhile (/= ";") . words -- to permit semicolon in the end
pCF :: String -> String -> Err CF pCF :: String -> String -> Err [CFRule]
pCF mo s = do pCF mo s = do
rules <- mapM (getCFRule mo) $ filter isRule $ lines s rules <- mapM (getCFRule mo) $ filter isRule $ lines s
return $ rules2CF $ concat rules return $ concat rules
where where
isRule line = case line of isRule line = case dropWhile isSpace line of
'-':'-':_ -> False '-':'-':_ -> False
_ -> not $ all isSpace line _ -> not $ all isSpace line

View File

@@ -5,9 +5,9 @@
-- Stability : (stable) -- Stability : (stable)
-- Portability : (portable) -- Portability : (portable)
-- --
-- > CVS $Date: 2005/04/21 16:21:37 $ -- > CVS $Date: 2005/11/15 17:56:13 $
-- > CVS $Author: bringert $ -- > CVS $Author: aarne $
-- > CVS $Revision: 1.15 $ -- > CVS $Revision: 1.16 $
-- --
-- this module builds the internal GF grammar that is sent to the type checker -- this module builds the internal GF grammar that is sent to the type checker
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
@@ -32,6 +32,7 @@ import GF.Infra.Option
import GF.Source.ParGF import GF.Source.ParGF
import qualified GF.Source.LexGF as L import qualified GF.Source.LexGF as L
import GF.CF.CF (rules2CF)
import GF.CF.PPrCF import GF.CF.PPrCF
import GF.CF.CFtoGrammar import GF.CF.CFtoGrammar
import GF.CF.EBNF import GF.CF.EBNF
@@ -103,9 +104,13 @@ oldLexer = map change . L.tokens where
getCFGrammar :: Options -> FilePath -> IOE SourceGrammar getCFGrammar :: Options -> FilePath -> IOE SourceGrammar
getCFGrammar opts file = do getCFGrammar opts file = do
let mo = takeWhile (/='.') file let mo = takeWhile (/='.') file
s <- ioeIO $ readFileIf file s <- ioeIO $ readFileIf file
cf <- ioeErr $ pCF mo s let files = case words (concat (take 1 (lines s))) of
defs <- return $ cf2grammar cf "--":"include":fs -> fs
_ -> []
ss <- ioeIO $ mapM readFileIf files
cfs <- ioeErr $ mapM (pCF mo) $ s:ss
defs <- return $ cf2grammar $ rules2CF $ concat cfs
let g = A.OldGr A.NoIncl defs let g = A.OldGr A.NoIncl defs
--- let ma = justModuleName file --- let ma = justModuleName file
--- let mc = 'C':ma --- --- let mc = 'C':ma ---