mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-20 02:09:32 -06:00
Turn the GF compiler into a library. Main program is now in src/programs/gf.hs
The module src/compiler/GF.hs now serves as a prelimiary compiler API. It just exports a selection of functions and types from the compiler. Haddock documentation can be generated with cabal haddock --hyperlink-source Also bumbed the version number to 3.6.10.
This commit is contained in:
@@ -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.Compile
|
||||
import GF.CompileInParallel
|
||||
import GF.CompileOne
|
||||
|
||||
import GF.Compile.GetGrammar
|
||||
import GF.Grammar
|
||||
|
||||
import GF.Data.Operations
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
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.System.Console
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
48
src/compiler/GF/Main.hs
Normal file
48
src/compiler/GF/Main.hs
Normal file
@@ -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
|
||||
3
src/programs/gf.hs
Normal file
3
src/programs/gf.hs
Normal file
@@ -0,0 +1,3 @@
|
||||
import qualified GF
|
||||
|
||||
main = GF.main
|
||||
Reference in New Issue
Block a user