on master help sign in
Improve whitespace error message: don't say we expect tabs
commitebde6919893d3eac4e12cb08567f016ea3ce4b5f authorLaszlo Pandy <laszlo.pandy@prezi.com> dateWed 13 Jan 2016, 10:52 (11 years ago) parente2775f7
2 files changed+11−2
src/Parse/Helpers.hs+1−1 src/Reporting/Error/Syntax.hs+10−1
src/Parse/Helpers.hs+1−1
@@ -346,7 +346,7 @@ badWhiteSpaceMessage =
346346
347347failIfTabFound :: IParser ()
348348failIfTabFound =
349− do foundTab <- option False (lookAhead (char '\t') >> return True)
349+ do foundTab <- option False (lookAhead (char '\t') >> return True) <?> Syntax.tab
350350 if foundTab
351351 then fail tabsErrorMessage
352352 else return ()
src/Reporting/Error/Syntax.hs+10−1
@@ -228,6 +228,10 @@ whitespace :: String
228228whitespace = "WHITESPACE"
229229
230230
231+tab :: String
232+tab = "TAB"
233+
234+
231235keyword :: String -> String
232236keyword kwd =
233237 "KEYWORD=" ++ kwd
@@ -263,7 +267,12 @@ parseErrorReport messages =
263267 else
264268 msg
265269 in
266− hint { _expected = Set.insert msg' (_expected hint) }
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
275+ hint { _expected = Set.insert msg' (_expected hint) }
267276
268277 Parsec.Message msg ->
269278 hint { _messages = msg : _messages hint }