diff options
author | Juan J. Martinez <jjm@usebox.net> | 2022-08-15 12:11:10 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2022-08-15 12:11:10 +0100 |
commit | 60d8f688a0c66759bdb7645c9dd4c232bc433c9f (patch) | |
tree | c81394d00bf9825eae6c456ac6238e0f72bbe4ce /src/Error.hs | |
parent | cd4c8a3f1b92f0e6a585bd0b199374b8b99c6238 (diff) | |
download | micro-lang-hs-60d8f688a0c66759bdb7645c9dd4c232bc433c9f.tar.gz micro-lang-hs-60d8f688a0c66759bdb7645c9dd4c232bc433c9f.zip |
Unify error reporting
Diffstat (limited to 'src/Error.hs')
-rw-r--r-- | src/Error.hs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/Error.hs b/src/Error.hs index 96b02dc..f61cea2 100644 --- a/src/Error.hs +++ b/src/Error.hs @@ -1,13 +1,19 @@ module Error where import Data.List (sort) -import Text.Parsec (SourcePos) +import Text.Parsec (SourcePos, errorPos) +import Text.Parsec.Error (ParseError, errorMessages, showErrorMessages) data Error = Error String SourcePos deriving (Eq) instance Show Error where show (Error message pos) = - "error: " ++ show pos ++ ":\n" ++ message + 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 |