blob: 1363120a46f634bf9aa6ce1df20f7950d28796c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
module Error where
import Data.List (sort)
import Text.Parsec (SourcePos, errorPos)
import Text.Parsec.Error (ParseError, errorMessages, showErrorMessages)
data Error
= TypeError String SourcePos
| UnexpectedReturn String SourcePos
| Error String SourcePos
deriving (Eq)
instance Show Error where
show (Error message pos) =
show pos ++ " error: " ++ message
-- XXX: can we do this differently?
show (TypeError message pos) =
show pos ++ " error: " ++ message
show (UnexpectedReturn message pos) =
show pos ++ " error: " ++ message
showParserError :: ParseError -> String
showParserError error =
show (errorPos error) ++ " error: syntax error"
++ showErrorMessages "or" "unknown parser error" " expecting" " unexpected" "end of input" (errorMessages error)
instance Ord Error where
compare (Error _ pos1) (Error _ pos2) = compare pos1 pos2
showErrorList :: [Error] -> String
showErrorList errs = unlines $ map show (sort errs)
|