-- Meh, this is a pain. The parser is pure so we'd basically need to give it
-- the result of hGetContents; but that breaks any further input ("semi-closes"
-- the handle). So just read a char at a time until we get a successful parse.
--
-- The spec doesn't say what to do if we get nonsense like anything starting
-- with ")", so we choose to loop forever (or until EOF).
--
-- O(n^2 + np) where n is the length of the input and p the time it takes for a
-- parse.
scmRead :: Handle -> IO ScmValue
scmRead hdl = go []
 where
   go s = do
      eof <- hIsEOF hdl
      if eof
         then return ScmEOF
         else do
            c <- hGetChar hdl
            let s' = s ++ [c]
            either (const $ go s') return (runParser value "" s')
scmRead :: Handle -> IO ScmValue
scmRead hdl = go []
 where
   go s = do
      eof <- hIsEOF hdl
      if eof
         then return ScmEOF
         else do
            c <- hGetChar hdl
            let s' = s ++ [c]
            either (const $ go s') return (runParser value "" s')
scmRead hdl = go []
 where
   go s = do
      eof <- hIsEOF hdl
      if eof
         then return ScmEOF
         else do
            c <- hGetChar hdl
            let s' = s ++ [c]
            either (const $ go s') return (runParser value "" s')