Display errors instead of printing

This commit is contained in:
Chris Done 2019-11-25 15:33:09 +00:00
parent cfda673f1d
commit c8d85590c9
3 changed files with 42 additions and 17 deletions

View File

@ -15,6 +15,7 @@ import Control.Monad.Writer
import qualified Data.Map.Strict as M
import Data.Semigroup ((<>))
import Duet.Context
import Duet.Errors
import Duet.Infer
import Duet.Parser
import Duet.Printer
@ -108,20 +109,24 @@ runClassesPrint _ = do
runProgram :: Run -> IO ()
runProgram run@Run {..} = do
decls <- parseFile runInputFile
runNoLoggingT
(evalSupplyT
(do (binds, ctx) <- createContext decls
things <-
execWriterT
(runStepperIO
run
runSteps
ctx
(fmap (fmap typeSignatureA) binds)
runMainIs)
pure things)
[1 ..])
catch
(catch
(runNoLoggingT
(evalSupplyT
(do decls <- liftIO (parseFile runInputFile)
(binds, ctx) <- createContext decls
things <-
execWriterT
(runStepperIO
run
runSteps
ctx
(fmap (fmap typeSignatureA) binds)
runMainIs)
pure things)
[1 ..]))
(putStrLn . displayContextException))
(putStrLn . displayParseException)
-- | Run the substitution model on the code.
runStepperIO ::

View File

@ -4,15 +4,36 @@
module Duet.Errors where
import Control.Exception
import Data.Char
import Data.Function
import Data.List
import qualified Data.Map.Strict as M
import Data.Ord
import Data.Typeable
import Duet.Printer
import Duet.Types
import Text.EditDistance
displayContextException :: ContextException -> String
displayContextException (ContextException specialTypes (SomeException se)) =
maybe
(maybe
(maybe
(maybe
(maybe
(displayException se)
(displayRenamerException specialTypes)
(cast se))
(displayInferException specialTypes)
(cast se))
(displayStepperException specialTypes)
(cast se))
(displayResolveException specialTypes)
(cast se))
displayParseException
(cast se)
displayParseException :: ParseException -> String
displayParseException e =
case e of

View File

@ -217,9 +217,8 @@ data RenamerException
deriving (Show, Generic, Data, Typeable, Typeable)
instance Exception RenamerException
data ContextException = ContextException (SpecialTypes Name) RenamerException
deriving (Show, Generic, Data, Typeable, Typeable)
data ContextException = ContextException (SpecialTypes Name) SomeException
deriving (Show, Generic, Typeable)
instance Exception ContextException
-- | An exception that may be thrown when reading in source code,