on master help sign in
move getNChar and getLen to IdeSlave
commita0ccc57a457d92d0edf422fa6b2b3f9ca9382cbb authorHannes Mehnert <hannes@mehnert.org> dateMon 4 Aug 2014, 12:22 (12 years ago) parent2558c13
2 files changed+18−14
src/Idris/IdeSlave.hs+13−1 src/Idris/REPL.hs+5−13
src/Idris/IdeSlave.hs+13−1
@@ -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
src/Idris/REPL.hs+5−13
@@ -236,23 +236,15 @@ ideslaveStart s orig mods
236236 _ -> return ()
237237 ideslave h orig mods
238238
239−getNChar :: Handle -> Int -> String -> IO (String)
240−getNChar _ 0 s = return (reverse s)
241−getNChar h n s = do c <- hGetChar h
242− getNChar h (n - 1) (c : s)
243−
244−getLen :: Handle -> Idris (Int)
245−getLen h = do s <- runIO $ getNChar h 6 ""
246− case readHex s of
247− ((num, ""):_) -> return num
248− _ -> ierror (Msg $ "Couldn't read length " ++ s)
249−
250239ideslave :: Handle -> IState -> [FilePath] -> Idris ()
251240ideslave h orig mods
252241 = do idrisCatch
253242 (do let inh = if h == stdout then stdin else h
254− len <- getLen inh
255− l <- runIO $ getNChar inh len ""
243+ len' <- runIO $ IdeSlave.getLen inh
244+ len <- case len' of
245+ Left err -> ierror err
246+ Right n -> return n
247+ l <- runIO $ IdeSlave.getNChar inh len ""
256248 (sexp, id) <- case IdeSlave.parseMessage l of
257249 Left err -> ierror err
258250 Right (sexp, id) -> return (sexp, id)