@@ -1,6 +1,6 @@
1{-# LANGUAGE FlexibleInstances, IncoherentInstances, PatternGuards #-}
1{-# LANGUAGE FlexibleInstances, IncoherentInstances, PatternGuards #-}
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
5import Text.Printf
5import Text.Printf
6import Numeric
6import Numeric
@@ -12,12 +12,24 @@ import qualified Data.ByteString.UTF8 as UTF8
12-- import qualified Data.Text as T
12-- import qualified Data.Text as T
13import Text.Trifecta hiding (Err)
13import Text.Trifecta hiding (Err)
14import Text.Trifecta.Delta
14import Text.Trifecta.Delta
16import Idris.Core.TT
17import Idris.Core.TT
17import Idris.Core.Binary
18import Idris.Core.Binary
19import Control.Applicative hiding (Const)
20import Control.Applicative hiding (Const)
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)
27+getLen :: Handle -> IO (Either Err Int)
28+getLen h = do s <- getNChar h 6 ""
30+ ((num, ""):_) -> return $ Right num
31+ _ -> return $ Left . Msg $ "Couldn't read length " ++ s
21data SExp = SexpList [SExp]
33data SExp = SexpList [SExp]
22 | StringAtom String
34 | StringAtom String
23 | BoolAtom Bool
35 | BoolAtom Bool