@@ -35,7 +35,10 @@ module Data.Attoparsec.Text.Internal
3535 , skip
3636 , char
3737 , notChar
38+
39+ -- ** Lookahead
3840 , peekChar
41+ , peekChar'
3942
4043 -- ** Character classes
4144 , inClass
@@ -440,8 +443,8 @@ notChar :: Char -> Parser Char
440443notChar c = satisfy (/= c) <?> "not " ++ show c
441444{-# INLINE notChar #-}
442445
443−-- | Match any character. Returns 'Nothing' if end of input has been
444−-- reached. Does not consume any input.
446+-- | Match any character, to perform lookahead. Returns 'Nothing' if
447+-- end of input has been reached. Does not consume any input.
445448--
446449-- /Note/: Because this parser does not fail, do not use it with
447450-- combinators such as 'many', because such parsers loop until a
@@ -459,6 +462,14 @@ peekChar = T.Parser $ \i0 a0 m0 _kf ks ->
459462 in ks i0 a0 m0 (Just c)
460463{-# INLINE peekChar #-}
461464
465+-- | Match any character, to perform lookahead. Does not consume any
466+-- input, but will fail if end of input has been reached.
467+peekChar' :: Parser Char
468+peekChar' = do
469+ s <- ensure 1
470+ return $! unsafeHead s
471+{-# INLINE peekChar' #-}
472+
462473-- | Match only if all input has been consumed.
463474endOfInput :: Parser ()
464475endOfInput = T.Parser $ \i0 a0 m0 kf ks ->