From d8cabf026390f0f69a4e9b3a503f0ea5538ff362 Mon Sep 17 00:00:00 2001 From: "kr.angelov" Date: Thu, 22 May 2008 14:39:16 +0000 Subject: move GFC and GFI --- src-3.0/GF.hs | 13 ++++---- src-3.0/GF/Devel/GFC.hs | 67 ---------------------------------------- src-3.0/GF/Devel/GFI.hs | 82 ------------------------------------------------- src-3.0/GFC.hs | 67 ++++++++++++++++++++++++++++++++++++++++ src-3.0/GFI.hs | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 155 insertions(+), 156 deletions(-) delete mode 100644 src-3.0/GF/Devel/GFC.hs delete mode 100644 src-3.0/GF/Devel/GFI.hs create mode 100644 src-3.0/GFC.hs create mode 100644 src-3.0/GFI.hs diff --git a/src-3.0/GF.hs b/src-3.0/GF.hs index 70fddcd67..038d034d6 100644 --- a/src-3.0/GF.hs +++ b/src-3.0/GF.hs @@ -1,14 +1,13 @@ module Main where -import GF.Devel.GFC -import GF.Devel.GFI +import GFC +import GFI -import System (getArgs) +import System.Environment (getArgs) main :: IO () main = do - xx <- getArgs - case xx of + args <- getArgs + case args of "--batch":args -> mainGFC args - _ -> mainGFI xx - + _ -> mainGFI args diff --git a/src-3.0/GF/Devel/GFC.hs b/src-3.0/GF/Devel/GFC.hs deleted file mode 100644 index 562570f14..000000000 --- a/src-3.0/GF/Devel/GFC.hs +++ /dev/null @@ -1,67 +0,0 @@ -module GF.Devel.GFC (mainGFC) where --- module Main where - -import GF.Compile -import GF.Devel.PrintGFCC -import GF.GFCC.CId -import GF.GFCC.DataGFCC -import GF.GFCC.Raw.ParGFCCRaw -import GF.GFCC.Raw.ConvertGFCC -import GF.Devel.UseIO -import GF.Infra.Option -import GF.GFCC.API -import GF.Data.ErrM - -import System.FilePath - -mainGFC :: [String] -> IO () -mainGFC xx = do - let (opts,fs) = getOptions "-" xx - case opts of - _ | oElem (iOpt "help") opts -> putStrLn usageMsg - _ | oElem (iOpt "-make") opts -> do - gfcc <- appIOE (compileToGFCC opts fs) >>= err fail return - let gfccFile = targetNameGFCC opts (absname gfcc) - outputFile gfccFile (printGFCC gfcc) - mapM_ (alsoPrint opts gfcc) printOptions - - -- gfc -o target.gfcc source_1.gfcc ... source_n.gfcc - _ | all ((==".gfcc") . takeExtensions) fs -> do - gfccs <- mapM file2gfcc fs - let gfcc = foldl1 unionGFCC gfccs - let gfccFile = targetNameGFCC opts (absname gfcc) - outputFile gfccFile (printGFCC gfcc) - mapM_ (alsoPrint opts gfcc) printOptions - - _ -> do - appIOE (mapM_ (batchCompile opts) (map return fs)) >>= err fail return - putStrLn "Done." - -targetName :: Options -> CId -> String -targetName opts abs = case getOptVal opts (aOpt "target") of - Just n -> n - _ -> prCId abs - -targetNameGFCC :: Options -> CId -> FilePath -targetNameGFCC opts abs = targetName opts abs ++ ".gfcc" - ----- TODO: nicer and richer print options - -alsoPrint opts gr (opt,name) = do - if oElem (iOpt opt) opts - then outputFile name (prGFCC opt gr) - else return () - -outputFile :: FilePath -> String -> IO () -outputFile outfile output = - do writeFile outfile output - putStrLn $ "wrote file " ++ outfile - -printOptions = [ - ("haskell","GSyntax.hs"), - ("haskell_gadt","GSyntax.hs"), - ("js","grammar.js") - ] - -usageMsg = - "usage: gfc (-h | --make (-noopt) (-noparse) (-target=PREFIX) (-js | -haskell | -haskell_gadt)) (-src) FILES" diff --git a/src-3.0/GF/Devel/GFI.hs b/src-3.0/GF/Devel/GFI.hs deleted file mode 100644 index f78e576cf..000000000 --- a/src-3.0/GF/Devel/GFI.hs +++ /dev/null @@ -1,82 +0,0 @@ -module GF.Devel.GFI (mainGFI) where - -import GF.Command.Interpreter -import GF.Command.Importing -import GF.Command.Commands -import GF.GFCC.API - -import GF.Devel.UseIO -import GF.System.Readline (fetchCommand) -import GF.Infra.Option ---- Haskell's option lib - -import System.CPUTime - - -mainGFI :: [String] -> IO () -mainGFI xx = do - putStrLn welcome - env <- importInEnv emptyMultiGrammar xx - loop (GFEnv env [] 0) - return () - -loop :: GFEnv -> IO GFEnv -loop gfenv0 = do - let env = commandenv gfenv0 - s <- fetchCommand (prompt env) - let gfenv = gfenv0 {history = s : history gfenv0} - case words s of - - -- special commands, working on GFEnv - "i":args -> 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 - - -- ordinary commands, working on CommandEnv - _ -> do - interpretCommandLine env s - loopNewCPU gfenv - -loopNewCPU gfenv = do - cpu' <- getCPUTime - putStrLn (show ((cpu' - cputime gfenv) `div` 1000000000) ++ " msec") - loop $ gfenv {cputime = cpu'} - -importInEnv mgr0 xx = do - let (opts,files) = getOptions "-" xx - mgr1 <- case files of - [] -> return mgr0 - _ -> importGrammar mgr0 opts files - let env = CommandEnv mgr1 (allCommands mgr1) - putStrLn $ unwords $ "\nLanguages:" : languages mgr1 - return env - -welcome = unlines [ - " ", - " * * * ", - " * * ", - " * * ", - " * ", - " * ", - " * * * * * * * ", - " * * * ", - " * * * * * * ", - " * * * ", - " * * * ", - " ", - "This is GF version 3.0 alpha. ", - "Some things may work. " - ] - -prompt env = absname ++ "> " where - absname = case abstractName (multigrammar env) of - "_" -> "" --- created by new Ident handling 22/5/2008 - n -> n - -data GFEnv = GFEnv { - commandenv :: CommandEnv, - history :: [String], - cputime :: Integer - } diff --git a/src-3.0/GFC.hs b/src-3.0/GFC.hs new file mode 100644 index 000000000..9273117b7 --- /dev/null +++ b/src-3.0/GFC.hs @@ -0,0 +1,67 @@ +module GFC (mainGFC) where +-- module Main where + +import GF.Compile +import GF.Devel.PrintGFCC +import GF.GFCC.CId +import GF.GFCC.DataGFCC +import GF.GFCC.Raw.ParGFCCRaw +import GF.GFCC.Raw.ConvertGFCC +import GF.Devel.UseIO +import GF.Infra.Option +import GF.GFCC.API +import GF.Data.ErrM + +import System.FilePath + +mainGFC :: [String] -> IO () +mainGFC xx = do + let (opts,fs) = getOptions "-" xx + case opts of + _ | oElem (iOpt "help") opts -> putStrLn usageMsg + _ | oElem (iOpt "-make") opts -> do + gfcc <- appIOE (compileToGFCC opts fs) >>= err fail return + let gfccFile = targetNameGFCC opts (absname gfcc) + outputFile gfccFile (printGFCC gfcc) + mapM_ (alsoPrint opts gfcc) printOptions + + -- gfc -o target.gfcc source_1.gfcc ... source_n.gfcc + _ | all ((==".gfcc") . takeExtensions) fs -> do + gfccs <- mapM file2gfcc fs + let gfcc = foldl1 unionGFCC gfccs + let gfccFile = targetNameGFCC opts (absname gfcc) + outputFile gfccFile (printGFCC gfcc) + mapM_ (alsoPrint opts gfcc) printOptions + + _ -> do + appIOE (mapM_ (batchCompile opts) (map return fs)) >>= err fail return + putStrLn "Done." + +targetName :: Options -> CId -> String +targetName opts abs = case getOptVal opts (aOpt "target") of + Just n -> n + _ -> prCId abs + +targetNameGFCC :: Options -> CId -> FilePath +targetNameGFCC opts abs = targetName opts abs ++ ".gfcc" + +---- TODO: nicer and richer print options + +alsoPrint opts gr (opt,name) = do + if oElem (iOpt opt) opts + then outputFile name (prGFCC opt gr) + else return () + +outputFile :: FilePath -> String -> IO () +outputFile outfile output = + do writeFile outfile output + putStrLn $ "wrote file " ++ outfile + +printOptions = [ + ("haskell","GSyntax.hs"), + ("haskell_gadt","GSyntax.hs"), + ("js","grammar.js") + ] + +usageMsg = + "usage: gfc (-h | --make (-noopt) (-noparse) (-target=PREFIX) (-js | -haskell | -haskell_gadt)) (-src) FILES" diff --git a/src-3.0/GFI.hs b/src-3.0/GFI.hs new file mode 100644 index 000000000..0efbd420e --- /dev/null +++ b/src-3.0/GFI.hs @@ -0,0 +1,82 @@ +module GFI (mainGFI) where + +import GF.Command.Interpreter +import GF.Command.Importing +import GF.Command.Commands +import GF.GFCC.API + +import GF.Devel.UseIO +import GF.System.Readline (fetchCommand) +import GF.Infra.Option ---- Haskell's option lib + +import System.CPUTime + + +mainGFI :: [String] -> IO () +mainGFI xx = do + putStrLn welcome + env <- importInEnv emptyMultiGrammar xx + loop (GFEnv env [] 0) + return () + +loop :: GFEnv -> IO GFEnv +loop gfenv0 = do + let env = commandenv gfenv0 + s <- fetchCommand (prompt env) + let gfenv = gfenv0 {history = s : history gfenv0} + case words s of + + -- special commands, working on GFEnv + "i":args -> 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 + + -- ordinary commands, working on CommandEnv + _ -> do + interpretCommandLine env s + loopNewCPU gfenv + +loopNewCPU gfenv = do + cpu' <- getCPUTime + putStrLn (show ((cpu' - cputime gfenv) `div` 1000000000) ++ " msec") + loop $ gfenv {cputime = cpu'} + +importInEnv mgr0 xx = do + let (opts,files) = getOptions "-" xx + mgr1 <- case files of + [] -> return mgr0 + _ -> importGrammar mgr0 opts files + let env = CommandEnv mgr1 (allCommands mgr1) + putStrLn $ unwords $ "\nLanguages:" : languages mgr1 + return env + +welcome = unlines [ + " ", + " * * * ", + " * * ", + " * * ", + " * ", + " * ", + " * * * * * * * ", + " * * * ", + " * * * * * * ", + " * * * ", + " * * * ", + " ", + "This is GF version 3.0 alpha. ", + "Some things may work. " + ] + +prompt env = absname ++ "> " where + absname = case abstractName (multigrammar env) of + "_" -> "" --- created by new Ident handling 22/5/2008 + n -> n + +data GFEnv = GFEnv { + commandenv :: CommandEnv, + history :: [String], + cputime :: Integer + } -- cgit v1.2.3