@@ -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