@@ -327,13 +327,19 @@ spaces =
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)
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"
341+ ++ "You are either missing some stuff in the declaration above or just need to add\n"
342+ ++ "some spaces here:"
339-- Just eats whitespace until the next meaningful character.
345-- Just eats whitespace until the next meaningful character.
@@ -347,11 +353,21 @@ whitespace =
347 option "" forcedWS
353 option "" forcedWS
350−freshLine :: IParser [[String]]
356+freshLine :: IParser String
351freshLine =
357freshLine =
359+ do ws <- many1 (spaces <|> newline)
360+ column <- sourceColumn <$> getPosition
362+ then return (concat ws)
363+ else fail badFreshLineMessage
352− try (many1 newline >> many space_nl) <|> try (many1 space_nl) <?> Syntax.freshLine
364+ ) <?> Syntax.freshLine
354− space_nl = try $ spaces >> many1 newline
366+
367+badFreshLineMessage :: String
368+badFreshLineMessage =
369+ "I need a fresh line to start a new declaration. This means a new line that\n"
370+ ++ "starts with stuff, not with spaces or comments."
357newline :: IParser String
373newline :: IParser String