diff options
| author | aarne <aarne@cs.chalmers.se> | 2008-05-21 09:26:44 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2008-05-21 09:26:44 +0000 |
| commit | 055c0d0d5a5bb0dc75904fe53df7f2e4f5732a8f (patch) | |
| tree | 0e63fb68c69c8f6ad0f78893c63420f0a3600e1c /src-3.0/GF/Devel/GFI.hs | |
| parent | 915a1de71783ab8446b1af9e72c7ba7dfbc12d3f (diff) | |
GF/src is now for 2.9, and the new sources are in src-3.0 - keep it this way until the release of GF 3
Diffstat (limited to 'src-3.0/GF/Devel/GFI.hs')
| -rw-r--r-- | src-3.0/GF/Devel/GFI.hs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src-3.0/GF/Devel/GFI.hs b/src-3.0/GF/Devel/GFI.hs new file mode 100644 index 000000000..f59bd15e6 --- /dev/null +++ b/src-3.0/GF/Devel/GFI.hs @@ -0,0 +1,77 @@ +module GF.Devel.GFI (mainGFI) where + +import GF.Command.Interpreter +import GF.Command.Importing +import GF.Command.Commands +import GF.GFCC.API + +import GF.Devel.UseIO +import GF.Devel.Arch +import GF.Infra.Option ---- Haskell's option lib + + +mainGFI :: [String] -> IO () +mainGFI xx = do + putStrLn welcome + env <- importInEnv emptyMultiGrammar xx + loop (GFEnv env [] 0) + return () + +loop :: GFEnv -> IO GFEnv +loop gfenv0 = do + let env = commandenv gfenv0 + putStrFlush (prompt env) + s <- getLine + let gfenv = gfenv0 {history = s : history gfenv0} + case words s of + + -- special commands, working on GFEnv + "i":args -> do + env1 <- importInEnv (multigrammar env) args + loopNewCPU $ gfenv {commandenv = env1} + "e":_ -> loopNewCPU $ gfenv {commandenv=env{multigrammar=emptyMultiGrammar}} + "ph":_ -> mapM_ putStrLn (reverse (history gfenv0)) >> loopNewCPU gfenv + "q":_ -> putStrLn "See you." >> return gfenv + + -- ordinary commands, working on CommandEnv + _ -> do + interpretCommandLine env s + loopNewCPU gfenv + +loopNewCPU gfenv = do + cpu <- prCPU $ cputime gfenv + loop $ gfenv {cputime = cpu} + +importInEnv mgr0 xx = do + let (opts,files) = getOptions "-" xx + mgr1 <- case files of + [] -> return mgr0 + _ -> importGrammar mgr0 opts files + let env = CommandEnv mgr1 (allCommands mgr1) + putStrLn $ unwords $ "\nLanguages:" : languages mgr1 + return env + +welcome = unlines [ + " ", + " * * * ", + " * * ", + " * * ", + " * ", + " * ", + " * * * * * * * ", + " * * * ", + " * * * * * * ", + " * * * ", + " * * * ", + " ", + "This is GF version 3.0 alpha. ", + "Some things may work. " + ] + +prompt env = abstractName (multigrammar env) ++ "> " + +data GFEnv = GFEnv { + commandenv :: CommandEnv, + history :: [String], + cputime :: Integer + } |
