summaryrefslogtreecommitdiff
path: root/src/GF/Command/Interpreter.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2007-11-06 11:01:45 +0000
committeraarne <aarne@cs.chalmers.se>2007-11-06 11:01:45 +0000
commit693621ffbe9146f24ba75e073b6ce2e716c56a5e (patch)
tree43f880829a17c7834fcdb179f5c468fa6c53fc05 /src/GF/Command/Interpreter.hs
parentdb399191d926209d36c8496ba65d53dcaeb7855b (diff)
made command table independent of options
Diffstat (limited to 'src/GF/Command/Interpreter.hs')
-rw-r--r--src/GF/Command/Interpreter.hs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/GF/Command/Interpreter.hs b/src/GF/Command/Interpreter.hs
index fb2158d1d..fce0014db 100644
--- a/src/GF/Command/Interpreter.hs
+++ b/src/GF/Command/Interpreter.hs
@@ -1,4 +1,5 @@
module GF.Command.Interpreter (
+ CommandEnv (..),
interpretCommandLine
) where
@@ -14,8 +15,13 @@ import GF.Command.ErrM ----
import qualified Data.Map as Map
-interpretCommandLine :: MultiGrammar -> String -> IO ()
-interpretCommandLine gr line = case (pCommandLine (myLexer line)) of
+data CommandEnv = CommandEnv {
+ multigrammar :: MultiGrammar,
+ commands :: Map.Map String CommandInfo
+ }
+
+interpretCommandLine :: CommandEnv -> String -> IO ()
+interpretCommandLine env line = case (pCommandLine (myLexer line)) of
Ok CEmpty -> return ()
Ok (CLine pipes) -> mapM_ interPipe pipes
_ -> putStrLn "command not parsed"
@@ -27,14 +33,14 @@ interpretCommandLine gr line = case (pCommandLine (myLexer line)) of
intercs (trees,_) (c:cs) = do
treess2 <- interc trees c
intercs treess2 cs
- interc = interpret gr
+ interc = interpret env
-- return the trees to be sent in pipe, and the output possibly printed
-interpret :: MultiGrammar -> [Tree] -> Command -> IO CommandOutput
-interpret mgr trees0 comm = case lookCommand co commands of
+interpret :: CommandEnv -> [Tree] -> Command -> IO CommandOutput
+interpret env trees0 comm = case lookCommand co comms of
Just info -> do
checkOpts info
- tss@(_,s) <- exec info trees
+ tss@(_,s) <- exec info opts trees
optTrace s
return tss
_ -> do
@@ -43,7 +49,7 @@ interpret mgr trees0 comm = case lookCommand co commands of
where
optTrace = if isOpt "tr" opts then putStrLn else const (return ())
(co,opts,trees) = getCommand comm trees0
- commands = allCommands mgr opts
+ comms = commands env
checkOpts info =
case
[o | OOpt (Ident o) <- opts, notElem o (options info)] ++