Commits

wren romano committed f62513a

Added lookaheadWord8 and lookaheadChar.

Comments (0)

Files changed (3)

Data/Attoparsec.hs

     , I.word8
     , I.anyWord8
     , I.notWord8
+    , I.lookaheadWord8
     , I.satisfy
     , I.satisfyWith
     , I.skip

Data/Attoparsec/Char8.hs

     , char8
     , anyChar
     , notChar
+    , lookaheadChar
     , satisfy
 
     -- ** Special character parsers
 notChar c = satisfy (/= c) <?> "not " ++ [c]
 {-# INLINE notChar #-}
 
+-- | Return the next character, without consuming it.
+lookaheadChar :: Parser Char
+lookaheadChar = w2c <$> I.lookaheadWord8
+{-# INLINE lookaheadChar #-}
+
 -- | Match any character in a set.
 --
 -- >vowel = inClass "aeiou"

Data/Attoparsec/Internal.hs

     , skip
     , word8
     , notWord8
+    , lookaheadWord8
 
     -- ** Byte classes
     , inClass
 notWord8 c = satisfy (/= c) <?> "not " ++ show c
 {-# INLINE notWord8 #-}
 
+-- | Return the next byte, without consuming it.
+lookaheadWord8 :: Parser Word8
+lookaheadWord8 = B.unsafeHead <$> ensure 1
+{-# INLINE lookaheadWord8 #-}
+
 -- | Match only if all input has been consumed.
 endOfInput :: Parser ()
 endOfInput = Parser $ \i0 a0 m0 kf ks ->
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.