forked from GitHub/gf-core
questions and transfer in shell state
This commit is contained in:
@@ -63,6 +63,8 @@ import GF.UseGrammar.Editing
|
|||||||
|
|
||||||
----import GrammarToMGrammar as M
|
----import GrammarToMGrammar as M
|
||||||
|
|
||||||
|
import qualified Transfer.InterpreterAPI as T
|
||||||
|
|
||||||
import GF.System.Arch (myStdGen)
|
import GF.System.Arch (myStdGen)
|
||||||
|
|
||||||
import GF.Text.UTF8
|
import GF.Text.UTF8
|
||||||
@@ -356,6 +358,23 @@ wrapByFun opts gr f t =
|
|||||||
t' = qualifTerm (absId gr) $ M.appCons f [tree2exp t]
|
t' = qualifTerm (absId gr) $ M.appCons f [tree2exp t]
|
||||||
g = grammar gr
|
g = grammar gr
|
||||||
|
|
||||||
|
applyTransfer :: Options -> GFGrammar -> [(Ident,T.Env)] ->
|
||||||
|
(Maybe Ident,Ident) -> Tree -> Tree
|
||||||
|
applyTransfer opts gr trs (mm,f) t =
|
||||||
|
err (const t) id $ annotate g t'
|
||||||
|
where
|
||||||
|
t' = qualifTerm (absId gr) $ trans tr f $ tree2exp t
|
||||||
|
g = grammar gr
|
||||||
|
tr = case mm of
|
||||||
|
Just m -> maybe empty id $ lookup m trs
|
||||||
|
_ -> ifNull empty (snd . head) trs
|
||||||
|
|
||||||
|
-- these are missing
|
||||||
|
trans = error "no transfer yet"
|
||||||
|
----- core2exp . T.appTransfer tr . exp2core
|
||||||
|
empty = error "emptyEnv"
|
||||||
|
---- T.emptyEnv
|
||||||
|
|
||||||
{-
|
{-
|
||||||
optTransfer :: Options -> StateGrammar -> G.Term -> G.Term
|
optTransfer :: Options -> StateGrammar -> G.Term -> G.Term
|
||||||
optTransfer opts g = case getOptVal opts transferFun of
|
optTransfer opts g = case getOptVal opts transferFun of
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ import GF.Data.Operations
|
|||||||
import GF.Infra.UseIO
|
import GF.Infra.UseIO
|
||||||
import GF.System.Arch
|
import GF.System.Arch
|
||||||
|
|
||||||
|
import qualified Transfer.InterpreterAPI as T
|
||||||
|
|
||||||
import Control.Monad (liftM)
|
import Control.Monad (liftM)
|
||||||
|
|
||||||
-- | a heuristic way of renaming constants is used
|
-- | a heuristic way of renaming constants is used
|
||||||
@@ -56,6 +58,9 @@ shellStateFromFiles opts st file = do
|
|||||||
ign <- ioeIO $ getNoparseFromFile opts file
|
ign <- ioeIO $ getNoparseFromFile opts file
|
||||||
let top = identC $ justModuleName file
|
let top = identC $ justModuleName file
|
||||||
sh <- case fileSuffix file of
|
sh <- case fileSuffix file of
|
||||||
|
"trc" -> do
|
||||||
|
env <- ioeIO $ T.loadFile file
|
||||||
|
return $ addTransfer (top,env) st
|
||||||
"gfcm" -> do
|
"gfcm" -> do
|
||||||
cenv <- compileOne opts (compileEnvShSt st []) file
|
cenv <- compileOne opts (compileEnvShSt st []) file
|
||||||
ioeErr $ updateShellState opts ign Nothing st cenv
|
ioeErr $ updateShellState opts ign Nothing st cenv
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ import GF.Infra.Option
|
|||||||
import GF.Infra.Ident
|
import GF.Infra.Ident
|
||||||
import GF.System.Arch (ModTime)
|
import GF.System.Arch (ModTime)
|
||||||
|
|
||||||
|
import qualified Transfer.InterpreterAPI as T
|
||||||
|
|
||||||
import qualified GF.OldParsing.ConvertGrammar as CnvOld -- OBSOLETE
|
import qualified GF.OldParsing.ConvertGrammar as CnvOld -- OBSOLETE
|
||||||
import qualified GF.Conversion.GFC as Cnv
|
import qualified GF.Conversion.GFC as Cnv
|
||||||
import qualified GF.Parsing.GFC as Prs
|
import qualified GF.Parsing.GFC as Prs
|
||||||
@@ -67,7 +69,8 @@ data ShellState = ShSt {
|
|||||||
[((G.Fun,Int),G.Type)]))], -- ^ cats, (their contexts,
|
[((G.Fun,Int),G.Type)]))], -- ^ cats, (their contexts,
|
||||||
-- functions to them,
|
-- functions to them,
|
||||||
-- functions on them)
|
-- functions on them)
|
||||||
statistics :: [Statistics] -- ^ statistics on grammars
|
statistics :: [Statistics], -- ^ statistics on grammars
|
||||||
|
transfers :: [(Ident,T.Env)] -- ^ transfer modules
|
||||||
}
|
}
|
||||||
|
|
||||||
actualConcretes :: ShellState -> [((Ident,Ident),Bool)]
|
actualConcretes :: ShellState -> [((Ident,Ident),Bool)]
|
||||||
@@ -103,7 +106,8 @@ emptyShellState = ShSt {
|
|||||||
gloptions = noOptions,
|
gloptions = noOptions,
|
||||||
readFiles = [],
|
readFiles = [],
|
||||||
absCats = [],
|
absCats = [],
|
||||||
statistics = []
|
statistics = [],
|
||||||
|
transfers = []
|
||||||
}
|
}
|
||||||
|
|
||||||
optInitShellState :: Options -> ShellState
|
optInitShellState :: Options -> ShellState
|
||||||
@@ -247,7 +251,8 @@ updateShellState opts ign mcnc sh ((_,sgr,gr),rts) = do
|
|||||||
gloptions = gloptions sh, --- opts, -- this would be command-line options
|
gloptions = gloptions sh, --- opts, -- this would be command-line options
|
||||||
readFiles = [ft | ft@(f,_) <- readFiles sh, notInrts f] ++ rts,
|
readFiles = [ft | ft@(f,_) <- readFiles sh, notInrts f] ++ rts,
|
||||||
absCats = csi,
|
absCats = csi,
|
||||||
statistics = [StDepTypes deps,StBoundVars binds]
|
statistics = [StDepTypes deps,StBoundVars binds],
|
||||||
|
transfers = transfers sh
|
||||||
}
|
}
|
||||||
|
|
||||||
prShellStateInfo :: ShellState -> String
|
prShellStateInfo :: ShellState -> String
|
||||||
@@ -259,7 +264,8 @@ prShellStateInfo sh = unlines [
|
|||||||
"all concretes : " +++ unwords (map (P.prt . fst . fst) (concretes sh)),
|
"all concretes : " +++ unwords (map (P.prt . fst . fst) (concretes sh)),
|
||||||
"canonical modules :" +++ unwords (map (P.prt .fst) (M.modules (canModules sh))),
|
"canonical modules :" +++ unwords (map (P.prt .fst) (M.modules (canModules sh))),
|
||||||
"source modules : " +++ unwords (map (P.prt .fst) (M.modules (srcModules sh))),
|
"source modules : " +++ unwords (map (P.prt .fst) (M.modules (srcModules sh))),
|
||||||
"global options : " +++ prOpts (gloptions sh)
|
"global options : " +++ prOpts (gloptions sh),
|
||||||
|
"transfer modules : " +++ unwords (map (P.prt . fst) (transfers sh))
|
||||||
]
|
]
|
||||||
|
|
||||||
{- ---- should be called from IOGrammar *before* compiling
|
{- ---- should be called from IOGrammar *before* compiling
|
||||||
@@ -309,7 +315,8 @@ purgeShellState sh = ShSt {
|
|||||||
gloptions = gloptions sh,
|
gloptions = gloptions sh,
|
||||||
readFiles = [],
|
readFiles = [],
|
||||||
absCats = absCats sh,
|
absCats = absCats sh,
|
||||||
statistics = statistics sh
|
statistics = statistics sh,
|
||||||
|
transfers = transfers sh
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
abstr = abstract sh
|
abstr = abstract sh
|
||||||
@@ -320,17 +327,17 @@ purgeShellState sh = ShSt {
|
|||||||
acncs = maybe [] singleton abstr ++ map (snd . fst) (actualConcretes sh)
|
acncs = maybe [] singleton abstr ++ map (snd . fst) (actualConcretes sh)
|
||||||
|
|
||||||
changeMain :: Maybe Ident -> ShellState -> Err ShellState
|
changeMain :: Maybe Ident -> ShellState -> Err ShellState
|
||||||
changeMain Nothing (ShSt _ _ cs ms ss cfs old_pis mcfgs cfgs pinfos mos pbs os rs acs s) =
|
changeMain Nothing (ShSt _ _ cs ms ss cfs old_pis mcfgs cfgs pinfos mos pbs os rs acs s trs) =
|
||||||
return (ShSt Nothing Nothing [] ms ss cfs old_pis mcfgs cfgs pinfos mos pbs os rs acs s)
|
return (ShSt Nothing Nothing [] ms ss cfs old_pis mcfgs cfgs pinfos mos pbs os rs acs s trs)
|
||||||
changeMain
|
changeMain
|
||||||
(Just c) st@(ShSt _ _ cs ms ss cfs old_pis mcfgs cfgs pinfos mos pbs os rs acs s) =
|
(Just c) st@(ShSt _ _ cs ms ss cfs old_pis mcfgs cfgs pinfos mos pbs os rs acs s trs) =
|
||||||
case lookup c (M.modules ms) of
|
case lookup c (M.modules ms) of
|
||||||
Just _ -> do
|
Just _ -> do
|
||||||
a <- M.abstractOfConcrete ms c
|
a <- M.abstractOfConcrete ms c
|
||||||
let cas = M.allConcretes ms a
|
let cas = M.allConcretes ms a
|
||||||
let cs' = [((c,c),True) | c <- cas]
|
let cs' = [((c,c),True) | c <- cas]
|
||||||
return (ShSt (Just a) (Just c) cs' ms ss cfs old_pis mcfgs cfgs
|
return (ShSt (Just a) (Just c) cs' ms ss cfs old_pis mcfgs cfgs
|
||||||
pinfos mos pbs os rs acs s)
|
pinfos mos pbs os rs acs s trs)
|
||||||
_ -> P.prtBad "The state has no concrete syntax named" c
|
_ -> P.prtBad "The state has no concrete syntax named" c
|
||||||
|
|
||||||
-- | form just one state grammar, if unique, from a canonical grammar
|
-- | form just one state grammar, if unique, from a canonical grammar
|
||||||
@@ -482,13 +489,14 @@ stateIsWord :: StateGrammar -> String -> Bool
|
|||||||
stateIsWord sg = isKnownWord (stateMorpho sg)
|
stateIsWord sg = isKnownWord (stateMorpho sg)
|
||||||
|
|
||||||
addProbs :: (Ident,Probs) -> ShellState -> Err ShellState
|
addProbs :: (Ident,Probs) -> ShellState -> Err ShellState
|
||||||
addProbs ip@(lang,probs)
|
addProbs ip@(lang,probs) sh = do
|
||||||
sh@(ShSt x y cs ms ss cfs old_pis mcfgs cfgs pinfos mos pbs os rs acs s) = do
|
|
||||||
let gr = grammarOfLang sh lang
|
let gr = grammarOfLang sh lang
|
||||||
probs' <- checkGrammarProbs gr probs
|
probs' <- checkGrammarProbs gr probs
|
||||||
let pbs' = (lang,probs') : filter ((/= lang) . fst) pbs
|
let pbs' = (lang,probs') : filter ((/= lang) . fst) (probss sh)
|
||||||
return (ShSt x y cs ms ss cfs old_pis mcfgs cfgs pinfos mos pbs' os rs acs s)
|
return $ sh{probss = pbs'}
|
||||||
|
|
||||||
|
addTransfer :: (Ident,T.Env) -> ShellState -> ShellState
|
||||||
|
addTransfer it sh = sh {transfers = it : transfers sh}
|
||||||
|
|
||||||
{-
|
{-
|
||||||
|
|
||||||
@@ -543,10 +551,8 @@ languageOff = languageOnOff False
|
|||||||
|
|
||||||
languageOnOff :: Bool -> Language -> ShellStateOper
|
languageOnOff :: Bool -> Language -> ShellStateOper
|
||||||
--- __________ this is OBSOLETE
|
--- __________ this is OBSOLETE
|
||||||
languageOnOff b lang
|
languageOnOff b lang sh = sh {concretes = cs'} where
|
||||||
(ShSt a c cs cg sg cfs old_pinfos mcfgs cfgs pinfos ms pbs os fs cats sts) =
|
cs' = [if lang==l then (lc,b) else i | i@(lc@(l,c),_) <- concretes sh]
|
||||||
ShSt a c cs' cg sg cfs old_pinfos mcfgs cfgs pinfos ms pbs os fs cats sts where
|
|
||||||
cs' = [if lang==l then (lc,b) else i | i@(lc@(l,c),_) <- cs]
|
|
||||||
|
|
||||||
{-
|
{-
|
||||||
updateLanguage :: FilePath -> (Language, StateConcrete) -> ShellStateOper
|
updateLanguage :: FilePath -> (Language, StateConcrete) -> ShellStateOper
|
||||||
@@ -564,15 +570,13 @@ removeLanguage lang (ShSt (ab,gs,os)) = ShSt (ab,removeAssoc lang gs, os)
|
|||||||
|
|
||||||
changeOptions :: (Options -> Options) -> ShellStateOper
|
changeOptions :: (Options -> Options) -> ShellStateOper
|
||||||
--- __________ this is OBSOLETE
|
--- __________ this is OBSOLETE
|
||||||
changeOptions f
|
changeOptions f sh = sh {gloptions = f (gloptions sh)}
|
||||||
(ShSt a c cs can src cfs old_pinfos mcfgs cfgs pinfos ms pbs os ff ts ss) =
|
|
||||||
ShSt a c cs can src cfs old_pinfos mcfgs cfgs pinfos ms pbs (f os) ff ts ss
|
|
||||||
|
|
||||||
changeModTimes :: [(FilePath,ModTime)] -> ShellStateOper
|
changeModTimes :: [(FilePath,ModTime)] -> ShellStateOper
|
||||||
--- __________ this is OBSOLETE
|
--- __________ this is OBSOLETE
|
||||||
changeModTimes mfs
|
changeModTimes mfs
|
||||||
(ShSt a c cs can src cfs old_pinfos mcfgs cfgs pinfos ms pbs os ff ts ss) =
|
(ShSt a c cs can src cfs old_pinfos mcfgs cfgs pinfos ms pbs os ff ts ss trs) =
|
||||||
ShSt a c cs can src cfs old_pinfos mcfgs cfgs pinfos ms pbs os ff' ts ss
|
ShSt a c cs can src cfs old_pinfos mcfgs cfgs pinfos ms pbs os ff' ts ss trs
|
||||||
where
|
where
|
||||||
ff' = mfs ++ [mf | mf@(f,_) <- ff, notElem f (map fst mfs)]
|
ff' = mfs ++ [mf | mf@(f,_) <- ff, notElem f (map fst mfs)]
|
||||||
|
|
||||||
|
|||||||
@@ -301,6 +301,7 @@ execC co@(comm, opts0) sa@(sh@(st,(h,_,_,_)),a) = checkOptions st co >> case com
|
|||||||
CPutTerm -> changeArg (opTT2CommandArg (optTermCommand opts gro) . s2t) sa
|
CPutTerm -> changeArg (opTT2CommandArg (optTermCommand opts gro) . s2t) sa
|
||||||
|
|
||||||
CWrapTerm f -> changeArg (opTT2CommandArg (return . wrapByFun opts gro f)) sa
|
CWrapTerm f -> changeArg (opTT2CommandArg (return . wrapByFun opts gro f)) sa
|
||||||
|
CApplyTransfer f -> changeArg (opTT2CommandArg (return . applyTransfer opts gro transfs f)) sa
|
||||||
CMorphoAnalyse -> changeArg (AString . morphoAnalyse opts gro . prCommandArg) sa
|
CMorphoAnalyse -> changeArg (AString . morphoAnalyse opts gro . prCommandArg) sa
|
||||||
CTestTokenizer -> changeArg (AString . optTokenizer opts gro . prCommandArg) sa
|
CTestTokenizer -> changeArg (AString . optTokenizer opts gro . prCommandArg) sa
|
||||||
|
|
||||||
@@ -395,6 +396,8 @@ execC co@(comm, opts0) sa@(sh@(st,(h,_,_,_)),a) = checkOptions st co >> case com
|
|||||||
src = srcModules st
|
src = srcModules st
|
||||||
cgr = canModules st
|
cgr = canModules st
|
||||||
|
|
||||||
|
transfs = transfers st
|
||||||
|
|
||||||
s2t a = case a of
|
s2t a = case a of
|
||||||
ASTrm ('$':c) -> maybe (AError "undefined term") (ATrms . return) $ lookupShTerm sh c
|
ASTrm ('$':c) -> maybe (AError "undefined term") (ATrms . return) $ lookupShTerm sh c
|
||||||
ASTrm s -> err AError (ATrms . return) $ string2treeErr gro s
|
ASTrm s -> err AError (ATrms . return) $ string2treeErr gro s
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ pCommand ws = case ws of
|
|||||||
"gt" : t -> aTerm CGenerateTrees t
|
"gt" : t -> aTerm CGenerateTrees t
|
||||||
"pt" : s -> aTerm CPutTerm s
|
"pt" : s -> aTerm CPutTerm s
|
||||||
"wt" : f : s -> aTerm (CWrapTerm (pzIdent f)) s
|
"wt" : f : s -> aTerm (CWrapTerm (pzIdent f)) s
|
||||||
|
"at" : f : s -> aTerm (CApplyTransfer (pmIdent f)) s
|
||||||
"ma" : s -> aString CMorphoAnalyse s
|
"ma" : s -> aString CMorphoAnalyse s
|
||||||
"tt" : s -> aString CTestTokenizer s
|
"tt" : s -> aString CTestTokenizer s
|
||||||
"cc" : s -> aUnit $ CComputeConcrete $ unwords s
|
"cc" : s -> aUnit $ CComputeConcrete $ unwords s
|
||||||
@@ -175,4 +176,7 @@ pCommand ws = case ws of
|
|||||||
|
|
||||||
aTermLi c ss = (c [], [ASTrm $ unwords ss])
|
aTermLi c ss = (c [], [ASTrm $ unwords ss])
|
||||||
---- (c forms, [ASTrms [term]]) where
|
---- (c forms, [ASTrms [term]]) where
|
||||||
---- (forms,term) = ([], s2t (unwords ss)) ---- string2formsAndTerm (unwords ss)
|
---- (forms,term) = ([], s2t (unwords ss)) ----string2formsAndTerm(unwords ss)
|
||||||
|
pmIdent m = case span (/='.') m of
|
||||||
|
(k,_:f) -> (Just (pzIdent k), pzIdent f)
|
||||||
|
_ -> (Nothing,pzIdent m)
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ data Command =
|
|||||||
| CGenerateTrees
|
| CGenerateTrees
|
||||||
| CPutTerm
|
| CPutTerm
|
||||||
| CWrapTerm I.Ident
|
| CWrapTerm I.Ident
|
||||||
|
| CApplyTransfer (Maybe I.Ident, I.Ident)
|
||||||
| CMorphoAnalyse
|
| CMorphoAnalyse
|
||||||
| CTestTokenizer
|
| CTestTokenizer
|
||||||
| CComputeConcrete String
|
| CComputeConcrete String
|
||||||
|
|||||||
Reference in New Issue
Block a user