packages feed

smith 0.1.0.0 → 0.1.1.0

raw patch · 3 files changed

+20/−2 lines, 3 filesdep ~primitivePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: primitive

API changes (from Hackage documentation)

+ Data.Parser: trySatisfy :: (a -> Bool) -> Parser a e s Bool

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for smith +## 0.1.1.0 -- 2020-01-20++* Add `trySatisfy`.+ ## 0.1.0.0 -- 2019-09-30  * First version. Released on an unsuspecting world.
smith.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: smith-version: 0.1.0.0+version: 0.1.1.0 synopsis: Parse arrays of tokens description:   This library is similar in spirit to `bytesmith`. While `bytesmith`
src/Data/Parser.hs view
@@ -30,6 +30,7 @@   , token   , effect   , fail+  , trySatisfy     -- * Control Flow   , foldSepBy1   , sepBy1@@ -62,7 +63,7 @@     let w = PM.indexSmallArray array off      in Success (Slice (off + 1) (len - 1) w) --- | Consume a character from the input or return @Nothing@ if+-- | Consume a token from the input or return @Nothing@ if -- end of the stream has been reached. This parser never fails. opt :: Parser a e s (Maybe a) {-# inline opt #-}@@ -71,6 +72,19 @@   _ ->      let w = PM.indexSmallArray array off      in Success (Slice (off + 1) (len - 1) (Just w))++-- | Looks at the next token from the input. If the token matches+-- the predicate, consume the token and return @True@. Otherwise,+-- do not consume the token and return @False@. If no tokens+-- remain in the input, return @False@. This parser never fails.+trySatisfy :: (a -> Bool) -> Parser a e s Bool+{-# inline trySatisfy #-}+trySatisfy p = uneffectful $ \array off len -> case len of+  0 -> Success (Slice off 0 False)+  _ -> let w = PM.indexSmallArray array off in+    case p w of+      True -> Success (Slice (off + 1) (len - 1) True)+      False -> Success (Slice off len False)  -- | Lift an effect into a parser. effect :: ST s b -> Parser a e s b