mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
reload command in shell
This commit is contained in:
@@ -665,6 +665,10 @@ allCommands env@(pgf, mos) = Map.fromList [
|
|||||||
longname = "quit",
|
longname = "quit",
|
||||||
synopsis = "exit GF interpreter"
|
synopsis = "exit GF interpreter"
|
||||||
}),
|
}),
|
||||||
|
("r", emptyCommandInfo {
|
||||||
|
longname = "reload",
|
||||||
|
synopsis = "repeat the latest import command"
|
||||||
|
}),
|
||||||
("rf", emptyCommandInfo {
|
("rf", emptyCommandInfo {
|
||||||
longname = "read_file",
|
longname = "read_file",
|
||||||
synopsis = "read string or tree input from a file",
|
synopsis = "read string or tree input from a file",
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ computeTermOpt rec gr = comput True where
|
|||||||
return $ lookup x g
|
return $ lookup x g
|
||||||
case t' of
|
case t' of
|
||||||
_ | t == t' -> return t
|
_ | t == t' -> return t
|
||||||
_ -> comp g t'
|
_ -> comp g t' --- why compute again? AR 25/8/2011
|
||||||
|
|
||||||
-- Abs x@(IA _) b -> do
|
-- Abs x@(IA _) b -> do
|
||||||
Abs _ _ _ | full -> do -- \xs -> b
|
Abs _ _ _ | full -> do -- \xs -> b
|
||||||
@@ -391,7 +391,7 @@ computeTermOpt rec gr = comput True where
|
|||||||
ps0 <- mapM (compPatternMacro . fst) cs
|
ps0 <- mapM (compPatternMacro . fst) cs
|
||||||
|
|
||||||
cs' <- mapM (compBranch g) (zip ps0 (map snd cs))
|
cs' <- mapM (compBranch g) (zip ps0 (map snd cs))
|
||||||
----- cs' <- return (zip ps0 (map snd cs)) --- probably right AR 22/8/2011
|
----- cs' <- return (zip ps0 (map snd cs)) --- probably right AR 22/8/2011 but can leave uninstantiated variables :-(
|
||||||
|
|
||||||
---- cs' <- mapM (compBranch g) cs
|
---- cs' <- mapM (compBranch g) cs
|
||||||
return $ T i cs' -- happens with variable types
|
return $ T i cs' -- happens with variable types
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ loopOptNewCPU opts gfenv'
|
|||||||
execute1 :: Options -> GFEnv -> String -> IO (Maybe GFEnv)
|
execute1 :: Options -> GFEnv -> String -> IO (Maybe GFEnv)
|
||||||
execute1 opts gfenv0 s0 =
|
execute1 opts gfenv0 s0 =
|
||||||
interruptible $ optionallyShowCPUTime opts $
|
interruptible $ optionallyShowCPUTime opts $
|
||||||
case pwords of
|
case pwords s0 of
|
||||||
-- special commands, requiring source grammar in env
|
-- special commands, requiring source grammar in env
|
||||||
{-"eh":w:_ -> do
|
{-"eh":w:_ -> do
|
||||||
cs <- readFile w >>= return . map words . lines
|
cs <- readFile w >>= return . map words . lines
|
||||||
@@ -134,6 +134,7 @@ execute1 opts gfenv0 s0 =
|
|||||||
"dc":ws -> define_command ws
|
"dc":ws -> define_command ws
|
||||||
"dt":ws -> define_tree ws
|
"dt":ws -> define_tree ws
|
||||||
"ph":_ -> print_history
|
"ph":_ -> print_history
|
||||||
|
"r" :_ -> reload_last
|
||||||
"se":ws -> set_encoding ws
|
"se":ws -> set_encoding ws
|
||||||
-- ordinary commands, working on CommandEnv
|
-- ordinary commands, working on CommandEnv
|
||||||
_ -> do interpretCommandLine env s0
|
_ -> do interpretCommandLine env s0
|
||||||
@@ -145,9 +146,9 @@ execute1 opts gfenv0 s0 =
|
|||||||
env = commandenv gfenv0
|
env = commandenv gfenv0
|
||||||
sgr = sourcegrammar gfenv0
|
sgr = sourcegrammar gfenv0
|
||||||
gfenv = gfenv0 {history = s0 : history gfenv0}
|
gfenv = gfenv0 {history = s0 : history gfenv0}
|
||||||
pwords = case words s0 of
|
pwords s = case words s of
|
||||||
w:ws -> getCommandOp w :ws
|
w:ws -> getCommandOp w :ws
|
||||||
ws -> ws
|
ws -> ws
|
||||||
|
|
||||||
interruptible act =
|
interruptible act =
|
||||||
either (\e -> printException e >> return (Just gfenv)) return
|
either (\e -> printException e >> return (Just gfenv)) return
|
||||||
@@ -256,6 +257,16 @@ execute1 opts gfenv0 s0 =
|
|||||||
|
|
||||||
print_history = mapM_ putStrLn (reverse (history gfenv0))>> continue gfenv
|
print_history = mapM_ putStrLn (reverse (history gfenv0))>> continue gfenv
|
||||||
|
|
||||||
|
reload_last = do
|
||||||
|
let imports = [(s,ws) | s <- history gfenv0, ("i":ws) <- [pwords s]]
|
||||||
|
case imports of
|
||||||
|
(s,ws):_ -> do
|
||||||
|
putStrLn $ "repeating latest import: " ++ s
|
||||||
|
import_ ws
|
||||||
|
_ -> do
|
||||||
|
putStrLn $ "no import in history"
|
||||||
|
continue gfenv
|
||||||
|
|
||||||
set_encoding [c] =
|
set_encoding [c] =
|
||||||
do let cod = renameEncoding c
|
do let cod = renameEncoding c
|
||||||
#ifdef mingw32_HOST_OS
|
#ifdef mingw32_HOST_OS
|
||||||
|
|||||||
Reference in New Issue
Block a user