summaryrefslogtreecommitdiff
path: root/compiler/parser/Lexer.x
diff options
context:
space:
mode:
authorsimonmar@microsoft.com <unknown>2006-06-01 11:53:06 +0000
committersimonmar@microsoft.com <unknown>2006-06-01 11:53:06 +0000
commit77452bc2888f3fd071774b1177868e95f85a43dc (patch)
tree28a8537662598707c4ac24c491453c800372455c /compiler/parser/Lexer.x
parent543a890b3de87c2535072c894035996661bf106c (diff)
downloadhaskell-77452bc2888f3fd071774b1177868e95f85a43dc.tar.gz
improvements to lexical error reporting
Diffstat (limited to 'compiler/parser/Lexer.x')
-rw-r--r--compiler/parser/Lexer.x10
1 files changed, 4 insertions, 6 deletions
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x
index 5015ca7059..f6863c6286 100644
--- a/compiler/parser/Lexer.x
+++ b/compiler/parser/Lexer.x
@@ -1445,15 +1445,13 @@ lexToken = do
span `seq` setLastToken span bytes
t span buf bytes
--- ToDo: Alex reports the buffer at the start of the erroneous lexeme,
--- but it would be more informative to report the location where the
--- error was actually discovered, especially if this is a decoding
--- error.
-reportLexError loc1 loc2 buf str =
+reportLexError loc1 loc2 buf str
+ | atEnd buf = failLocMsgP loc1 loc2 (str ++ " at end of input")
+ | otherwise =
let
c = fst (nextChar buf)
in
if c == '\0' -- decoding errors are mapped to '\0', see utf8DecodeChar#
- then failLocMsgP loc2 loc2 "UTF-8 decoding error"
+ then failLocMsgP loc2 loc2 (str ++ " (UTF-8 decoding error)")
else failLocMsgP loc1 loc2 (str ++ " at character " ++ show c)
}