@@ -15,6 +15,8 @@ import qualified Text.Parser.Token as Tok
15import qualified Text.Parser.Char as Chr
15import qualified Text.Parser.Char as Chr
16import qualified Text.Parser.Token.Highlight as Hi
16import qualified Text.Parser.Token.Highlight as Hi
18+import Text.PrettyPrint.ANSI.Leijen (Doc, plain)
18import Idris.AbsSyntax
20import Idris.AbsSyntax
19import Idris.DSL
21import Idris.DSL
20import Idris.Imports
22import Idris.Imports
@@ -911,6 +913,13 @@ parseImports fname input
912 return ((mname, ps, mrk'), i)
914 return ((mname, ps, mrk'), i)
916+-- | There should be a better way of doing this...
917+findFC :: Doc -> (FC, String)
918+findFC x = let s = show (plain x) in
919+ case span (/= ':') s of
920+ (failname, ':':rest) -> case span isDigit rest of
921+ (line, ':':rest') -> (FC failname (read line) 0, drop 2 (dropWhile (/= ':') rest'))
914-- | A program is a list of declarations, possibly with associated
923-- | A program is a list of declarations, possibly with associated
915-- documentation strings.
924-- documentation strings.
916parseProg :: SyntaxInfo -> FilePath -> String -> Maybe Delta ->
925parseProg :: SyntaxInfo -> FilePath -> String -> Maybe Delta ->
@@ -919,10 +928,13 @@ parseProg syn fname input mrk
919 = do i <- getIState
928 = do i <- getIState
920 case runparser mainProg i fname input of
929 case runparser mainProg i fname input of
921 Failure doc -> do -- FIXME: Get error location from trifecta
930 Failure doc -> do -- FIXME: Get error location from trifecta
922− --let errl = sourceLine (errorPos err)
931+ -- this can't be the solution!
932+ let (fc, msg) = findFC doc
923 i <- getIState
933 i <- getIState
934+ case idris_outputmode i of
924− ihputStrLn (idris_outh i) (show doc)
935+ RawOutput -> ihputStrLn (idris_outh i) (show doc)
936+ IdeSlave n -> ihWarn (idris_outh i) fc msg
925− putIState (i { errLine = Just 0 }) -- Just errl })
937+ putIState (i { errLine = Just (fc_line fc) }) -- Just errl })
926 return []
938 return []
927 Success (x, i) -> do putIState i
939 Success (x, i) -> do putIState i
928 return $ collect x
940 return $ collect x
@@ -935,34 +947,40 @@ parseProg syn fname input mrk
935 i' <- get
947 i' <- get
936 return (ds, i')
948 return (ds, i')
938−{- | Load idris module -}
950+{- | Load idris module and show error if something wrong happens -}
939loadModule :: Handle -> FilePath -> Idris String
951loadModule :: Handle -> FilePath -> Idris String
940loadModule outh f
952loadModule outh f
941− = idrisCatch (do i <- getIState
953+ = idrisCatch (loadModule' outh f)
942− let file = takeWhile (/= ' ') f
943− ibcsd <- valIBCSubDir i
944− ids <- allImportDirs
945− fp <- liftIO $ findImport ids ibcsd file
946− if file `elem` imported i
947− then iLOG $ "Already read " ++ file
948− else do putIState (i { imported = file : imported i })
950− IDR fn -> loadSource outh False fn
951− LIDR fn -> loadSource outh True fn
953− idrisCatch (loadIBC fn)
954− (\c -> do iLOG $ fn ++ " failed " ++ show c
956− IDR sfn -> loadSource outh False sfn
957− LIDR sfn -> loadSource outh True sfn)
958− let (dir, fh) = splitFileName file
959− return (dropExtension fh))
960 (\e -> do setErrLine (getErrLine e)
954 (\e -> do setErrLine (getErrLine e)
961 ist <- getIState
955 ist <- getIState
962 msg <- showErr e
956 msg <- showErr e
963 ihputStrLn outh msg
957 ihputStrLn outh msg
964 return "")
958 return "")
960+{- | Load idris module -}
961+loadModule' :: Handle -> FilePath -> Idris String
964+ let file = takeWhile (/= ' ') f
965+ ibcsd <- valIBCSubDir i
966+ ids <- allImportDirs
967+ fp <- liftIO $ findImport ids ibcsd file
968+ if file `elem` imported i
969+ then iLOG $ "Already read " ++ file
970+ else do putIState (i { imported = file : imported i })
972+ IDR fn -> loadSource outh False fn
973+ LIDR fn -> loadSource outh True fn
975+ idrisCatch (loadIBC fn)
976+ (\c -> do iLOG $ fn ++ " failed " ++ show c
978+ IDR sfn -> loadSource outh False sfn
979+ LIDR sfn -> loadSource outh True sfn)
980+ let (dir, fh) = splitFileName file
981+ return (dropExtension fh)
966{- | Load idris code from file -}
984{- | Load idris code from file -}
967loadFromIFile :: Handle -> IFileType -> Idris ()
985loadFromIFile :: Handle -> IFileType -> Idris ()
968loadFromIFile h i@(IBC fn src)
986loadFromIFile h i@(IBC fn src)