summaryrefslogtreecommitdiff
path: root/src/compiler/GFC.hs
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2014-03-21 21:25:05 +0000
committerkr.angelov <kr.angelov@gmail.com>2014-03-21 21:25:05 +0000
commit51a9ef72c7e32f06d2413a5aea5751df2780063b (patch)
treedc7a0626ade80e5d5c621d9eb381ebaf8d15f50c /src/compiler/GFC.hs
parentd816c34986d3ecb4624d7638e290adddc941b38d (diff)
refactor the compilation of CFG and EBNF grammars. Now they are parsed by using GF.Grammar.Parser just like the ordinary GF grammars. Furthermore now GF.Speech.CFG is moved to GF.Grammar.CFG. The new module is used by both the speech conversion utils and by the compiler for CFG grammars. The parser for CFG now consumes a lot less memory and can be used with grammars with more than 4 000 000 productions.
Diffstat (limited to 'src/compiler/GFC.hs')
-rw-r--r--src/compiler/GFC.hs26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/compiler/GFC.hs b/src/compiler/GFC.hs
index acb4e21ab..8d548e449 100644
--- a/src/compiler/GFC.hs
+++ b/src/compiler/GFC.hs
@@ -8,10 +8,11 @@ import PGF.Optimize
import PGF.Binary(putSplitAbs)
import GF.Compile
import GF.Compile.Export
+import GF.Compile.CFGtoPGF
+import GF.Compile.GetGrammar
+import GF.Grammar.CFG
-import GF.Grammar.CF ---- should this be on a deeper level? AR 15/10/2008
import GF.Infra.Ident(identS,showIdent)
-
import GF.Infra.UseIO
import GF.Infra.Option
import GF.Data.ErrM
@@ -21,6 +22,7 @@ import Data.Maybe
import Data.Binary(encode,encodeFile)
import Data.Binary.Put(runPut)
import qualified Data.Map as Map
+import qualified Data.Set as Set
import qualified Data.ByteString as BSS
import qualified Data.ByteString.Lazy as BSL
import System.FilePath
@@ -61,14 +63,18 @@ compileSourceFiles opts fs =
writeOutputs opts pgf
compileCFFiles :: Options -> [FilePath] -> IOE ()
-compileCFFiles opts fs =
- do s <- liftIO $ fmap unlines $ mapM readFile fs
- let cnc = justModuleName (last fs)
- gr <- compileSourceGrammar opts =<< getCF cnc s
- unless (flag optStopAfterPhase opts == Compile) $
- do pgf <- link opts (identS cnc, (), gr)
- writePGF opts pgf
- writeOutputs opts pgf
+compileCFFiles opts fs = do
+ rules <- fmap concat $ mapM (getCFRules opts) fs
+ startCat <- case rules of
+ (CFRule cat _ _ : _) -> return cat
+ _ -> fail "empty CFG"
+ let gf = cf2gf (last fs) (uniqueFuns (mkCFG startCat Set.empty rules))
+ gr <- compileSourceGrammar opts gf
+ let cnc = justModuleName (last fs)
+ unless (flag optStopAfterPhase opts == Compile) $
+ do pgf <- link opts (identS cnc, (), gr)
+ writePGF opts pgf
+ writeOutputs opts pgf
unionPGFFiles :: Options -> [FilePath] -> IOE ()
unionPGFFiles opts fs =