on master help sign in
Make tabs error message better.
commit8d1e258f3bd6d1e96118ed3146431cdfad6bddf3 authorLaszlo Pandy <laszlo.pandy@prezi.com> dateWed 13 Jan 2016, 11:23 (11 years ago) parentebde691
2 files changed+19−11
src/Parse/Helpers.hs+1−6 src/Reporting/Error/Syntax.hs+18−5
src/Parse/Helpers.hs+1−6
@@ -348,15 +348,10 @@ failIfTabFound :: IParser ()
348348failIfTabFound =
349349 do foundTab <- option False (lookAhead (char '\t') >> return True) <?> Syntax.tab
350350 if foundTab
351− then fail tabsErrorMessage
351+ then fail Syntax.tab
352352 else return ()
353353
354354
355−tabsErrorMessage :: String
356−tabsErrorMessage =
357− "A tab character was found, but all whitespace (including indentation) must be spaces not tabs."
358−
359−
360355-- Just eats whitespace until the next meaningful character.
361356dumbWhitespace :: IParser String
362357dumbWhitespace =
src/Reporting/Error/Syntax.hs+18−5
@@ -237,10 +237,18 @@ keyword kwd =
237237 "KEYWORD=" ++ kwd
238238
239239
240−unkeyword :: String -> Maybe String
241−unkeyword message =
240+data SpecialMessage
241+ = MsgKeyword String
242+ | MsgTab
243+
244+
245+extractSpecialMessage :: String -> Maybe SpecialMessage
246+extractSpecialMessage message =
242247 if List.isPrefixOf "KEYWORD=" message then
243− Just (drop (length "KEYWORD=") message)
248+ Just $ MsgKeyword (drop (length "KEYWORD=") message)
249+
250+ else if tab == message then
251+ Just MsgTab
244252
245253 else
246254 Nothing
@@ -283,12 +291,17 @@ parseErrorReport messages =
283291 (preHint, maybePost) =
284292 case msgs of
285293 [msg] ->
286− case unkeyword msg of
287− Just kwd ->
294+ case extractSpecialMessage msg of
295+ Just (MsgKeyword kwd) ->
288296 ( "It looks like the keyword `" ++ kwd ++ "` is being used as a variable."
289297 , Just "Rename it to something else."
290298 )
291299
300+ Just MsgTab ->
301+ ( "A tab character was found, but all whitespace (including indentation) must be spaces not tabs."
302+ , Just "I am looking for spaces, not tabs."
303+ )
304+
292305 Nothing ->
293306 ( msg
294307 , Nothing