mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-19 16:12:52 -06:00
support for source gr and i -retain in GFI env
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
module GF.Command.Importing (importGrammar) where
|
module GF.Command.Importing (importGrammar, importSource) where
|
||||||
|
|
||||||
import GF.Compile
|
import GF.Compile
|
||||||
import GF.GFCC.DataGFCC
|
import GF.GFCC.DataGFCC
|
||||||
import GF.GFCC.API
|
import GF.GFCC.API
|
||||||
|
|
||||||
|
import GF.Grammar.Grammar (SourceGrammar) -- for cc command
|
||||||
|
|
||||||
import GF.Infra.UseIO
|
import GF.Infra.UseIO
|
||||||
import GF.Infra.Option
|
import GF.Infra.Option
|
||||||
import GF.Data.ErrM
|
import GF.Data.ErrM
|
||||||
@@ -26,3 +28,12 @@ importGrammar mgr0 opts files =
|
|||||||
gfcc2 <- mapM file2gfcc files >>= return . foldl1 unionGFCC
|
gfcc2 <- mapM file2gfcc files >>= return . foldl1 unionGFCC
|
||||||
let gfcc3 = unionGFCC (gfcc mgr0) gfcc2
|
let gfcc3 = unionGFCC (gfcc mgr0) gfcc2
|
||||||
return $ MultiGrammar gfcc3
|
return $ MultiGrammar gfcc3
|
||||||
|
|
||||||
|
importSource :: SourceGrammar -> Options -> [FilePath] -> IO SourceGrammar
|
||||||
|
importSource src0 opts files = do
|
||||||
|
src <- appIOE $ batchCompile opts files
|
||||||
|
case src of
|
||||||
|
Ok gr -> return gr
|
||||||
|
Bad msg -> do
|
||||||
|
putStrLn msg
|
||||||
|
return src0
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
module GF.Grammar.Grammar (SourceGrammar,
|
module GF.Grammar.Grammar (SourceGrammar,
|
||||||
|
emptySourceGrammar,
|
||||||
SourceModInfo,
|
SourceModInfo,
|
||||||
SourceModule,
|
SourceModule,
|
||||||
SourceAbs,
|
SourceAbs,
|
||||||
@@ -64,6 +65,8 @@ import qualified Data.ByteString.Char8 as BS
|
|||||||
-- | grammar as presented to the compiler
|
-- | grammar as presented to the compiler
|
||||||
type SourceGrammar = MGrammar Ident Info
|
type SourceGrammar = MGrammar Ident Info
|
||||||
|
|
||||||
|
emptySourceGrammar = MGrammar []
|
||||||
|
|
||||||
type SourceModInfo = ModInfo Ident Info
|
type SourceModInfo = ModInfo Ident Info
|
||||||
|
|
||||||
type SourceModule = (Ident, SourceModInfo)
|
type SourceModule = (Ident, SourceModInfo)
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import GF.Command.Importing
|
|||||||
import GF.Command.Commands
|
import GF.Command.Commands
|
||||||
import GF.GFCC.API
|
import GF.GFCC.API
|
||||||
|
|
||||||
|
import GF.Grammar.Grammar (SourceGrammar,emptySourceGrammar) -- for cc command
|
||||||
|
|
||||||
import GF.Infra.UseIO
|
import GF.Infra.UseIO
|
||||||
import GF.Infra.Option ---- Haskell's option lib
|
import GF.Infra.Option ---- Haskell's option lib
|
||||||
import GF.System.Readline (fetchCommand)
|
import GF.System.Readline (fetchCommand)
|
||||||
@@ -19,7 +21,7 @@ mainGFI :: [String] -> IO ()
|
|||||||
mainGFI xx = do
|
mainGFI xx = do
|
||||||
putStrLn welcome
|
putStrLn welcome
|
||||||
env <- importInEnv emptyMultiGrammar xx
|
env <- importInEnv emptyMultiGrammar xx
|
||||||
loop (GFEnv env [] 0)
|
loop (GFEnv emptySourceGrammar env [] 0)
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
loop :: GFEnv -> IO GFEnv
|
loop :: GFEnv -> IO GFEnv
|
||||||
@@ -29,10 +31,18 @@ loop gfenv0 = do
|
|||||||
let gfenv = gfenv0 {history = s : history gfenv0}
|
let gfenv = gfenv0 {history = s : history gfenv0}
|
||||||
case words s of
|
case words s of
|
||||||
|
|
||||||
-- special commands, working on GFEnv
|
-- special commands, requiring source grammar in env
|
||||||
"i":args -> do
|
"i":args -> do
|
||||||
env1 <- importInEnv (multigrammar env) args
|
let (opts,files) = getOptions "-" args
|
||||||
loopNewCPU $ gfenv {commandenv = env1}
|
case opts of
|
||||||
|
_ | oElem (iOpt "retain") opts -> do
|
||||||
|
src <- importSource (sourcegrammar gfenv) opts files
|
||||||
|
loopNewCPU $ gfenv {sourcegrammar = src}
|
||||||
|
|
||||||
|
-- other special commands, working on GFEnv
|
||||||
|
_ -> do
|
||||||
|
env1 <- importInEnv (multigrammar env) args
|
||||||
|
loopNewCPU $ gfenv {commandenv = env1}
|
||||||
"e":_ -> loopNewCPU $ gfenv {commandenv=env{multigrammar=emptyMultiGrammar}}
|
"e":_ -> loopNewCPU $ gfenv {commandenv=env{multigrammar=emptyMultiGrammar}}
|
||||||
"ph":_ -> mapM_ putStrLn (reverse (history gfenv0)) >> loopNewCPU gfenv
|
"ph":_ -> mapM_ putStrLn (reverse (history gfenv0)) >> loopNewCPU gfenv
|
||||||
"q":_ -> putStrLn "See you." >> return gfenv
|
"q":_ -> putStrLn "See you." >> return gfenv
|
||||||
@@ -79,6 +89,7 @@ prompt env = absname ++ "> " where
|
|||||||
n -> n
|
n -> n
|
||||||
|
|
||||||
data GFEnv = GFEnv {
|
data GFEnv = GFEnv {
|
||||||
|
sourcegrammar :: SourceGrammar, -- gfo grammar -retain
|
||||||
commandenv :: CommandEnv,
|
commandenv :: CommandEnv,
|
||||||
history :: [String],
|
history :: [String],
|
||||||
cputime :: Integer
|
cputime :: Integer
|
||||||
|
|||||||
Reference in New Issue
Block a user