on master help sign in
use process in ideslave loop
commit1b65f6a5da0b7d016e4a4d25b2e7e4e485747af2 authorHannes Mehnert <hannes@mehnert.org> dateThu 11 Apr 2013, 13:03 (14 years ago) parentc458007
3 files changed+22−10
src/Idris/AbsSyntaxTree.hs+1 src/Idris/IdeSlave.hs+12−10 src/Idris/REPL.hs+9
src/Idris/AbsSyntaxTree.hs+1
@@ -149,6 +149,7 @@ idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
149149
150150-- | The monad for the main REPL - reading and processing files and updating
151151-- global state (hence the IO inner monad).
152+--type Idris = WriterT [Either String (IO ())] (State IState a))
152153type Idris = StateT IState IO
153154
154155-- Commands in the REPL
src/Idris/IdeSlave.hs+12−10
@@ -1,11 +1,11 @@
11{-# LANGUAGE FlexibleInstances, IncoherentInstances #-}
22
3−module Idris.IdeSlave(receiveMessage, sendMessage) where
3+module Idris.IdeSlave(receiveMessage, sendMessage, IdeSlaveCommand(..)) where
44
55import Text.Printf
66import Numeric
77import Data.List
8−
8+-- import qualified Data.Text as T
99import Text.Parsec
1010
1111data SExp = List [SExp]
@@ -74,20 +74,22 @@ quotedChar = noneOf "\""
7474parseSExp :: String -> Either ParseError SExp
7575parseSExp input = parse pSExp "(unknown)" input
7676
77−data Command = Version
77+data IdeSlaveCommand = Version
78+ | Interpret String
7879 deriving Show
7980
80−sexpToCommand :: SExp -> Maybe Command
81−sexpToCommand (List (x:[])) = sexpToCommand x
82−sexpToCommand (SymbolAtom "version") = Just Version
83−sexpToCommand _ = Nothing
81+sexpToCommand :: SExp -> Maybe IdeSlaveCommand
82+sexpToCommand (List (x:[])) = sexpToCommand x
83+sexpToCommand (List [SymbolAtom "interpret", StringAtom cmd]) = Just (Interpret cmd)
84+sexpToCommand (SymbolAtom "version") = Just Version
85+sexpToCommand _ = Nothing
8486
85−receiveMessage :: IO (Maybe Command)
87+receiveMessage :: IO (Maybe IdeSlaveCommand)
8688receiveMessage
8789 = do x <- getLine
8890 return (receiveString x)
8991
90−receiveString :: String -> Maybe Command
92+receiveString :: String -> Maybe IdeSlaveCommand
9193receiveString x =
9294 case readHex (take 6 x) of
9395 ((num, ""):_) ->
@@ -97,7 +99,7 @@ receiveString x =
9799 else parseSExpToCommand msg
98100 _ -> error "blah"
99101
100−parseSExpToCommand :: String -> Maybe Command
102+parseSExpToCommand :: String -> Maybe IdeSlaveCommand
101103parseSExpToCommand msg =
102104 case parseSExp msg of
103105 Left _ -> Nothing
src/Idris/REPL.hs+9
@@ -87,6 +87,15 @@ ideslave orig mods
8787 = do x <- liftIO $ receiveMessage
8888 case x of
8989 Nothing -> do liftIO $ sendMessage (Just "did not understand")
90+ Just (Interpret cmd) -> do i <- getIState
91+ let fn = case mods of
92+ (f:_) -> f
93+ _ -> ""
94+ case parseCmd i cmd of
95+ Left err -> do liftIO $ sendMessage (show err)
96+ Right cmd -> do idrisCatch (do xs <- process fn cmd
97+ liftIO $ sendMessage xs)
98+ (\e -> do liftIO $ sendMessage (show e))
9099 Just y -> do liftIO $ sendMessage (Just "understood you!")
91100 liftIO $ sendMessage (Just "Hello world")
92101 ideslave orig mods