From a77519ba1045d23a7bb8ea1c56cc90518e9fedb9 Mon Sep 17 00:00:00 2001 From: aarne Date: Wed, 16 Jun 2004 14:49:50 +0000 Subject: [PATCH] bug fixes ; command so ; reintroduce batch mode --- src/GF.hs | 79 ++++----- src/GF/API/IOGrammar.hs | 5 + src/GF/Compile/ShellState.hs | 10 +- src/GF/GFModes.hs | 77 +++++++++ src/GF/Grammar/Lookup.hs | 296 +--------------------------------- src/GF/Grammar/PrGrammar.hs | 3 + src/GF/Infra/Modules.hs | 3 + src/GF/Infra/Option.hs | 3 + src/GF/Shell.hs | 11 ++ src/GF/Shell/PShell.hs | 8 + src/GF/Shell/ShellCommands.hs | 3 + src/HelpFile | 11 ++ src/HelpFile.hs | 11 ++ 13 files changed, 187 insertions(+), 333 deletions(-) create mode 100644 src/GF/GFModes.hs diff --git a/src/GF.hs b/src/GF.hs index b29a3c797..5eafefe8d 100644 --- a/src/GF.hs +++ b/src/GF.hs @@ -1,5 +1,6 @@ module Main where +import GFModes import Operations import UseIO import Option @@ -23,47 +24,49 @@ main :: IO () main = do xs <- getArgs let (os,fs) = getOptions "-" xs - java = oElem forJava os - isNew = oElem newParser os ---- temporary hack to have two parallel GUIs - putStrLnFlush $ if java then encodeUTF8 welcomeMsg else welcomeMsg - st <- case fs of - _ -> useIOE emptyShellState $ foldM (shellStateFromFiles os) emptyShellState fs - --- _ -> return emptyShellState - if null fs then return () else putCPU - if java then sessionLineJ isNew st else do - gfInteract (initHState st) - return () + opt j = oElem j os + case 0 of -gfInteract :: HState -> IO HState -gfInteract st@(env,_) = do - -- putStrFlush "> " M.F 25/01-02 prompt moved to Arch. - (s,cs) <- getCommandLines - case ifImpure cs of + _ | opt getHelp -> do + putStrLnFlush $ encodeUTF8 helpMsg - -- these are the three impure commands - Just (ICQuit,_) -> do - putStrLn "See you." - return st - Just (ICExecuteHistory file,_) -> do - ss <- readFileIf file - let co = pCommandLines ss - st' <- execLinesH s co st - gfInteract st' - Just (ICEarlierCommand i,_) -> do - let line = earlierCommandH st i - co = pCommandLine $ words line - st' <- execLinesH line [co] st -- s would not work in execLinesH - gfInteract st' - Just (ICEditSession,os) -> - editSession (addOptions os opts) env >> gfInteract st - Just (ICTranslateSession,os) -> - translateSession (addOptions os opts) env >> gfInteract st - -- this is a normal command sequence + _ | opt forJava -> do + putStrLnFlush $ encodeUTF8 welcomeMsg + st <- useIOE emptyShellState $ + foldM (shellStateFromFiles os) emptyShellState fs + sessionLineJ True st + return () + + _ | opt doMake -> do + case fs of + [f] -> batchCompile os f + _ -> putStrLnFlush "expecting exactly one gf file to compile" + + _ | opt doBatch -> do + if opt beSilent then return () else putStrLnFlush "" + st <- useIOE emptyShellState $ + foldM (shellStateFromFiles os) emptyShellState fs + gfBatch (initHState st) + if opt beSilent then return () else putStrLnFlush "" + return () _ -> do - st' <- execLinesH s cs st - gfInteract st' - where - opts = globalOptions env + putStrLnFlush $ welcomeMsg + st <- useIOE emptyShellState $ + foldM (shellStateFromFiles os) emptyShellState fs + if null fs then return () else putCPU + gfInteract (initHState st) + return () + +helpMsg = unlines [ + "Usage: gf