From f989ff2d5d6da01d2c0ac70429c0a0bc5e207ff4 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 25 Jan 2013 18:32:06 -0800 Subject: Parsing: More improvements of anyLine parser. --- src/Text/Pandoc/Parsing.hs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs index 8fbcc54b4..0ab4c0694 100644 --- a/src/Text/Pandoc/Parsing.hs +++ b/src/Text/Pandoc/Parsing.hs @@ -195,12 +195,14 @@ anyLine = do -- manyTill anyChar newline inp <- getInput pos <- getPosition - let (this, rest) = break (=='\n') inp - setInput rest - let newpos = incSourceLine (setSourceColumn pos 0) 1 - setPosition newpos - void (char '\n') <|> (guard (not $ null this) >> eof) - return this + case break (=='\n') inp of + (this, '\n':rest) -> do + -- needed to persuade parsec that this won't match an empty string: + anyChar + setInput rest + setPosition $ incSourceLine (setSourceColumn pos 1) 1 + return this + _ -> mzero -- | Like @manyTill@, but reads at least one item. many1Till :: Parser [tok] st a -- cgit v1.2.3