From f6065472094f28c720ae8fb6e5f99631c11ffe5f Mon Sep 17 00:00:00 2001 From: krangelov Date: Fri, 24 Dec 2021 12:35:12 +0100 Subject: [PATCH] the import command can now create blank grammars --- src/compiler/GF/Command/Importing.hs | 10 ++++++++++ src/compiler/GF/Infra/Option.hs | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/compiler/GF/Command/Importing.hs b/src/compiler/GF/Command/Importing.hs index fd3c0d676..dd37eb534 100644 --- a/src/compiler/GF/Command/Importing.hs +++ b/src/compiler/GF/Command/Importing.hs @@ -22,6 +22,16 @@ import Control.Monad(foldM) -- import a grammar in an environment where it extends an existing grammar importGrammar :: Maybe PGF -> Options -> [FilePath] -> IO (Maybe PGF) +importGrammar pgf0 opts _ + | Just name <- flag optBlank opts = do + mb_ngf_file <- if snd (flag optLinkTargets opts) + then do let fname = name <.> ".ngf" + putStr ("(Boot image "++fname++") ") + return (Just fname) + else do return Nothing + pgf <- newNGF name mb_ngf_file + putStrLn (abstractName pgf) + return (Just pgf) importGrammar pgf0 _ [] = return pgf0 importGrammar pgf0 opts fs | all (extensionIs ".cf") fs = fmap Just $ importCF opts fs getBNFCRules bnfc2cf diff --git a/src/compiler/GF/Infra/Option.hs b/src/compiler/GF/Infra/Option.hs index 8cf41f943..c44c69a70 100644 --- a/src/compiler/GF/Infra/Option.hs +++ b/src/compiler/GF/Infra/Option.hs @@ -153,6 +153,7 @@ data Flags = Flags { optShowCPUTime :: Bool, optOutputFormats :: [OutputFormat], optLinkTargets :: (Bool,Bool), -- pgf,ngf files + optBlank :: Maybe String, optSISR :: Maybe SISRFormat, optHaskellOptions :: Set HaskellOption, optLexicalCats :: Set String, @@ -262,6 +263,7 @@ defaultFlags = Flags { optShowCPUTime = False, optOutputFormats = [], optLinkTargets = (True,False), + optBlank = Nothing, optSISR = Nothing, optHaskellOptions = Set.empty, optLiteralCats = Set.fromList [cString,cInt,cFloat,cVar], @@ -320,6 +322,7 @@ optDescr = Option [] ["make"] (NoArg (liftM2 addOptions (mode ModeCompiler) (phase Link))) "Build .pgf file and other output files and exit.", Option [] ["boot"] (NoArg (set $ \o -> o {optLinkTargets = (True,True)})) "Boot an .ngf database for fast grammar reloading", Option [] ["boot-only"] (NoArg (set $ \o -> o {optLinkTargets = (False,True)})) "Boot the .ngf database and don't write a .pgf file", + Option [] ["blank"] (ReqArg (\x -> set $ \o -> o { optBlank = Just x }) "ABSTR_NAME") "Create a blank database with an empty abstract syntax.", Option [] ["cpu"] (NoArg (cpu True)) "Show compilation CPU time statistics.", Option [] ["no-cpu"] (NoArg (cpu False)) "Don't show compilation CPU time statistics (default).", Option [] ["gfo-dir"] (ReqArg gfoDir "DIR") "Directory to put .gfo files in (default = '.').",