mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
GF Shell: refactoring for improved modularity and reusability:
+ Generalize the CommandInfo type by parameterizing it on the monad
instead of just the environment.
+ Generalize the commands defined in
GF.Command.{Commands,Commands2,CommonCommands,SourceCommands,HelpCommand}
to work in any monad that supports the needed operations.
+ Liberate GF.Command.Interpreter from the IO monad.
Also, move the current PGF from CommandEnv to GFEnv in
GF.Interactive, making the command interpreter even more generic.
+ Use a state monad to maintain the state of the interpreter in
GF.{Interactive,Interactive2}.
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
module GF.Command.CommandInfo where
|
||||
import GF.Command.Abstract(Option,Expr)
|
||||
import GF.Infra.SIO(SIO)
|
||||
import qualified PGF as H(showExpr)
|
||||
import qualified PGF.Internal as H(Literal(LStr),Expr(ELit)) ----
|
||||
import GF.Text.Pretty(Doc)
|
||||
|
||||
data CommandInfo env = CommandInfo {
|
||||
exec :: env -> [Option] -> [Expr] -> SIO CommandOutput,
|
||||
data CommandInfo m = CommandInfo {
|
||||
exec :: [Option] -> [Expr] -> m CommandOutput,
|
||||
synopsis :: String,
|
||||
syntax :: String,
|
||||
explanation :: String,
|
||||
@@ -17,11 +15,11 @@ data CommandInfo env = CommandInfo {
|
||||
needsTypeCheck :: Bool
|
||||
}
|
||||
|
||||
mapCommandEnv f c = c { exec = exec c . f }
|
||||
mapCommandExec f c = c { exec = \ opts ts -> f (exec c opts ts) }
|
||||
|
||||
emptyCommandInfo :: CommandInfo env
|
||||
--emptyCommandInfo :: CommandInfo env
|
||||
emptyCommandInfo = CommandInfo {
|
||||
exec = \_ _ ts -> return $ pipeExprs ts, ----
|
||||
exec = error "command not implemented",
|
||||
synopsis = "",
|
||||
syntax = "",
|
||||
explanation = "",
|
||||
@@ -33,10 +31,7 @@ emptyCommandInfo = CommandInfo {
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
class TypeCheckArg env where typeCheckArg :: env -> Expr -> Either Doc Expr
|
||||
|
||||
instance TypeCheckArg env => TypeCheckArg (x,env) where
|
||||
typeCheckArg (x,env) = typeCheckArg env
|
||||
class Monad m => TypeCheckArg m where typeCheckArg :: Expr -> m Expr
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user