on master help sign in
Make tabs error message better.
8d1e258Laszlo Pandy
src/Parse/Helpers.hs+1−6
@@ -348,15 +348,10 @@ failIfTabFound :: IParser ()
348failIfTabFound =
348failIfTabFound =
349 do foundTab <- option False (lookAhead (char '\t') >> return True) <?> Syntax.tab
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 Syntax.tab
352 else return ()
352 else return ()
353
353
354
354
355−tabsErrorMessage :: String
356−tabsErrorMessage =
357− "A tab character was found, but all whitespace (including indentation) must be spaces not tabs."
358−
359−
360-- Just eats whitespace until the next meaningful character.
355-- Just eats whitespace until the next meaningful character.
361dumbWhitespace :: IParser String
356dumbWhitespace :: IParser String
362dumbWhitespace =
357dumbWhitespace =
src/Reporting/Error/Syntax.hs+18−5
@@ -237,10 +237,18 @@ keyword kwd =
237 "KEYWORD=" ++ kwd
237 "KEYWORD=" ++ kwd
238
238
239
239
240−unkeyword :: String -> Maybe String
240+data SpecialMessage
241−unkeyword message =
241+ = MsgKeyword String
242+ | MsgTab
243+
244+
245+extractSpecialMessage :: String -> Maybe SpecialMessage
246+extractSpecialMessage message =
242 if List.isPrefixOf "KEYWORD=" message then
247 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
244
252
245 else
253 else
246 Nothing
254 Nothing
@@ -283,12 +291,17 @@ parseErrorReport messages =
283 (preHint, maybePost) =
291 (preHint, maybePost) =
284 case msgs of
292 case msgs of
285 [msg] ->
293 [msg] ->
286− case unkeyword msg of
294+ case extractSpecialMessage msg of
287− Just kwd ->
295+ Just (MsgKeyword kwd) ->
288 ( "It looks like the keyword `" ++ kwd ++ "` is being used as a variable."
296 ( "It looks like the keyword `" ++ kwd ++ "` is being used as a variable."
289 , Just "Rename it to something else."
297 , Just "Rename it to something else."
290 )
298 )
291
299
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+
292 Nothing ->
305 Nothing ->
293 ( msg
306 ( msg
294 , Nothing
307 , Nothing