diff options
Diffstat (limited to 'src/GF/Shell')
| -rw-r--r-- | src/GF/Shell/CommandL.hs | 20 | ||||
| -rw-r--r-- | src/GF/Shell/Commands.hs | 7 | ||||
| -rw-r--r-- | src/GF/Shell/ShellCommands.hs | 2 |
3 files changed, 28 insertions, 1 deletions
diff --git a/src/GF/Shell/CommandL.hs b/src/GF/Shell/CommandL.hs index 2bb240018..93214781e 100644 --- a/src/GF/Shell/CommandL.hs +++ b/src/GF/Shell/CommandL.hs @@ -4,6 +4,7 @@ import Operations import UseIO import CMacros +import Values (Tree) import GetTree import ShellState @@ -13,6 +14,7 @@ import Commands import Char import List (intersperse) +import Monad (foldM) import UTF8 @@ -39,6 +41,23 @@ editLoop env state resume = do editLoop env' state' resume +-- execute a command script and return a tree + +execCommandHistory :: CEnv -> String -> IO (CEnv,Tree) +execCommandHistory env s = do + let env' = startEditEnv env + let state = initSStateEnv env' + (env',state') <- foldM exec (env,state) $ lines s + return $ (env',treeSState state') + + where + + exec (env,state) l = do + let c = pCommand l + execCommand env c state + + + getCommand :: IO Command getCommand = do s <- getLine @@ -101,6 +120,7 @@ pCommand = pCommandWords . words where "off":lang: _ -> CCEnvOff lang "pfile" :f:_ -> CCEnvRefineParse f "tfile" :f:_ -> CCEnvRefineWithTree f + "save":l:f:_ -> CCEnvSave l f -- openstring file -- pfile file diff --git a/src/GF/Shell/Commands.hs b/src/GF/Shell/Commands.hs index 4b0b3f82d..09f9b5f78 100644 --- a/src/GF/Shell/Commands.hs +++ b/src/GF/Shell/Commands.hs @@ -96,6 +96,7 @@ data Command = -- other commands using IO | CCEnvRefineWithTree String | CCEnvRefineParse String + | CCEnvSave String FilePath isQuit CQuit = True isQuit _ = False @@ -160,6 +161,12 @@ execCommand env c s = case c of CCEnvOn name -> return (languageOn (language name) env,s) CCEnvOff name -> return (languageOff (language name) env,s) + CCEnvSave lang file -> do + let str = optLinearizeTreeVal opts (stateGrammarOfLang env (language lang)) $ treeSState s + writeFile file str + let msg = ["wrote file" +++ file] + return (env,changeMsg msg s) + -- this command is improved by the use of IO CRefineRandom -> do g <- newStdGen diff --git a/src/GF/Shell/ShellCommands.hs b/src/GF/Shell/ShellCommands.hs index b4c28ca2e..78c023f50 100644 --- a/src/GF/Shell/ShellCommands.hs +++ b/src/GF/Shell/ShellCommands.hs @@ -167,7 +167,7 @@ optionsOfCommand co = case co of CHelp _ -> opts "all filter length lexer unlexer printer transform depth number" - CImpure ICEditSession -> opts "f" + CImpure ICEditSession -> both "f" "file" CImpure ICTranslateSession -> both "f langs" "cat" _ -> none |
