@@ -1,6 +1,6 @@
11{-# LANGUAGE FlexibleInstances, IncoherentInstances, PatternGuards #-}
22
3−module Idris.IdeSlave(parseMessage, convSExp, IdeSlaveCommand(..), sexpToCommand, toSExp, SExp(..), SExpable, Opt(..), ideSlaveEpoch) where
3+module Idris.IdeSlave(parseMessage, convSExp, IdeSlaveCommand(..), sexpToCommand, toSExp, SExp(..), SExpable, Opt(..), ideSlaveEpoch, getLen, getNChar) where
44
55import Text.Printf
66import Numeric
@@ -12,12 +12,24 @@ import qualified Data.ByteString.UTF8 as UTF8
1212-- import qualified Data.Text as T
1313import Text.Trifecta hiding (Err)
1414import Text.Trifecta.Delta
15+import System.IO
1516
1617import Idris.Core.TT
1718import Idris.Core.Binary
1819
1920import Control.Applicative hiding (Const)
2021
22+getNChar :: Handle -> Int -> String -> IO (String)
23+getNChar _ 0 s = return (reverse s)
24+getNChar h n s = do c <- hGetChar h
25+ getNChar h (n - 1) (c : s)
26+
27+getLen :: Handle -> IO (Either Err Int)
28+getLen h = do s <- getNChar h 6 ""
29+ case readHex s of
30+ ((num, ""):_) -> return $ Right num
31+ _ -> return $ Left . Msg $ "Couldn't read length " ++ s
32+
2133data SExp = SexpList [SExp]
2234 | StringAtom String
2335 | BoolAtom Bool