mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user