2 % (c) The AQUA Project, Glasgow University, 1994-1995
4 \section[ErrsUtils]{Utilities for error reporting}
7 #include "HsVersions.h"
10 SYN_IE(Error), SYN_IE(Warning), SYN_IE(Message),
12 addShortErrLocLine, addShortWarnLocLine,
20 import Bag --( bagToList )
21 import PprStyle ( PprStyle(..) )
23 import SrcLoc ( noSrcLoc, SrcLoc{-instance-} )
24 #if __GLASGOW_HASKELL__ >= 202
30 type Error = PprStyle -> Doc
31 type Warning = PprStyle -> Doc
32 type Message = PprStyle -> Doc
34 addErrLoc :: SrcLoc -> String -> Error -> Error
35 addErrLoc locn title rest_of_err_msg sty
36 = hang (hcat [ppr PprForUser locn,
37 if null title then empty else text (": " ++ title),
39 4 (rest_of_err_msg sty)
41 addShortErrLocLine, addShortWarnLocLine :: SrcLoc -> Error -> Error
43 addShortErrLocLine locn rest_of_err_msg sty
44 = hang ((<>) (ppr PprForUser locn) (char ':'))
45 4 (rest_of_err_msg sty)
47 addShortWarnLocLine locn rest_of_err_msg sty
48 = hang ((<>) (ppr PprForUser locn) (ptext SLIT(":warning:")))
49 4 (rest_of_err_msg sty)
51 dontAddErrLoc :: String -> Error -> Error
52 dontAddErrLoc title rest_of_err_msg sty
53 = hang (hcat [text title, char ':'])
54 4 (rest_of_err_msg sty)
56 pprBagOfErrors :: PprStyle -> Bag Error -> Doc
57 pprBagOfErrors sty bag_of_errors
58 = let pretties = map ( \ e -> e sty ) (bagToList bag_of_errors) in
59 vcat (map (\ p -> ($$) space p) pretties)
63 ghcExit :: Int -> IO ()
67 then error "Compilation had errors\n"