@@ -46,6 +46,9 @@ instance (SExpable a) => SExpable (Maybe a) where
46instance (SExpable a) => SExpable [a] where
46instance (SExpable a) => SExpable [a] where
47 toSExp l = List (map toSExp l)
47 toSExp l = List (map toSExp l)
49+instance (SExpable a, SExpable b) => SExpable (a, b) where
50+ toSExp (l, r) = List [toSExp l, toSExp r]
49escape :: String -> String
52escape :: String -> String
50escape = concatMap escapeChar
53escape = concatMap escapeChar
@@ -74,15 +77,15 @@ quotedChar = noneOf "\""
74parseSExp :: String -> Either ParseError SExp
77parseSExp :: String -> Either ParseError SExp
75parseSExp input = parse pSExp "(unknown)" input
78parseSExp input = parse pSExp "(unknown)" input
77−data IdeSlaveCommand = Version
80+data IdeSlaveCommand = REPLCompletions String
78 | Interpret String
81 | Interpret String
79 deriving Show
82 deriving Show
81sexpToCommand :: SExp -> Maybe IdeSlaveCommand
84sexpToCommand :: SExp -> Maybe IdeSlaveCommand
82−sexpToCommand (List (x:[])) = sexpToCommand x
85+sexpToCommand (List (x:[])) = sexpToCommand x
83−sexpToCommand (List [SymbolAtom "interpret", StringAtom cmd]) = Just (Interpret cmd)
86+sexpToCommand (List [SymbolAtom "interpret", StringAtom cmd]) = Just (Interpret cmd)
84−sexpToCommand (SymbolAtom "version") = Just Version
87+sexpToCommand (List [SymbolAtom "repl-completions", StringAtom prefix]) = Just (REPLCompletions prefix)
85−sexpToCommand _ = Nothing
88+sexpToCommand _ = Nothing
87receiveMessage :: IO (SExp)
90receiveMessage :: IO (SExp)
88receiveMessage
91receiveMessage
@@ -106,7 +109,7 @@ sendMessage id s =
106 -- TODO: get real output here!!!
109 -- TODO: get real output here!!!
107 case s of
110 case s of
108 Left err -> putStrLn $ conv (List [SymbolAtom "abort", toSExp err])
111 Left err -> putStrLn $ conv (List [SymbolAtom "abort", toSExp err])
109− Right succ -> putStrLn $ conv (List [SymbolAtom "ok", List [toSExp succ, StringAtom "no output"]])
112+ Right succ -> putStrLn $ conv (List [SymbolAtom "ok", toSExp succ])
110 where conv sexp =
113 where conv sexp =
111 let str = sExpToString (List [SymbolAtom "return", sexp, IntegerAtom id]) in (getHexLength str) ++ str
114 let str = sExpToString (List [SymbolAtom "return", sexp, IntegerAtom id]) in (getHexLength str) ++ str