summaryrefslogtreecommitdiff
path: root/src-3.0/GF/Command/Interpreter.hs
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@chalmers.se>2008-06-05 07:33:42 +0000
committerkr.angelov <kr.angelov@chalmers.se>2008-06-05 07:33:42 +0000
commit4803fb8052caba0421949c9d7768d44ec28d109d (patch)
tree669ab3dcc40cca9a91cd9220c366677ce1db8bdb /src-3.0/GF/Command/Interpreter.hs
parent0b1a157222e0f96b9c9d6f8cea98caf547c4bdf9 (diff)
use parser combinators to parse the shell commands. simplified CommandLine type
Diffstat (limited to 'src-3.0/GF/Command/Interpreter.hs')
-rw-r--r--src-3.0/GF/Command/Interpreter.hs30
1 files changed, 15 insertions, 15 deletions
diff --git a/src-3.0/GF/Command/Interpreter.hs b/src-3.0/GF/Command/Interpreter.hs
index fa0de5ec8..f39960ae9 100644
--- a/src-3.0/GF/Command/Interpreter.hs
+++ b/src-3.0/GF/Command/Interpreter.hs
@@ -5,9 +5,8 @@ module GF.Command.Interpreter (
) where
import GF.Command.Commands
-import GF.Command.AbsGFShell
-import GF.Command.PPrTree
-import GF.Command.ParGFShell
+import GF.Command.Abstract
+import GF.Command.Parse
import PGF
import PGF.Data
import PGF.Macros
@@ -26,15 +25,16 @@ mkCommandEnv :: PGF -> CommandEnv
mkCommandEnv pgf = CommandEnv pgf (allCommands pgf)
interpretCommandLine :: CommandEnv -> String -> IO ()
-interpretCommandLine env line = case (pCommandLine (myLexer line)) of
- Ok CEmpty -> return ()
- Ok (CLine pipes) -> do res <- runInterruptibly (mapM_ interPipe pipes)
- case res of
- Left ex -> print ex
- Right x -> return x
- _ -> putStrLn "command not parsed"
+interpretCommandLine env line =
+ case readCommandLine line of
+ Just [] -> return ()
+ Just pipes -> do res <- runInterruptibly (mapM_ interPipe pipes)
+ case res of
+ Left ex -> print ex
+ Right x -> return x
+ Nothing -> putStrLn "command not parsed"
where
- interPipe (PComm cs) = do
+ interPipe cs = do
(_,s) <- intercs ([],"") cs
putStrLn s
intercs treess [] = return treess
@@ -60,8 +60,8 @@ interpret env trees0 comm = case lookCommand co comms of
comms = commands env
checkOpts info =
case
- [o | OOpt (Ident o) <- opts, notElem o (options info)] ++
- [o | OFlag (Ident o) _ <- opts, notElem o (flags info)]
+ [o | OOpt o <- opts, notElem o (options info)] ++
+ [o | OFlag o _ <- opts, notElem o (flags info)]
of
[] -> return ()
[o] -> putStrLn $ "option not interpreted: " ++ o
@@ -70,8 +70,8 @@ interpret env trees0 comm = case lookCommand co comms of
-- analyse command parse tree to a uniform datastructure, normalizing comm name
getCommand :: Command -> [Exp] -> (String,[Option],[Exp])
getCommand co ts = case co of
- Comm (Ident c) opts (ATree t) -> (getOp c,opts,[tree2exp t]) -- ignore piped
- CNoarg (Ident c) opts -> (getOp c,opts,ts) -- use piped
+ Command c opts (AExp t) -> (getOp c,opts,[t]) -- ignore piped
+ Command c opts ANoArg -> (getOp c,opts,ts) -- use piped
where
-- abbreviation convention from gf
getOp s = case break (=='_') s of