on master help sign in
Fix #1099, less backtracking and better errors for forcedWS
27e0addEvan Czaplicki
src/Parse/Helpers.hs+13−7
@@ -327,13 +327,19 @@ spaces =
327
327
328forcedWS :: IParser String
328forcedWS :: IParser String
329forcedWS =
329forcedWS =
330− choice
330+ do ws <- many1 (spaces <|> newline)
331− [ (++) <$> spaces <*> (concat <$> many nl_space)
331+ column <- sourceColumn <$> getPosition
332− , concat <$> many1 nl_space
332+ if column == 1
333− ]
333+ then fail badWhiteSpaceMessage
334− where
334+ else return (concat ws)
335− nl_space =
335+
336− try ((++) <$> (concat <$> many1 newline) <*> spaces)
336+
337+badWhiteSpaceMessage :: String
338+badWhiteSpaceMessage =
339+ "I need whitespace, but got stuck on what looks like a new declaration.\n"
340+ ++ "\n"
341+ ++ "You are either missing some stuff in the declaration above or just need to add\n"
342+ ++ "some spaces here:"
337
343
338
344
339-- Just eats whitespace until the next meaningful character.
345-- Just eats whitespace until the next meaningful character.