aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-11-14 07:49:32 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2019-11-14 07:49:32 -0800
commitdb6e9de091d02a5d36893aa1ef9708afb85da588 (patch)
tree6001dfc36c0162017b58fde0ad01fd6578aa86a2 /src/Text
parenta60eb60a3dc8bf03ea8ae23fad3f3ebff124a8e1 (diff)
downloadpandoc-db6e9de091d02a5d36893aa1ef9708afb85da588.tar.gz
Parsing: Rename takeWhileP -> take1WhileP and clean it up.
(It doesn't match the empty sequence.)
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Parsing.hs20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index f56b13b66..17f6a7562 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -21,7 +21,7 @@
A utility library with parsers used in pandoc readers.
-}
-module Text.Pandoc.Parsing ( takeWhileP,
+module Text.Pandoc.Parsing ( take1WhileP,
takeP,
countChar,
textStr,
@@ -264,19 +264,21 @@ textStr :: Stream s m Char => Text -> ParsecT s u m Text
textStr t = string (T.unpack t) $> t
-- | Parse characters while a predicate is true.
-takeWhileP :: Monad m
+take1WhileP :: Monad m
=> (Char -> Bool)
-> ParserT Text st m Text
-takeWhileP f = do
- -- faster than 'many (satisfy f)'
+take1WhileP f = do
+ -- needed to persuade parsec that this won't match an empty string:
+ c <- satisfy f
inp <- getInput
pos <- getPosition
- let (xs, rest) = T.span f inp
- -- needed to persuade parsec that this won't match an empty string:
- anyChar
+ let (t, rest) = T.span f inp
setInput rest
- setPosition $ updatePosString pos $ T.unpack xs
- return xs
+ setPosition $
+ if f '\t' || f '\n'
+ then updatePosString pos $ T.unpack t
+ else incSourceColumn pos (T.length t)
+ return $ T.singleton c <> t
-- Parse n characters of input (or the rest of the input if
-- there aren't n characters).