@@ -95,10 +95,10 @@ instance (a ~ Text) => IsString (Parser a) where
9595-- > where isDigit c = c >= '0' && c <= '9'
9696satisfy :: (Char -> Bool) -> Parser Char
9797satisfy p = do
98− c <- ensure 1
98+ (k,c) <- ensure 1
9999 let !h = T.unsafeHead c
100100 if p h
101− then advance 1 >> return h
101+ then advance k >> return h
102102 else fail "satisfy"
103103{-# INLINE satisfy #-}
104104
@@ -109,9 +109,9 @@ satisfy p = do
109109-- > where isDigit c = c >= '0' && c <= '9'
110110skip :: (Char -> Bool) -> Parser ()
111111skip p = do
112− s <- ensure 1
112+ (k,s) <- ensure 1
113113 if p (T.head s)
114− then advance 1
114+ then advance k
115115 else fail "skip"
116116
117117-- | The parser @satisfyWith f p@ transforms a character, and succeeds
@@ -119,10 +119,10 @@ skip p = do
119119-- parser returns the transformed character that was parsed.
120120satisfyWith :: (Char -> a) -> (a -> Bool) -> Parser a
121121satisfyWith f p = do
122− s <- ensure 1
122+ (k,s) <- ensure 1
123123 let c = f $! T.head s
124124 if p c
125− then advance 1 >> return c
125+ then advance k >> return c
126126 else fail "satisfyWith"
127127{-# INLINE satisfyWith #-}
128128
@@ -130,10 +130,10 @@ satisfyWith f p = do
130130-- predicate returns 'True'.
131131takeWith :: Int -> (Text -> Bool) -> Parser Text
132132takeWith n p = do
133− s <- ensure n
133+ (k,s) <- ensure n
134134 let h = T.take n s
135135 if p h
136− then advance n >> return h
136+ then advance k >> return h
137137 else fail "takeWith"
138138
139139-- | Consume exactly @n@ characters of input.
@@ -172,9 +172,9 @@ stringCI s = go 0
172172 go !n
173173 | n > T.length fs = fail "stringCI"
174174 | otherwise = do
175− t <- ensure n
175+ (k,t) <- ensure n
176176 if T.toCaseFold t == fs
177− then advance n >> return t
177+ then advance k >> return t
178178 else go (n+1)
179179 fs = T.toCaseFold s
180180{-# INLINE stringCI #-}
@@ -183,10 +183,10 @@ stringCI s = go 0
183183-- | Satisfy a literal string, ignoring case for characters in the ASCII range.
184184asciiCI :: Text -> Parser Text
185185asciiCI input = do
186− t <- ensure n
186+ (k,t) <- ensure n
187187 let h = T.take n t
188188 if asciiToLower h == s
189− then advance n >> return h
189+ then advance k >> return h
190190 else fail "asciiCI"
191191 where
192192 n = T.length input
@@ -397,7 +397,7 @@ peekChar = T.Parser $ \t pos more _lose succ ->
397397-- input, but will fail if end of input has been reached.
398398peekChar' :: Parser Char
399399peekChar' = do
400− s <- ensure 1
400+ (_,s) <- ensure 1
401401 return $! T.head s
402402{-# INLINE peekChar' #-}
403403
@@ -445,21 +445,21 @@ advance n = T.Parser $ \t pos more _lose succ ->
445445{-# INLINE advance #-}
446446
447447ensureSuspended :: Int -> Text -> Pos -> More
448− -> Failure r -> Success Text r
448+ -> Failure r -> Success (Int,Text) r
449449 -> Result r
450450ensureSuspended n t pos more lose succ =
451451 runParser (demandInput >> go) t pos more lose succ
452452 where go = T.Parser $ \t' pos' more' lose' succ' ->
453453 if lengthAtLeast pos' n t'
454− then succ' t' pos' more' (substring pos n t')
454+ then succ' t' pos' more' (n, substring pos n t')
455455 else runParser (demandInput >> go) t' pos' more' lose' succ'
456456
457457-- | If at least @n@ elements of input are available, return the
458458-- current input, otherwise fail.
459−ensure :: Int -> Parser Text
459+ensure :: Int -> Parser (Int, Text)
460460ensure n = T.Parser $ \t pos more lose succ ->
461461 if lengthAtLeast pos n t
462− then succ t pos more (substring pos n t)
462+ then succ t pos more (n, substring pos n t)
463463 -- The uncommon case is kept out-of-line to reduce code size:
464464 else ensureSuspended n t pos more lose succ
465465-- Non-recursive so the bounds check can be inlined: