on master help sign in
use process in ideslave loop
1b65f6aHannes Mehnert
src/Idris/AbsSyntaxTree.hs+1
@@ -149,6 +149,7 @@ idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
149
149
150-- | The monad for the main REPL - reading and processing files and updating
150-- | The monad for the main REPL - reading and processing files and updating
151-- global state (hence the IO inner monad).
151-- global state (hence the IO inner monad).
152+--type Idris = WriterT [Either String (IO ())] (State IState a))
152type Idris = StateT IState IO
153type Idris = StateT IState IO
153
154
154-- Commands in the REPL
155-- Commands in the REPL
src/Idris/IdeSlave.hs+12−10
@@ -1,11 +1,11 @@
1{-# LANGUAGE FlexibleInstances, IncoherentInstances #-}
1{-# LANGUAGE FlexibleInstances, IncoherentInstances #-}
2
2
3−module Idris.IdeSlave(receiveMessage, sendMessage) where
3+module Idris.IdeSlave(receiveMessage, sendMessage, IdeSlaveCommand(..)) where
4
4
5import Text.Printf
5import Text.Printf
6import Numeric
6import Numeric
7import Data.List
7import Data.List
8−
8+-- import qualified Data.Text as T
9import Text.Parsec
9import Text.Parsec
10
10
11data SExp = List [SExp]
11data SExp = List [SExp]
@@ -74,20 +74,22 @@ quotedChar = noneOf "\""
74parseSExp :: String -> Either ParseError SExp
74parseSExp :: String -> Either ParseError SExp
75parseSExp input = parse pSExp "(unknown)" input
75parseSExp input = parse pSExp "(unknown)" input
76
76
77−data Command = Version
77+data IdeSlaveCommand = Version
78+ | Interpret String
78 deriving Show
79 deriving Show
79
80
80−sexpToCommand :: SExp -> Maybe Command
81+sexpToCommand :: SExp -> Maybe IdeSlaveCommand
81−sexpToCommand (List (x:[])) = sexpToCommand x
82+sexpToCommand (List (x:[])) = sexpToCommand x
83+sexpToCommand (List [SymbolAtom "interpret", StringAtom cmd]) = Just (Interpret cmd)
82−sexpToCommand (SymbolAtom "version") = Just Version
84+sexpToCommand (SymbolAtom "version") = Just Version
83−sexpToCommand _ = Nothing
85+sexpToCommand _ = Nothing
84
86
85−receiveMessage :: IO (Maybe Command)
87+receiveMessage :: IO (Maybe IdeSlaveCommand)
86receiveMessage
88receiveMessage
87 = do x <- getLine
89 = do x <- getLine
88 return (receiveString x)
90 return (receiveString x)
89
91
90−receiveString :: String -> Maybe Command
92+receiveString :: String -> Maybe IdeSlaveCommand
91receiveString x =
93receiveString x =
92 case readHex (take 6 x) of
94 case readHex (take 6 x) of
93 ((num, ""):_) ->
95 ((num, ""):_) ->
@@ -97,7 +99,7 @@ receiveString x =
97 else parseSExpToCommand msg
99 else parseSExpToCommand msg
98 _ -> error "blah"
100 _ -> error "blah"
99
101
100−parseSExpToCommand :: String -> Maybe Command
102+parseSExpToCommand :: String -> Maybe IdeSlaveCommand
101parseSExpToCommand msg =
103parseSExpToCommand msg =
102 case parseSExp msg of
104 case parseSExp msg of
103 Left _ -> Nothing
105 Left _ -> Nothing
src/Idris/REPL.hs+9
@@ -87,6 +87,15 @@ ideslave orig mods
87 = do x <- liftIO $ receiveMessage
87 = do x <- liftIO $ receiveMessage
88 case x of
88 case x of
89 Nothing -> do liftIO $ sendMessage (Just "did not understand")
89 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))
90 Just y -> do liftIO $ sendMessage (Just "understood you!")
99 Just y -> do liftIO $ sendMessage (Just "understood you!")
91 liftIO $ sendMessage (Just "Hello world")
100 liftIO $ sendMessage (Just "Hello world")
92 ideslave orig mods
101 ideslave orig mods