on master help sign in
Improve whitespace error message: don't say we expect tabs
ebde691Laszlo Pandy
src/Parse/Helpers.hs+1−1
@@ -346,7 +346,7 @@ badWhiteSpaceMessage =
346
346
347failIfTabFound :: IParser ()
347failIfTabFound :: IParser ()
348failIfTabFound =
348failIfTabFound =
349− do foundTab <- option False (lookAhead (char '\t') >> return True)
349+ do foundTab <- option False (lookAhead (char '\t') >> return True) <?> Syntax.tab
350 if foundTab
350 if foundTab
351 then fail tabsErrorMessage
351 then fail tabsErrorMessage
352 else return ()
352 else return ()
src/Reporting/Error/Syntax.hs+10−1
@@ -228,6 +228,10 @@ whitespace :: String
228whitespace = "WHITESPACE"
228whitespace = "WHITESPACE"
229
229
230
230
231+tab :: String
232+tab = "TAB"
233+
234+
231keyword :: String -> String
235keyword :: String -> String
232keyword kwd =
236keyword kwd =
233 "KEYWORD=" ++ kwd
237 "KEYWORD=" ++ kwd
@@ -263,7 +267,12 @@ parseErrorReport messages =
263 else
267 else
264 msg
268 msg
265 in
269 in
270+ if msg == tab then
271+ -- Our parser looks for tab so it can throw a custom tab error message.
272+ -- Exclude tabs from the list of expected tokens so that no one thinks they are supported.
273+ hint
274+ else
266− hint { _expected = Set.insert msg' (_expected hint) }
275+ hint { _expected = Set.insert msg' (_expected hint) }
267
276
268 Parsec.Message msg ->
277 Parsec.Message msg ->
269 hint { _messages = msg : _messages hint }
278 hint { _messages = msg : _messages hint }