mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-07 02:02:51 -06:00
Moved parser building in the PGF interpreter to PGF.hs from PGF/Raw/Convert.hs, in preparation for doing something more clever about it (e.g. looking at the parser flag).
This commit is contained in:
10
src/PGF.hs
10
src/PGF.hs
@@ -69,6 +69,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
|
||||||
@@ -204,7 +205,14 @@ complete :: PGF -> Language -> Category -> String
|
|||||||
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 (mkCId lang)
|
linearize pgf lang = concat . take 1 . PGF.Linearize.linearizes pgf (mkCId lang)
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ module PGF.Raw.Convert (toPGF,fromPGF) where
|
|||||||
import PGF.CId
|
import PGF.CId
|
||||||
import PGF.Data
|
import PGF.Data
|
||||||
import PGF.Raw.Abstract
|
import PGF.Raw.Abstract
|
||||||
import qualified GF.Compile.GeneratePMCFG as PMCFG
|
|
||||||
|
|
||||||
import Data.Array.IArray
|
import Data.Array.IArray
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
@@ -53,11 +52,7 @@ toConcr pgf rexp =
|
|||||||
lindefs = Map.empty,
|
lindefs = Map.empty,
|
||||||
printnames = Map.empty,
|
printnames = Map.empty,
|
||||||
paramlincats = Map.empty,
|
paramlincats = Map.empty,
|
||||||
parser = Just (PMCFG.convertConcrete (abstract pgf) cnc)
|
parser = Nothing
|
||||||
-- This thunk will be overwritten if there is a parser
|
|
||||||
-- compiled in the PGF file. We use lazy evaluation here
|
|
||||||
-- to make sure that buildParserOnDemand is called only
|
|
||||||
-- if it is needed.
|
|
||||||
}) rexp
|
}) rexp
|
||||||
in cnc
|
in cnc
|
||||||
where
|
where
|
||||||
|
|||||||
Reference in New Issue
Block a user