on master help sign in
Add custom error message if tab character is found in parsing.
commite2775f72d07a7fd950f9adc1b141d7e4747aaa71 authorLaszlo Pandy <laszlo.pandy@prezi.com> dateSat 9 Jan 2016, 16:18 (11 years ago) parent29ab83c
1 file changed+16−1
src/Parse/Helpers.hs+16−1
src/Parse/Helpers.hs+16−1
@@ -327,7 +327,9 @@ spaces =
327327
328328forcedWS :: IParser String
329329forcedWS =
330− do ws <- many1 (spaces <|> newline)
330+ do failIfTabFound
331+ ws <- many1 (spaces <|> newline)
332+ failIfTabFound
331333 column <- sourceColumn <$> getPosition
332334 if column == 1
333335 then fail badWhiteSpaceMessage
@@ -342,6 +344,19 @@ badWhiteSpaceMessage =
342344 ++ "some spaces here:"
343345
344346
347+failIfTabFound :: IParser ()
348+failIfTabFound =
349+ do foundTab <- option False (lookAhead (char '\t') >> return True)
350+ if foundTab
351+ then fail tabsErrorMessage
352+ else return ()
353+
354+
355+tabsErrorMessage :: String
356+tabsErrorMessage =
357+ "A tab character was found, but all whitespace (including indentation) must be spaces not tabs."
358+
359+
345360-- Just eats whitespace until the next meaningful character.
346361dumbWhitespace :: IParser String
347362dumbWhitespace =