Commits

Bryan O'Sullivan committed 67de518

Add a skip combinator.

  • Participants
  • Parent commits d3a337f

Comments (0)

Files changed (3)

File Data/Attoparsec.hs

     , I.notWord8
     , I.satisfy
     , I.satisfyWith
+    , I.skip
 
     -- ** Byte classes
     , I.inClass

File Data/Attoparsec/Internal.hs

     , satisfy
     , satisfyWith
     , anyWord8
+    , skip
     , word8
     , notWord8
 
     then put (B.unsafeTail s) >> return w
     else fail "satisfy"
 
+-- | The parser @skip p@ succeeds for any byte for which the predicate
+-- @p@ returns 'True'.
+--
+-- >digit = satisfy isDigit
+-- >    where isDigit w = w >= 48 && w <= 57
+skip :: (Word8 -> Bool) -> Parser ()
+skip p = do
+  ensure 1
+  s <- get
+  if p (B.unsafeHead s)
+    then put (B.unsafeTail s)
+    else fail "skip"
+
 -- | The parser @satisfyWith f p@ transforms a byte, and succeeds if
 -- the predicate @p@ returns 'True' on the transformed value. The
 -- parser returns the transformed byte that was parsed.

File attoparsec.cabal

 name:            attoparsec
-version:         0.8.0.2
+version:         0.8.1.0
 license:         BSD3
 license-file:    LICENSE
 category:        Text, Parsing