summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Interactive.hs
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2015-08-10 13:01:02 +0000
committerhallgren <hallgren@chalmers.se>2015-08-10 13:01:02 +0000
commitd38efbaa6a2c94218bb65925bd9ad6c028dfbfd6 (patch)
tree6b6f5b8d34e9d5daa8d021d0d748d64cb993b188 /src/compiler/GF/Interactive.hs
parent20644d02990f7510812fcb47d33ad20a27be48ab (diff)
Refactor GF shell modules to improve modularity and reusability
+ Move type CommandInfo from GF.Command.Commands to a new module GF.Commands.CommandInfo and make it independent of the PGF type. + Make the module GF.Command.Interpreter independent of the PGF type and eliminate the import of GF.Command.Commands. + Move the implementation of the "help" command to its own module GF.Command.Help
Diffstat (limited to 'src/compiler/GF/Interactive.hs')
-rw-r--r--src/compiler/GF/Interactive.hs19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/compiler/GF/Interactive.hs b/src/compiler/GF/Interactive.hs
index 153e699f5..a404e0567 100644
--- a/src/compiler/GF/Interactive.hs
+++ b/src/compiler/GF/Interactive.hs
@@ -3,9 +3,9 @@
module GF.Interactive (mainGFI,mainRunGFI,mainServerGFI) where
import Prelude hiding (putStrLn,print)
import qualified Prelude as P(putStrLn)
-import GF.Command.Interpreter(CommandEnv(..),commands,mkCommandEnv,emptyCommandEnv,interpretCommandLine)
+import GF.Command.Interpreter(CommandEnv(..),pgfenv,commands,mkCommandEnv,interpretCommandLine)
--import GF.Command.Importing(importSource,importGrammar)
-import GF.Command.Commands(flags,options)
+import GF.Command.Commands(flags,options,PGFEnv,pgfEnv,allCommands)
import GF.Command.Abstract
import GF.Command.Parse(readCommandLine,pCommand)
import GF.Data.Operations (Err(..),chunks,err,raise,done)
@@ -29,7 +29,7 @@ import qualified System.Console.Haskeline as Haskeline
--import GF.Compile.Coding(codeTerm)
import PGF
-import PGF.Internal(emptyPGF,abstract,funs,lookStartCat)
+import PGF.Internal(abstract,funs,lookStartCat,emptyPGF)
import Data.Char
import Data.List(nub,isPrefixOf,isInfixOf,partition)
@@ -357,10 +357,10 @@ importInEnv gfenv opts files
do src <- importSource opts files
pgf <- lazySIO importPGF -- duplicates some work, better to link src
return $ gfenv {grammar = src, retain=True,
- commandenv = mkCommandEnv pgf}
+ commandenv = commandEnv pgf }
| otherwise =
do pgf1 <- importPGF
- return $ gfenv { commandenv = mkCommandEnv pgf1 }
+ return $ gfenv { commandenv = commandEnv pgf1 }
where
importPGF =
do let opts' = addOptions (setOptimization OptCSE False) opts
@@ -406,13 +406,16 @@ prompt env
data GFEnv = GFEnv {
grammar :: Grammar, -- gfo grammar -retain
retain :: Bool, -- grammar was imported with -retain flag
- commandenv :: CommandEnv,
+ commandenv :: CommandEnv PGFEnv,
history :: [String]
}
emptyGFEnv :: GFEnv
-emptyGFEnv =
- GFEnv emptyGrammar False (mkCommandEnv emptyPGF) [] {-0-}
+emptyGFEnv = GFEnv emptyGrammar False emptyCommandEnv [] {-0-}
+
+commandEnv pgf = mkCommandEnv (pgfEnv pgf) allCommands
+emptyCommandEnv = commandEnv emptyPGF
+multigrammar = fst . pgfenv
wordCompletion gfenv (left,right) = do
case wc_type (reverse left) of