Added on-demand parser generation back in. It's pretty unproblematic, and can help with memory use in some cases.

This commit is contained in:
bjorn
2008-10-20 14:05:39 +00:00
parent d6ef31ada2
commit e5a595567a
2 changed files with 13 additions and 1 deletions

View File

@@ -588,6 +588,10 @@ library
GF.Data.Assoc GF.Data.Assoc
GF.Data.ErrM GF.Data.ErrM
GF.Text.UTF8 GF.Text.UTF8
-- needed only for the on demand generation of PMCFG
GF.Data.BacktrackM
GF.Compile.GenerateFCFG
GF.Compile.GeneratePMCFG
executable gf executable gf
build-depends: base, build-depends: base,

View File

@@ -71,6 +71,7 @@ import PGF.Raw.Parse
import PGF.Raw.Print (printTree) import PGF.Raw.Print (printTree)
import PGF.Parsing.FCFG import PGF.Parsing.FCFG
import qualified PGF.Parsing.FCFG.Incremental as Incremental import qualified PGF.Parsing.FCFG.Incremental as Incremental
import qualified GF.Compile.GeneratePMCFG as PMCFG
import GF.Text.UTF8 import GF.Text.UTF8
import GF.Data.ErrM import GF.Data.ErrM
@@ -211,7 +212,14 @@ showLanguage = prCId
readPGF f = do readPGF f = do
s <- readFile f >>= return . decodeUTF8 -- pgf is in UTF8, internal in unicode s <- readFile f >>= return . decodeUTF8 -- pgf is in UTF8, internal in unicode
g <- parseGrammar s g <- parseGrammar s
return $! toPGF g return $! addParsers $ toPGF g
-- Adds parsers for all concretes that don't have a parser.
addParsers :: PGF -> PGF
addParsers pgf = pgf { concretes = Map.map conv (concretes pgf) }
where
conv cnc | isJust (parser cnc) = cnc
| otherwise = cnc { parser = Just (PMCFG.convertConcrete (abstract pgf) cnc) }
linearize pgf lang = concat . take 1 . PGF.Linearize.linearizes pgf lang linearize pgf lang = concat . take 1 . PGF.Linearize.linearizes pgf lang