forked from GitHub/gf-core
command cm
This commit is contained in:
@@ -210,12 +210,14 @@ purgeShellState sh = ShSt {
|
|||||||
|
|
||||||
changeMain :: Maybe Ident -> ShellState -> Err ShellState
|
changeMain :: Maybe Ident -> ShellState -> Err ShellState
|
||||||
changeMain Nothing (ShSt _ _ cs ms ss cfs pis mos os rs acs s) =
|
changeMain Nothing (ShSt _ _ cs ms ss cfs pis mos os rs acs s) =
|
||||||
return (ShSt Nothing Nothing cs ms ss cfs pis mos os rs acs s)
|
return (ShSt Nothing Nothing [] ms ss cfs pis mos os rs acs s)
|
||||||
changeMain (Just c) (ShSt _ _ cs ms ss cfs pis mos os rs acs s) =
|
changeMain (Just c) st@(ShSt _ _ cs ms ss cfs pis mos os rs acs s) =
|
||||||
case lookup c (map fst cs) of
|
case lookup c (M.modules ms) of
|
||||||
Just i -> do
|
Just _ -> do
|
||||||
a <- M.abstractOfConcrete ms i
|
a <- M.abstractOfConcrete ms c
|
||||||
return (ShSt (Just a) (Just i) cs ms ss cfs pis mos os rs acs s)
|
let cas = M.allConcretes ms a
|
||||||
|
let cs' = [((c,c),True) | c <- cas]
|
||||||
|
return (ShSt (Just a) (Just c) cs' ms ss cfs pis mos os rs acs s)
|
||||||
_ -> P.prtBad "The state has no concrete syntax named" c
|
_ -> P.prtBad "The state has no concrete syntax named" c
|
||||||
|
|
||||||
-- form just one state grammar, if unique, from a canonical grammar
|
-- form just one state grammar, if unique, from a canonical grammar
|
||||||
@@ -385,6 +387,7 @@ getLangNameOpt opts file =
|
|||||||
-- modify state
|
-- modify state
|
||||||
|
|
||||||
type ShellStateOper = ShellState -> ShellState
|
type ShellStateOper = ShellState -> ShellState
|
||||||
|
type ShellStateOperErr = ShellState -> Err ShellState
|
||||||
|
|
||||||
reinitShellState :: ShellStateOper
|
reinitShellState :: ShellStateOper
|
||||||
reinitShellState = const emptyShellState
|
reinitShellState = const emptyShellState
|
||||||
|
|||||||
@@ -102,8 +102,9 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = checkOptions st co >> case comm of
|
|||||||
CImport file -> useIOE sa $ do
|
CImport file -> useIOE sa $ do
|
||||||
st1 <- shellStateFromFiles opts st file
|
st1 <- shellStateFromFiles opts st file
|
||||||
ioeIO $ changeState (const st1) sa --- \ ((_,h),a) -> ((st,h), a))
|
ioeIO $ changeState (const st1) sa --- \ ((_,h),a) -> ((st,h), a))
|
||||||
CEmptyState -> changeState reinitShellState sa
|
CEmptyState -> changeState reinitShellState sa
|
||||||
CStripState -> changeState purgeShellState sa
|
CChangeMain ma -> changeStateErr (changeMain ma) sa
|
||||||
|
CStripState -> changeState purgeShellState sa
|
||||||
|
|
||||||
{-
|
{-
|
||||||
CRemoveLanguage lan -> changeState (removeLanguage lan) sa
|
CRemoveLanguage lan -> changeState (removeLanguage lan) sa
|
||||||
@@ -173,7 +174,7 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = checkOptions st co >> case comm of
|
|||||||
maybe (I.identC "?") id $ -- meaningful if no opers in t
|
maybe (I.identC "?") id $ -- meaningful if no opers in t
|
||||||
maybe (resourceOfShellState st) (return . I.identC) $ -- topmost res
|
maybe (resourceOfShellState st) (return . I.identC) $ -- topmost res
|
||||||
getOptVal opts useResource -- flag -res=m
|
getOptVal opts useResource -- flag -res=m
|
||||||
justOutput (putStrLn (err id (prt . stripTerm) (
|
justOutput opts (putStrLn (err id (prt . stripTerm) (
|
||||||
string2srcTerm src m t >>=
|
string2srcTerm src m t >>=
|
||||||
Ch.justCheckLTerm src >>=
|
Ch.justCheckLTerm src >>=
|
||||||
Co.computeConcrete src))) sa
|
Co.computeConcrete src))) sa
|
||||||
@@ -182,7 +183,7 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = checkOptions st co >> case comm of
|
|||||||
maybe (I.identC "?") id $ -- meaningful if no opers in t
|
maybe (I.identC "?") id $ -- meaningful if no opers in t
|
||||||
maybe (resourceOfShellState st) (return . I.identC) $ -- topmost res
|
maybe (resourceOfShellState st) (return . I.identC) $ -- topmost res
|
||||||
getOptVal opts useResource -- flag -res=m
|
getOptVal opts useResource -- flag -res=m
|
||||||
justOutput (putStrLn (err id (unlines . map prOperSignature) (
|
justOutput opts (putStrLn (err id (unlines . map prOperSignature) (
|
||||||
string2srcTerm src m t >>=
|
string2srcTerm src m t >>=
|
||||||
Co.computeConcrete src >>=
|
Co.computeConcrete src >>=
|
||||||
return . L.opersForType src))) sa
|
return . L.opersForType src))) sa
|
||||||
@@ -190,7 +191,7 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = checkOptions st co >> case comm of
|
|||||||
|
|
||||||
CTranslationQuiz il ol -> do
|
CTranslationQuiz il ol -> do
|
||||||
warnDiscont opts
|
warnDiscont opts
|
||||||
justOutput (teachTranslation opts (sgr il) (sgr ol)) sa
|
justOutput opts (teachTranslation opts (sgr il) (sgr ol)) sa
|
||||||
CTranslationList il ol n -> do
|
CTranslationList il ol n -> do
|
||||||
warnDiscont opts
|
warnDiscont opts
|
||||||
qs <- transTrainList opts (sgr il) (sgr ol) (toInteger n)
|
qs <- transTrainList opts (sgr il) (sgr ol) (toInteger n)
|
||||||
@@ -198,17 +199,17 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = checkOptions st co >> case comm of
|
|||||||
|
|
||||||
CMorphoQuiz -> do
|
CMorphoQuiz -> do
|
||||||
warnDiscont opts
|
warnDiscont opts
|
||||||
justOutput (teachMorpho opts gro) sa
|
justOutput opts (teachMorpho opts gro) sa
|
||||||
CMorphoList n -> do
|
CMorphoList n -> do
|
||||||
warnDiscont opts
|
warnDiscont opts
|
||||||
qs <- useIOE [] $ morphoTrainList opts gro (toInteger n)
|
qs <- useIOE [] $ morphoTrainList opts gro (toInteger n)
|
||||||
returnArg (AString $ foldr (+++++) [] [unlines (s:ss) | (s,ss) <- qs]) sa
|
returnArg (AString $ foldr (+++++) [] [unlines (s:ss) | (s,ss) <- qs]) sa
|
||||||
|
|
||||||
CReadFile file -> returnArgIO (readFileIf file >>= return . AString) sa
|
CReadFile file -> returnArgIO (readFileIf file >>= return . AString) sa
|
||||||
CWriteFile file -> justOutputArg (writeFile file) sa
|
CWriteFile file -> justOutputArg opts (writeFile file) sa
|
||||||
CAppendFile file -> justOutputArg (appendFile file) sa
|
CAppendFile file -> justOutputArg opts (appendFile file) sa
|
||||||
CSpeakAloud -> justOutputArg (speechGenerate opts) sa
|
CSpeakAloud -> justOutputArg opts (speechGenerate opts) sa
|
||||||
CSystemCommand s -> justOutput (system s >> return ()) sa
|
CSystemCommand s -> justOutput opts (system s >> return ()) sa
|
||||||
CPutString -> changeArg (opSS2CommandArg (optStringCommand opts gro)) sa
|
CPutString -> changeArg (opSS2CommandArg (optStringCommand opts gro)) sa
|
||||||
----- CShowTerm -> changeArg (opTS2CommandArg (optPrintTerm opts gro) . s2t) sa
|
----- CShowTerm -> changeArg (opTS2CommandArg (optPrintTerm opts gro) . s2t) sa
|
||||||
|
|
||||||
@@ -222,9 +223,9 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = checkOptions st co >> case comm of
|
|||||||
_ -> returnArg (AString txtHelpFileSummary) sa
|
_ -> returnArg (AString txtHelpFileSummary) sa
|
||||||
|
|
||||||
CPrintGrammar -> returnArg (AString (optPrintGrammar opts gro)) sa
|
CPrintGrammar -> returnArg (AString (optPrintGrammar opts gro)) sa
|
||||||
CPrintGlobalOptions -> justOutput (putStrLn $ prShellStateInfo st) sa
|
CPrintGlobalOptions -> justOutput opts (putStrLn $ prShellStateInfo st) sa
|
||||||
CPrintInformation c -> justOutput (useIOE () $ showInformation opts st c) sa
|
CPrintInformation c -> justOutput opts (useIOE () $ showInformation opts st c) sa
|
||||||
CPrintLanguages -> justOutput
|
CPrintLanguages -> justOutput opts
|
||||||
(putStrLn $ unwords $ map prLanguage $ allLanguages st) sa
|
(putStrLn $ unwords $ map prLanguage $ allLanguages st) sa
|
||||||
CPrintMultiGrammar -> do
|
CPrintMultiGrammar -> do
|
||||||
sa' <- changeState purgeShellState sa
|
sa' <- changeState purgeShellState sa
|
||||||
@@ -235,7 +236,7 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = checkOptions st co >> case comm of
|
|||||||
---- CPrintGramlet -> returnArg (AString (Gr.prGramlet st)) sa
|
---- CPrintGramlet -> returnArg (AString (Gr.prGramlet st)) sa
|
||||||
---- CPrintCanonXML -> returnArg (AString (Canon.prCanonXML st False)) sa
|
---- CPrintCanonXML -> returnArg (AString (Canon.prCanonXML st False)) sa
|
||||||
---- CPrintCanonXMLStruct -> returnArg (AString (Canon.prCanonXML st True)) sa
|
---- CPrintCanonXMLStruct -> returnArg (AString (Canon.prCanonXML st True)) sa
|
||||||
_ -> justOutput (putStrLn "command not understood") sa
|
_ -> justOutput opts (putStrLn "command not understood") sa
|
||||||
|
|
||||||
where
|
where
|
||||||
sgr = stateGrammarOfLang st
|
sgr = stateGrammarOfLang st
|
||||||
@@ -264,6 +265,11 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = checkOptions st co >> case comm of
|
|||||||
changeState :: ShellStateOper -> ShellIO
|
changeState :: ShellStateOper -> ShellIO
|
||||||
changeState f ((st,h),a) = return ((f st,h), a)
|
changeState f ((st,h),a) = return ((f st,h), a)
|
||||||
|
|
||||||
|
changeStateErr :: ShellStateOperErr -> ShellIO
|
||||||
|
changeStateErr f ((st,h),a) = case f st of
|
||||||
|
Ok st' -> return ((st',h), a)
|
||||||
|
Bad s -> return ((st, h),AError s)
|
||||||
|
|
||||||
changeArg :: (CommandArg -> CommandArg) -> ShellIO
|
changeArg :: (CommandArg -> CommandArg) -> ShellIO
|
||||||
changeArg f (st,a) = return (st, f a)
|
changeArg f (st,a) = return (st, f a)
|
||||||
|
|
||||||
@@ -279,11 +285,13 @@ returnArg = changeArg . const
|
|||||||
returnArgIO :: IO CommandArg -> ShellIO
|
returnArgIO :: IO CommandArg -> ShellIO
|
||||||
returnArgIO io (st,_) = io >>= (\a -> return (st,a))
|
returnArgIO io (st,_) = io >>= (\a -> return (st,a))
|
||||||
|
|
||||||
justOutputArg :: (String -> IO ()) -> ShellIO
|
justOutputArg :: Options -> (String -> IO ()) -> ShellIO
|
||||||
justOutputArg f sa@(st,a) = f (prCommandArg a) >> return (st, AUnit)
|
justOutputArg opts f sa@(st,a) = f (utf (prCommandArg a)) >> return (st, AUnit)
|
||||||
|
where
|
||||||
|
utf = if (oElem useUTF8 opts) then encodeUTF8 else id
|
||||||
|
|
||||||
justOutput :: IO () -> ShellIO
|
justOutput :: Options -> IO () -> ShellIO
|
||||||
justOutput = justOutputArg . const
|
justOutput opts = justOutputArg opts . const
|
||||||
|
|
||||||
-- type system for command arguments; instead of plain strings...
|
-- type system for command arguments; instead of plain strings...
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ pCommand ws = case ws of
|
|||||||
"i" : f : [] -> aUnit (CImport f)
|
"i" : f : [] -> aUnit (CImport f)
|
||||||
"rl" : l : [] -> aUnit (CRemoveLanguage (language l))
|
"rl" : l : [] -> aUnit (CRemoveLanguage (language l))
|
||||||
"e" : [] -> aUnit CEmptyState
|
"e" : [] -> aUnit CEmptyState
|
||||||
|
"cm" : a : [] -> aUnit (CChangeMain (Just (pzIdent a)))
|
||||||
|
"cm" : [] -> aUnit (CChangeMain Nothing)
|
||||||
"s" : [] -> aUnit CStripState
|
"s" : [] -> aUnit CStripState
|
||||||
"tg" : f : [] -> aUnit (CTransformGrammar f)
|
"tg" : f : [] -> aUnit (CTransformGrammar f)
|
||||||
"cl" : f : [] -> aUnit (CConvertLatex f)
|
"cl" : f : [] -> aUnit (CConvertLatex f)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ data Command =
|
|||||||
CImport FilePath
|
CImport FilePath
|
||||||
| CRemoveLanguage Language
|
| CRemoveLanguage Language
|
||||||
| CEmptyState
|
| CEmptyState
|
||||||
|
| CChangeMain (Maybe I.Ident)
|
||||||
| CStripState
|
| CStripState
|
||||||
| CTransformGrammar FilePath
|
| CTransformGrammar FilePath
|
||||||
| CConvertLatex FilePath
|
| CConvertLatex FilePath
|
||||||
@@ -161,7 +162,7 @@ optionsOfCommand co = case co of
|
|||||||
CWriteFile _ -> none
|
CWriteFile _ -> none
|
||||||
CAppendFile _ -> none
|
CAppendFile _ -> none
|
||||||
CSpeakAloud -> flags "language"
|
CSpeakAloud -> flags "language"
|
||||||
CPutString -> flags "filter length"
|
CPutString -> both "utf8" "filter length"
|
||||||
CShowTerm -> flags "printer"
|
CShowTerm -> flags "printer"
|
||||||
CSystemCommand _ -> none
|
CSystemCommand _ -> none
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user