@@ -212,16 +212,45 @@ simpleNewline = try (string "\r\n") <|> string "\n"
212lineComment :: IParser String
212lineComment :: IParser String
213lineComment = do
213lineComment = do
214 try (string "--")
214 try (string "--")
215− comment <- manyTill anyChar $ simpleNewline <|> (eof >> return "\n")
215+ comment <- anyUntil $ simpleNewline <|> (eof >> return "\n")
216 return ("--" ++ comment)
216 return ("--" ++ comment)
218multiComment :: IParser String
218multiComment :: IParser String
219−multiComment = do { try (string "{-"); closeComment }
219+multiComment = (++) <$> try (string "{-") <*> closeComment
221closeComment :: IParser String
221closeComment :: IParser String
222−closeComment = do
222+closeComment =
223− comment <- manyTill anyChar . choice $
223+ anyUntil . choice $
224− [ try (string "-}") <?> "close comment"
224+ [ try (string "-}") <?> "close comment"
225− , do { try $ string "{-"; closeComment; closeComment }
225+ , concat <$> sequence [ try (string "{-"), closeComment, closeComment ]
228+anyUntil :: IParser String -> IParser String
231+ go = end <|> (:) <$> anyChar <*> go
233+anyThen :: IParser a -> IParser a
236+ ignore p = const () <$> p
237+ go = end <|> do ignore multiComment <|> ignore anyChar
240+withSource :: IParser a -> IParser (String, a)
242+ start <- getParserState
244+ endPos <- getPosition
245+ setParserState start
246+ raw <- anyUntilPos endPos
227− return ("{-" ++ comment ++ "-}")
247+ return (raw, result)
249+anyUntilPos :: SourcePos -> IParser String
252+ go = do currentPos <- getPosition
253+ case currentPos == pos of
255+ False -> (:) <$> anyChar <*> go