@@ -103,22 +103,22 @@ sexpToCommand (SexpList [SymbolAtom "repl-completions", StringAtom prefix]) = Ju
103sexpToCommand (SexpList [SymbolAtom "load-file", StringAtom filename]) = Just (LoadFile filename)
103sexpToCommand (SexpList [SymbolAtom "load-file", StringAtom filename]) = Just (LoadFile filename)
104sexpToCommand _ = Nothing
104sexpToCommand _ = Nothing
106−parseMessage :: String -> (SExp, Integer)
106+parseMessage :: String -> Either Err (SExp, Integer)
107parseMessage x = case receiveString x of
107parseMessage x = case receiveString x of
108− (SexpList [cmd, (IntegerAtom id)]) ->
108+ Right (SexpList [cmd, (IntegerAtom id)]) -> Right (cmd, id)
109− (cmd, id)
109+ Left err -> Left err
111−receiveString :: String -> SExp
111+receiveString :: String -> Either Err SExp
112receiveString x =
112receiveString x =
113 case readHex (take 6 x) of
113 case readHex (take 6 x) of
114 ((num, ""):_) ->
114 ((num, ""):_) ->
115 let msg = drop 6 x in
115 let msg = drop 6 x in
116 if (length msg) /= (num - 1)
116 if (length msg) /= (num - 1)
117− then error "bad input length"
117+ then Left . Msg $ "bad input length"
118 else (case parseSExp msg of
118 else (case parseSExp msg of
119− Left _ -> error "parse failure"
119+ Left _ -> Left . Msg $ "parse failure"
120− Right r -> r)
120+ Right r -> Right r)
121− _ -> error "readHex failed"
121+ _ -> Left . Msg $ "readHex failed"
123convSExp :: SExpable a => String -> a -> Integer -> String
123convSExp :: SExpable a => String -> a -> Integer -> String
124convSExp pre s id =
124convSExp pre s id =