add command "import -resource"

This commit is contained in:
krangelov
2021-12-24 14:46:07 +01:00
parent cb10e2fe32
commit 39853b3c04
4 changed files with 28 additions and 31 deletions

View File

@@ -4,7 +4,7 @@ module GF.Infra.Option
-- *** Option types
Options,
Flags(..),
Mode(..), Phase(..), Verbosity(..),
Mode(..), Phase(..), Verbosity(..), RetainMode(..),
OutputFormat(..),
SISRFormat(..), Optimization(..), CFGTransform(..), HaskellOption(..),
Dump(..), Pass(..), Recomp(..),
@@ -146,6 +146,9 @@ data Pass = Source | Rebuild | Extend | Rename | TypeCheck | Refresh | Optimize
data Recomp = AlwaysRecomp | RecompIfNewer | NeverRecomp
deriving (Show,Eq,Ord)
data RetainMode = RetainAll | RetainSource | RetainCompiled
deriving Show
data Flags = Flags {
optMode :: Mode,
optStopAfterPhase :: Phase,
@@ -164,7 +167,7 @@ data Flags = Flags {
optDocumentRoot :: Maybe FilePath, -- For --server mode
optRecomp :: Recomp,
optProbsFile :: Maybe FilePath,
optRetainResource :: Bool,
optRetainResource :: RetainMode,
optName :: Maybe String,
optPreprocessors :: [String],
optEncoding :: Maybe String,
@@ -185,7 +188,7 @@ data Flags = Flags {
optPlusAsBind :: Bool,
optJobs :: Maybe (Maybe Int)
}
deriving (Show)
deriving Show
newtype Options = Options (Flags -> Flags)
@@ -274,7 +277,7 @@ defaultFlags = Flags {
optDocumentRoot = Nothing,
optRecomp = RecompIfNewer,
optProbsFile = Nothing,
optRetainResource = False,
optRetainResource = RetainCompiled,
optName = Nothing,
optPreprocessors = [],
@@ -352,7 +355,8 @@ optDescr =
"(default) Recompile from source if the source is newer than the .gfo file.",
Option [] ["gfo","no-recomp"] (NoArg (recomp NeverRecomp))
"Never recompile from source, if there is already .gfo file.",
Option [] ["retain"] (NoArg (set $ \o -> o { optRetainResource = True })) "Retain opers.",
Option [] ["retain"] (NoArg (set $ \o -> o { optRetainResource = RetainAll })) "Retain the source and well as the compiled grammar.",
Option [] ["resource"] (NoArg (set $ \o -> o { optRetainResource = RetainSource })) "Load the source grammar as a resource only.",
Option [] ["probs"] (ReqArg probsFile "file.probs") "Read probabilities from file.",
Option ['n'] ["name"] (ReqArg name "NAME")
(unlines ["Use NAME as the name of the output. This is used in the output file names, ",

View File

@@ -11,8 +11,8 @@ module GF.Infra.SIO(
getCPUTime,getCurrentDirectory,getLibraryDirectory,
newStdGen,print,putStr,putStrLn,
-- ** Specific to GF
importGrammar,importSource,
putStrLnFlush,runInterruptibly,lazySIO,
importGrammar,importSource, link,
putStrLnFlush,runInterruptibly,
modifyPGF, checkoutPGF,
-- * Restricted accesss to arbitrary (potentially unsafe) IO operations
-- | If the environment variable GF_RESTRICTED is defined, these
@@ -30,7 +30,6 @@ import GF.System.Catch(try)
import System.Process(system)
import System.Environment(getEnv)
import Control.Concurrent.Chan(newChan,writeChan,getChanContents)
import GF.Infra.Concurrency(lazyIO)
import GF.Infra.UseIO(Output(..))
import GF.Data.Operations(ErrorMonad(..))
import qualified System.CPUTime as IO(getCPUTime)
@@ -39,6 +38,7 @@ import qualified System.Random as IO(newStdGen)
import qualified GF.Infra.UseIO as IO(getLibraryDirectory)
import qualified GF.System.Signal as IO(runInterruptibly)
import qualified GF.Command.Importing as GF(importGrammar, importSource)
import qualified GF.Compile as GF(link)
import qualified Control.Monad.Fail as Fail
import qualified PGF2.Transactions as PGFT
import Control.Exception
@@ -130,10 +130,10 @@ getCurrentDirectory = lift0 IO.getCurrentDirectory
getLibraryDirectory = lift0 . IO.getLibraryDirectory
newStdGen = lift0 IO.newStdGen
runInterruptibly = lift1 IO.runInterruptibly
lazySIO = lift1 lazyIO
importGrammar pgf opts files = lift0 $ GF.importGrammar pgf opts files
importSource opts files = lift0 $ GF.importSource opts files
link opts pgf src = lift0 $ GF.link opts pgf src
modifyPGF gr t = lift0 (PGFT.modifyPGF gr t)
checkoutPGF gr b = lift0 (PGFT.checkoutPGF gr b)