@@ -22,14 +22,13 @@ import Data.Monoid
22import Control.Monad.Error
22import Control.Monad.Error
24import Language.PureScript.Declarations
24import Language.PureScript.Declarations
25−import Language.PureScript.Options
26import Language.PureScript.Pretty
25import Language.PureScript.Pretty
27import Language.PureScript.Types
26import Language.PureScript.Types
30-- Type for sources of type checking errors
29-- Type for sources of type checking errors
32−data UnifyErrorSource
31+data ErrorSource
34 -- An error which originated at a Value
33 -- An error which originated at a Value
@@ -40,42 +39,41 @@ data UnifyErrorSource
40 | TypeError Type deriving (Show)
39 | TypeError Type deriving (Show)
43−-- Unification errors
42+-- Compilation errors
45−data UnifyError = UnifyError {
44+data CompileError = CompileError {
47 -- Error message
46 -- Error message
49− unifyErrorMessage :: String
48+ compileErrorMessage :: String
51 -- The value where the error occurred
50 -- The value where the error occurred
53− , unifyErrorValue :: Maybe UnifyErrorSource
52+ , compileErrorValue :: Maybe ErrorSource
55 -- Optional source position information
54 -- Optional source position information
57− , unifyErrorPosition :: Maybe SourcePos
56+ , compileErrorPosition :: Maybe SourcePos
58 } deriving (Show)
57 } deriving (Show)
61-- A stack trace for an error
60-- A stack trace for an error
63−newtype UnifyErrorStack = UnifyErrorStack { runUnifyErrorStack :: [UnifyError] } deriving (Show, Monoid)
62+newtype ErrorStack = ErrorStack { runUnifyErrorStack :: [CompileError] } deriving (Show, Monoid)
65−instance Error UnifyErrorStack where
64+instance Error ErrorStack where
66− strMsg s = UnifyErrorStack [UnifyError s Nothing Nothing]
65+ strMsg s = ErrorStack [CompileError s Nothing Nothing]
67− noMsg = UnifyErrorStack []
66+ noMsg = ErrorStack []
69−prettyPrintUnifyErrorStack :: Options -> UnifyErrorStack -> String
68+prettyPrintErrorStack :: Bool -> ErrorStack -> String
70−prettyPrintUnifyErrorStack opts (UnifyErrorStack es) =
69+prettyPrintErrorStack printAll (ErrorStack es) =
71− case mconcat $ map (Last . unifyErrorPosition) es of
70+ case mconcat $ map (Last . compileErrorPosition) es of
72 Last (Just sourcePos) -> "Error at " ++ show sourcePos ++ ": \n" ++ prettyPrintUnifyErrorStack'
71 Last (Just sourcePos) -> "Error at " ++ show sourcePos ++ ": \n" ++ prettyPrintUnifyErrorStack'
73 _ -> prettyPrintUnifyErrorStack'
72 _ -> prettyPrintUnifyErrorStack'
75 prettyPrintUnifyErrorStack' :: String
74 prettyPrintUnifyErrorStack' :: String
76 prettyPrintUnifyErrorStack'
75 prettyPrintUnifyErrorStack'
77− | optionsVerboseErrors opts =
78− intercalate "\n" (map showError (filter isErrorNonEmpty es))
76+ | printAll = intercalate "\n" (map showError (filter isErrorNonEmpty es))
79 | otherwise =
77 | otherwise =
81 es' = filter isErrorNonEmpty es
79 es' = filter isErrorNonEmpty es
@@ -83,16 +81,16 @@ prettyPrintUnifyErrorStack opts (UnifyErrorStack es) =
83 1 -> showError (head es')
81 1 -> showError (head es')
84 _ -> showError (head es') ++ "\n" ++ showError (last es')
82 _ -> showError (head es') ++ "\n" ++ showError (last es')
86−isErrorNonEmpty :: UnifyError -> Bool
84+isErrorNonEmpty :: CompileError -> Bool
87−isErrorNonEmpty = not . null . unifyErrorMessage
85+isErrorNonEmpty = not . null . compileErrorMessage
89−showError :: UnifyError -> String
87+showError :: CompileError -> String
90−showError (UnifyError msg Nothing _) = msg
88+showError (CompileError msg Nothing _) = msg
91−showError (UnifyError msg (Just (ValueError val)) _) = "Error in value " ++ prettyPrintValue val ++ "\n" ++ msg
89+showError (CompileError msg (Just (ValueError val)) _) = "Error in value " ++ prettyPrintValue val ++ "\n" ++ msg
92−showError (UnifyError msg (Just (TypeError ty)) _) = "Error in type " ++ prettyPrintType ty ++ "\n" ++ msg
90+showError (CompileError msg (Just (TypeError ty)) _) = "Error in type " ++ prettyPrintType ty ++ "\n" ++ msg
94−mkUnifyErrorStack :: String -> Maybe UnifyErrorSource -> UnifyErrorStack
92+mkUnifyErrorStack :: String -> Maybe ErrorSource -> ErrorStack
95−mkUnifyErrorStack msg t = UnifyErrorStack [UnifyError msg t Nothing]
93+mkUnifyErrorStack msg t = ErrorStack [CompileError msg t Nothing]
97−positionError :: SourcePos -> UnifyErrorStack
95+positionError :: SourcePos -> ErrorStack
98−positionError pos = UnifyErrorStack [UnifyError "" Nothing (Just pos)]
96+positionError pos = ErrorStack [CompileError "" Nothing (Just pos)]