diff options
| author | bjorn <bjorn@bringert.net> | 2008-05-28 15:10:36 +0000 |
|---|---|---|
| committer | bjorn <bjorn@bringert.net> | 2008-05-28 15:10:36 +0000 |
| commit | 3fd1f5652a3af22e90a040a821d244a91a3553a0 (patch) | |
| tree | 15225df670e1fb1c55f4a9eb1ca45eae7952061f /src-3.0/GFI.hs | |
| parent | 1bc74749aa7a9ec6ecfced68c0cdf38f43c7f9ef (diff) | |
Switch to new options handling.
This changes lots of stuff, let me know if it broke anything.
Comments:
- We use a local hacked version of GetOpt that allows long forms of commands to start with a single dash. This breaks other parts of GetOpt. For example, arguments to short options now require a =, and does not allo pace after the option character.
- The new command parsing is currently only used for the program command line, pragmas and the arguments for the 'i' shell command.
- I made a quick hack for the options for showTerm, which currently makes it impossible to use the print style flags for cc. This will be replaced by a facility for parsing command-specific options.
- The verbosity handling is broken in some places. I will fix that in a later patch.
Diffstat (limited to 'src-3.0/GFI.hs')
| -rw-r--r-- | src-3.0/GFI.hs | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src-3.0/GFI.hs b/src-3.0/GFI.hs index 5769d0550..97af0b3a4 100644 --- a/src-3.0/GFI.hs +++ b/src-3.0/GFI.hs @@ -3,12 +3,12 @@ module GFI (mainGFI) where import GF.Command.Interpreter import GF.Command.Importing import GF.Command.Commands +import GF.Data.ErrM import GF.GFCC.API - import GF.Grammar.API -- for cc command import GF.Infra.UseIO -import GF.Infra.Option ---- Haskell's option lib +import GF.Infra.Option import GF.System.Readline (fetchCommand) import System.CPUTime @@ -17,10 +17,10 @@ import Data.Version import Paths_gf -mainGFI :: [String] -> IO () -mainGFI xx = do +mainGFI :: Options -> [FilePath] -> IO () +mainGFI opts files = do putStrLn welcome - env <- importInEnv emptyMultiGrammar xx + env <- importInEnv emptyMultiGrammar opts files loop (GFEnv emptyGrammar env [] 0) return () @@ -31,25 +31,26 @@ loop gfenv0 = do s <- fetchCommand (prompt env) let gfenv = gfenv0 {history = s : history gfenv0} case words s of - -- special commands, requiring source grammar in env "cc":ws -> do - let (opts,term) = getOptions "-" ws + -- FIXME: add options parsing for cc arguments + let (opts,term) = (TermPrintDefault, ws) let t = pTerm (unwords term) >>= checkTerm sgr >>= computeTerm sgr err putStrLn (putStrLn . showTerm opts) t ---- make pipable loopNewCPU gfenv - "i":args -> do - let (opts,files) = getOptions "-" args - case opts of - _ | oElem (iOpt "retain") opts -> do - src <- importSource sgr opts files - loopNewCPU $ gfenv {sourcegrammar = src} + case parseOptions args of + Ok (opts,files) + | flag optRetainResource opts -> + do src <- importSource sgr opts files + loopNewCPU $ gfenv {sourcegrammar = src} + | otherwise -> + do env1 <- importInEnv (multigrammar env) opts files + loopNewCPU $ gfenv {commandenv = env1} + Bad err -> do putStrLn $ "Command parse error: " ++ err + loopNewCPU gfenv -- other special commands, working on GFEnv - _ -> 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 @@ -64,8 +65,8 @@ loopNewCPU gfenv = do putStrLn (show ((cpu' - cputime gfenv) `div` 1000000000) ++ " msec") loop $ gfenv {cputime = cpu'} -importInEnv mgr0 xx = do - let (opts,files) = getOptions "-" xx +importInEnv :: MultiGrammar -> Options -> [FilePath] -> IO CommandEnv +importInEnv mgr0 opts files = do mgr1 <- case files of [] -> return mgr0 _ -> importGrammar mgr0 opts files |
