- Timestamp:
- 11/12/08 10:00:43 (8 weeks ago)
- Location:
- src/Pugs
- Files:
-
- 2 modified
-
AST/Eval.hs (modified) (2 diffs)
-
Prim.hs (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/AST/Eval.hs
r15616 r22989 4 4 import Pugs.Internals 5 5 import Pugs.Cont hiding (resetT) 6 import Control.Exception (try, Exception)6 import System.IO.Error (try, IOError) 7 7 8 8 import Pugs.AST.SIO … … 165 165 supress the exception and return an associated value instead. 166 166 -} 167 guardIOexcept :: MonadIO m => [(( Exception-> Bool), a)] -> IO a -> m a167 guardIOexcept :: MonadIO m => [((IOError -> Bool), a)] -> IO a -> m a 168 168 guardIOexcept safetyNet x = do 169 169 rv <- io $ try x -
src/Pugs/Prim.hs
r22317 r22989 39 39 import Data.IORef 40 40 import System.IO.Error (isEOFError) 41 import Control.Exception (ioErrors)42 41 43 42 import Pugs.Prim.Keyed … … 217 216 op1 "~^" = op1Cast (VStr . mapStr complement) 218 217 op1 "?^" = op1 "!" 219 op1 "\\" = \v -> do 220 return $ case v of 221 (VRef (MkRef (IScalar _))) -> VRef . scalarRef $ v 222 (VRef _) -> v 223 (VList vs) -> VRef . arrayRef $ vs 224 _ -> VRef . scalarRef $ v 218 op1 "\\" = return . doCapture 219 where 220 doCapture :: Val -> Val 221 doCapture v@(VRef (MkRef IScalar{})) = VRef . scalarRef $ v 222 doCapture v@VRef{} = v 223 doCapture (VList vs) = VRef . arrayRef $ vs 224 doCapture v = VRef . scalarRef $ v 225 225 op1 "^" = op2RangeExclRight (VNum 0) 226 226 op1 "post:..." = op1Range … … 843 843 _ -> return undef 844 844 doGetLine :: VHandle -> IO (Maybe VStr) 845 doGetLine fh = guardIOexcept [(is IOError isEOFError, Nothing)] $ do845 doGetLine fh = guardIOexcept [(isEOFError, Nothing)] $ do 846 846 line <- hGetLine fh 847 847 return . Just . decodeUTF8 $ line 848 848 849 isIOError :: (IOError -> Bool) -> Exception -> Bool850 isIOError f err = case ioErrors err of851 Just ioe -> f ioe852 Nothing -> False853 854 849 op1Getc :: Val -> Eval Val 855 850 op1Getc = \v -> op1Read v (getChar) (getChar) 856 851 where 857 852 getChar :: VHandle -> Eval Val 858 getChar fh = guardIOexcept [(is IOError isEOFError, undef)] $ do853 getChar fh = guardIOexcept [(isEOFError, undef)] $ do 859 854 char <- hGetChar fh 860 855 str <- getChar' fh char
