diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/compiler/GF.hs | 61 | ||||
| -rw-r--r-- | src/compiler/GF/Infra/UseIO.hs | 2 | ||||
| -rw-r--r-- | src/compiler/GF/Main.hs | 48 | ||||
| -rw-r--r-- | src/programs/gf.hs | 3 |
4 files changed, 82 insertions, 32 deletions
diff --git a/src/compiler/GF.hs b/src/compiler/GF.hs index cb63cadbe..bdb3e9b48 100644 --- a/src/compiler/GF.hs +++ b/src/compiler/GF.hs @@ -1,37 +1,36 @@ -module Main where +module GF( + -- * Command line interface + module GF.Main, + module GF.Compiler, + module GF.Interactive, + -- * Compiling GF grammars + module GF.Compile, + module GF.CompileInParallel, + module GF.CompileOne, + + -- * Abstract syntax, parsing and pretty printing + module GF.Compile.GetGrammar, + module GF.Grammar, + + -- * Supporting infrastructure and system utilities + module GF.Data.Operations, + module GF.Infra.UseIO, + module GF.Infra.Option, + module GF.System.Console + ) where +import GF.Main import GF.Compiler import GF.Interactive -import GF.Data.ErrM -import GF.Infra.Option -import GF.Infra.UseIO -import GF.Infra.BuildInfo (buildInfo) -import Paths_gf -import Data.Version -import System.Directory -import System.Environment (getArgs) -import System.Exit -import GF.System.Console (setConsoleEncoding) +import GF.Compile +import GF.CompileInParallel +import GF.CompileOne -main :: IO () -main = do - setConsoleEncoding - args <- getArgs - case parseOptions args of - Ok (opts,files) -> do curr_dir <- getCurrentDirectory - lib_dir <- getLibraryDirectory opts - mainOpts (fixRelativeLibPaths curr_dir lib_dir opts) files - Bad err -> do ePutStrLn err - ePutStrLn "You may want to try --help." - exitFailure +import GF.Compile.GetGrammar +import GF.Grammar -mainOpts :: Options -> [FilePath] -> IO () -mainOpts opts files = - case flag optMode opts of - ModeVersion -> putStrLn $ "Grammatical Framework (GF) version " ++ showVersion version ++ "\n" ++ buildInfo - ModeHelp -> putStrLn helpMessage - ModeInteractive -> mainGFI opts files - ModeRun -> mainRunGFI opts files - ModeServer port -> mainServerGFI opts port files - ModeCompiler -> mainGFC opts files +import GF.Data.Operations +import GF.Infra.Option +import GF.Infra.UseIO +import GF.System.Console diff --git a/src/compiler/GF/Infra/UseIO.hs b/src/compiler/GF/Infra/UseIO.hs index e0477c1fc..58010f7f9 100644 --- a/src/compiler/GF/Infra/UseIO.hs +++ b/src/compiler/GF/Infra/UseIO.hs @@ -12,7 +12,7 @@ -- (Description of the module) ----------------------------------------------------------------------------- -module GF.Infra.UseIO(module GF.Infra.UseIO,liftErr, +module GF.Infra.UseIO(module GF.Infra.UseIO, -- ** Reused MonadIO(..),liftErr) where diff --git a/src/compiler/GF/Main.hs b/src/compiler/GF/Main.hs new file mode 100644 index 000000000..c7656248f --- /dev/null +++ b/src/compiler/GF/Main.hs @@ -0,0 +1,48 @@ +-- | GF main program (grammar compiler, interactive shell, http server) +module GF.Main where +import GF.Compiler +import GF.Interactive +import GF.Data.ErrM +import GF.Infra.Option +import GF.Infra.UseIO +import GF.Infra.BuildInfo (buildInfo) +import Paths_gf + +import Data.Version +import System.Directory +import System.Environment (getArgs) +import System.Exit +import GF.System.Console (setConsoleEncoding) + +-- | Run the GF main program, taking arguments from the command line. +-- (It calls 'setConsoleEncoding' and 'getOptions', then 'mainOpts'.) +-- Run @gf --help@ for usage info. +main :: IO () +main = do + setConsoleEncoding + uncurry mainOpts =<< getOptions + +-- | Get and parse GF command line arguments. Fix relative paths. +getOptions = do + args <- getArgs + case parseOptions args of + Ok (opts,files) -> do curr_dir <- getCurrentDirectory + lib_dir <- getLibraryDirectory opts + return (fixRelativeLibPaths curr_dir lib_dir opts, files) + Bad err -> do ePutStrLn err + ePutStrLn "You may want to try --help." + exitFailure + + +-- | Run the GF main program with the given options and files. Depending on +-- the options it invokes 'mainGFC', 'mainGFI', 'mainRunGFI', 'mainServerGFI', +-- or it just prints version/usage info. +mainOpts :: Options -> [FilePath] -> IO () +mainOpts opts files = + case flag optMode opts of + ModeVersion -> putStrLn $ "Grammatical Framework (GF) version " ++ showVersion version ++ "\n" ++ buildInfo + ModeHelp -> putStrLn helpMessage + ModeInteractive -> mainGFI opts files + ModeRun -> mainRunGFI opts files + ModeServer port -> mainServerGFI opts port files + ModeCompiler -> mainGFC opts files diff --git a/src/programs/gf.hs b/src/programs/gf.hs new file mode 100644 index 000000000..1dae54bc7 --- /dev/null +++ b/src/programs/gf.hs @@ -0,0 +1,3 @@ +import qualified GF + +main = GF.main |
