on df4ee4f help sign in
Idris-dev/src/Idris/Error.hs
41 lines 1.2 kB history raw
1module Idris.Error where
3import Idris.AbsSyntax
4import Idris.Delaborate
6import Core.TT
7import Core.Typecheck
9import Control.Monad.State
10import System.IO.Error
11import Data.Char
13report :: IOError -> String
14report e
15 | isUserError e = ioeGetErrorString e
16 | otherwise = show e
18-- Taken from the library source code - for ghc 6.12/7 compatibility
19liftCatch :: (m (a,s) -> (e -> m (a,s)) -> m (a,s)) ->
20 StateT s m a -> (e -> StateT s m a) -> StateT s m a
21liftCatch catchError m h =
22 StateT $ \s -> runStateT m s `catchError` \e -> runStateT (h e) s
24idrisCatch :: Idris a -> (IOError -> Idris a) -> Idris a
25idrisCatch op handler = liftCatch catch op handler
27tclift :: Show a => TC a -> Idris a
28tclift tc = case tc of
29 OK v -> return v
30 Error err -> do i <- get
31 case err of
32 At (FC f l) e -> setErrLine l
33 _ -> return ()
34 fail (pshow i err)
36getErrLine str
37 = case span (/=':') str of
38 (_, ':':rest) -> case span isDigit rest of
39 (num, _) -> read num
40 _ -> 0