forked from GitHub/gf-core
"Committed_by_peb"
This commit is contained in:
@@ -4,16 +4,16 @@
|
||||
-- Stability : (stable)
|
||||
-- Portability : (portable)
|
||||
--
|
||||
-- > CVS $Date: 2005/08/11 14:11:46 $
|
||||
-- > CVS $Date: 2005/09/01 09:53:18 $
|
||||
-- > CVS $Author: peb $
|
||||
-- > CVS $Revision: 1.13 $
|
||||
-- > CVS $Revision: 1.14 $
|
||||
--
|
||||
-- All conversions from GFC
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
module GF.Conversion.GFC
|
||||
(module GF.Conversion.GFC,
|
||||
SGrammar, MGrammar, CGrammar) where
|
||||
SGrammar, EGrammar, MGrammar, CGrammar) where
|
||||
|
||||
import GF.Infra.Option
|
||||
import GF.Canon.GFC (CanonGrammar)
|
||||
@@ -40,30 +40,39 @@ import GF.System.Tracing
|
||||
----------------------------------------------------------------------
|
||||
-- * GFC -> MCFG & CFG, using options to decide which conversion is used
|
||||
|
||||
gfc2mcfg2cfg :: Options -> (CanonGrammar, Ident) -> (MGrammar, CGrammar)
|
||||
gfc2mcfg2cfg opts = \g -> let e = g2e g in trace2 "Options" (show opts) (e2m e, e2c e)
|
||||
where e2c = mcfg2cfg
|
||||
convertGFC :: Options -> (CanonGrammar, Ident) -> (SGrammar, (EGrammar, (MGrammar, CGrammar)))
|
||||
convertGFC opts = \g -> let s = g2s g
|
||||
e = s2e s
|
||||
in trace2 "Options" (show opts) (s, (e, (e2m e, e2c e)))
|
||||
where e2c = M2C.convertGrammar
|
||||
e2m = case getOptVal opts firstCat of
|
||||
Just cat -> flip removeErasing [identC cat]
|
||||
Nothing -> flip removeErasing []
|
||||
g2e = case getOptVal opts gfcConversion of
|
||||
Just "strict" -> simple2mcfg_strict . gfc2simple
|
||||
Just "finite" -> simple2mcfg_nondet . simple2finite . gfc2simple
|
||||
Just "singletons" -> simple2mcfg_nondet . removeSingletons . gfc2simple
|
||||
Just "epsilon" -> removeEpsilon . simple2mcfg_nondet . gfc2simple
|
||||
Just "finite-singletons" -> simple2mcfg_nondet . removeSingletons . simple2finite . gfc2simple
|
||||
Just "finite-strict" -> simple2mcfg_strict . simple2finite . gfc2simple
|
||||
_ -> simple2mcfg_nondet . gfc2simple
|
||||
Just cat -> flip RemEra.convertGrammar [identC cat]
|
||||
Nothing -> flip RemEra.convertGrammar []
|
||||
s2e = case getOptVal opts gfcConversion of
|
||||
Just "strict" -> S2M.convertGrammarStrict
|
||||
Just "finite-strict" -> S2M.convertGrammarStrict
|
||||
Just "epsilon" -> RemEps.convertGrammar . S2M.convertGrammarNondet
|
||||
_ -> S2M.convertGrammarNondet
|
||||
g2s = case getOptVal opts gfcConversion of
|
||||
Just "finite" -> S2Fin.convertGrammar . G2S.convertGrammar
|
||||
Just "singletons" -> RemSing.convertGrammar . G2S.convertGrammar
|
||||
Just "finite-singletons" -> RemSing.convertGrammar . S2Fin.convertGrammar . G2S.convertGrammar
|
||||
Just "finite-strict" -> S2Fin.convertGrammar . G2S.convertGrammar
|
||||
_ -> G2S.convertGrammar
|
||||
|
||||
gfc2simple :: Options -> (CanonGrammar, Ident) -> SGrammar
|
||||
gfc2simple opts = fst . convertGFC opts
|
||||
|
||||
gfc2mcfg :: Options -> (CanonGrammar, Ident) -> MGrammar
|
||||
gfc2mcfg opts = fst . gfc2mcfg2cfg opts
|
||||
gfc2mcfg opts = fst . snd . snd . convertGFC opts
|
||||
|
||||
gfc2cfg :: Options -> (CanonGrammar, Ident) -> CGrammar
|
||||
gfc2cfg opts = snd . gfc2mcfg2cfg opts
|
||||
gfc2cfg opts = snd . snd . snd . convertGFC opts
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- * single step conversions
|
||||
|
||||
{-
|
||||
gfc2simple :: (CanonGrammar, Ident) -> SGrammar
|
||||
gfc2simple = G2S.convertGrammar
|
||||
|
||||
@@ -74,7 +83,7 @@ removeSingletons :: SGrammar -> SGrammar
|
||||
removeSingletons = RemSing.convertGrammar
|
||||
|
||||
simple2mcfg_nondet :: SGrammar -> EGrammar
|
||||
simple2mcfg_nondet = S2M.convertGrammarNondet
|
||||
simple2mcfg_nondet =
|
||||
|
||||
simple2mcfg_strict :: SGrammar -> EGrammar
|
||||
simple2mcfg_strict = S2M.convertGrammarStrict
|
||||
@@ -87,13 +96,14 @@ removeErasing = RemEra.convertGrammar
|
||||
|
||||
removeEpsilon :: EGrammar -> EGrammar
|
||||
removeEpsilon = RemEps.convertGrammar
|
||||
-}
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- * converting to some obscure formats
|
||||
|
||||
gfc2abstract :: (CanonGrammar, Ident) -> [Abstract SCat Fun]
|
||||
gfc2abstract gr = [ Abs (decl2cat decl) (map decl2cat decls) (name2fun name) |
|
||||
Rule (Abs decl decls name) _ <- gfc2simple gr ]
|
||||
Rule (Abs decl decls name) _ <- G2S.convertGrammar gr ]
|
||||
|
||||
abstract2skvatt :: [Abstract SCat Fun] -> String
|
||||
abstract2skvatt gr = skvatt_hdr ++ concatMap abs2pl gr
|
||||
|
||||
Reference in New Issue
Block a user