summaryrefslogtreecommitdiff
path: root/src/GF/IDE
diff options
context:
space:
mode:
authoraarne <unknown>2005-11-09 21:34:01 +0000
committeraarne <unknown>2005-11-09 21:34:01 +0000
commite322a9e5e367f87955f7f0b53546a7402c8e2f0e (patch)
tree16750990cbe12338e8e07636feae08fccce63025 /src/GF/IDE
parentaa3ba333d89cab64ed2e75f7d7e9b211e409d8e9 (diff)
started IDE support project
Diffstat (limited to 'src/GF/IDE')
-rw-r--r--src/GF/IDE/IDECommands.hs91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/GF/IDE/IDECommands.hs b/src/GF/IDE/IDECommands.hs
new file mode 100644
index 000000000..f879a87cd
--- /dev/null
+++ b/src/GF/IDE/IDECommands.hs
@@ -0,0 +1,91 @@
+----------------------------------------------------------------------
+-- |
+-- Module : IDECommands
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/11/09 22:34:01 $
+-- > CVS $Author: aarne $
+-- > CVS $Revision: 1.1 $
+--
+-- Commands usable in grammar-writing IDE.
+-----------------------------------------------------------------------------
+
+module GF.IDE.IDECommands where
+
+import GF.Infra.Ident (Ident, identC)
+import GF.Compile.ShellState
+import qualified GF.Shell.ShellCommands as S
+import qualified GF.Shell.Commands as E
+import qualified GF.Shell.CommandL as PE
+import GF.UseGrammar.Session
+import GF.UseGrammar.Custom
+import GF.Grammar.PrGrammar
+
+import GF.Infra.Option
+import GF.Data.Operations
+import GF.Infra.Modules
+import GF.Infra.UseIO
+
+data IDEState = IDE {
+ ideShellState :: ShellState,
+ ideAbstract :: Maybe Ident,
+ ideConcretes :: [Ident],
+ ideCurrentCnc :: Maybe Ident,
+ ideCurrentLin :: Maybe Ident, -- lin or lincat
+ ideSState :: Maybe SState
+ }
+
+emptyIDEState :: ShellState -> IDEState
+emptyIDEState shst = IDE shst Nothing [] Nothing Nothing Nothing
+
+data IDECommand =
+ IDEInit
+ | IDEAbstract Ident
+ | IDEConcrete Ident
+ | IDELin Ident
+ | IDEShell String -- S.Command
+ | IDEEdit String -- E.Command
+ | IDEQuit
+ | IDEVoid String -- the given command itself maybe
+
+
+execIDECommand :: IDECommand -> IDEState -> IOE IDEState
+execIDECommand c state = case c of
+ IDEInit ->
+ return $ emptyIDEState env
+ IDEAbstract a ->
+ return $ state {ideAbstract = Just a} ---- check a exists or import it
+ IDEEdit s ->
+ execEdit s
+ IDEShell s ->
+ execShell s
+ IDEVoid s -> ioeErr $ fail s
+ _ -> ioeErr $ fail "command not implemented"
+
+ where
+ env = ideShellState state
+ sstate = maybe initSState id $ ideSState state
+
+ execShell s = execEdit $ "gf" +++ s
+
+ execEdit s = ioeIO $ do
+ (env',sstate') <- E.execCommand env (PE.pCommand s) sstate
+ return $ state {ideShellState = env', ideSState = Just sstate'}
+
+ putMsg = putStrLn ---- XML
+
+pCommands :: String -> [IDECommand]
+pCommands = map pCommand . concatMap (chunks ";;" . words) . lines
+
+pCommand :: [String] -> IDECommand
+pCommand ws = case ws of
+ "gf" : s -> IDEShell $ unwords s
+ "edit" : s -> IDEEdit $ unwords s
+ "abstract" : a : _ -> IDEAbstract $ identC a
+ "concrete" : a : _ -> IDEConcrete $ identC a
+ "lin" : a : _ -> IDELin $ identC a
+ "empty" : _ -> IDEInit
+ "quit" : _ -> IDEQuit
+ _ -> IDEVoid $ unwords ws