@@ -13,6 +13,7 @@ import Core.Constraints
13import System.Console.Haskeline
13import System.Console.Haskeline
14import System.Console.Haskeline.MonadException
14import System.Console.Haskeline.MonadException
15import Control.Monad.State
15import Control.Monad.State
16+import Control.Monad.Error (throwError, catchError)
16import System.IO.Error(isUserError, ioeGetErrorString)
17import System.IO.Error(isUserError, ioeGetErrorString)
17import Data.Char
18import Data.Char
18import Data.Typeable
19import Data.Typeable
@@ -21,42 +22,36 @@ iucheck :: Idris ()
21iucheck = do tit <- typeInType
22iucheck = do tit <- typeInType
22 when (not tit) $
23 when (not tit) $
23 do ist <- getIState
24 do ist <- getIState
24− idrisCatch (tclift $ ucheck (idris_constraints ist))
25+ (tclift $ ucheck (idris_constraints ist)) `idrisCatch`
25− (\e -> do let msg = show e
26− setErrLine (getErrLine msg)
26+ (\e -> do setErrLine (getErrLine e)
27− iputStrLn msg)
27+ iputStrLn (pshow ist e))
29+showErr :: Err -> Idris String
30+showErr e = getIState >>= return . flip pshow e
29report :: IOError -> String
33report :: IOError -> String
31 | isUserError e = ioeGetErrorString e
35 | isUserError e = ioeGetErrorString e
32 | otherwise = show e
36 | otherwise = show e
34−idrisCatch :: Idris a -> (SomeException -> Idris a) -> Idris a
38+--idrisCatch :: Idris a -> (SomeException -> Idris a) -> Idris a
35−idrisCatch = catch
39+--idrisCatch = catch
37−data IdrisErr = IErr String
41+idrisCatch :: Idris a -> (Err -> Idris a) -> Idris a
38− deriving Typeable
42+idrisCatch = catchError
40−instance Show IdrisErr where
43−instance Exception IdrisErr
45ifail :: String -> Idris ()
45ifail :: String -> Idris ()
46−ifail str = throwIO (IErr str)
46+ifail = throwError . Msg
48ierror :: Err -> Idris a
48ierror :: Err -> Idris a
49−ierror err = do i <- getIState
49+ierror = throwError
50− throwIO (IErr $ pshow i err)
52tclift :: TC a -> Idris a
51tclift :: TC a -> Idris a
53−tclift tc = case tc of
54− OK v -> return v
52+tclift (OK v) = return v
55− Error err -> do i <- getIState
57− At (FC f l) e -> setErrLine l
53+tclift (Error err@(At (FC f l) e)) = do setErrLine l ; throwError err
58− _ -> return ()
54+tclift (Error err) = throwError err
59− throwIO (IErr $ pshow i err)
61tctry :: TC a -> TC a -> Idris a
56tctry :: TC a -> TC a -> Idris a
62tctry tc1 tc2
57tctry tc1 tc2
@@ -64,10 +59,8 @@ tctry tc1 tc2
64 OK v -> return v
59 OK v -> return v
65 Error err -> tclift tc2
60 Error err -> tclift tc2
67−getErrLine str
62+getErrLine :: Err -> Int
68− = case span (/=':') str of
63+getErrLine (At (FC _ l) _) = l
69− (_, ':':rest) -> case span isDigit rest of
64+getErrLine _ = 0