fastparser 0.3.1.2 → 0.3.2
raw patch · 3 files changed
+55/−33 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ ByteString.Parser.Fast: anyWord8 :: Parser Char
+ ByteString.Parser.Fast: dropN :: Int -> Parser ()
+ ByteString.Parser.Fast: word8 :: Word8 -> Parser ()
Files
- CHANGELOG.md +4/−0
- fastparser.cabal +1/−1
- src/ByteString/Parser/Fast.hs +50/−32
CHANGELOG.md view
@@ -1,3 +1,7 @@+v0.3.2++ * New functions: `dropN`, `anyWord8`, `word8`.+ v0.3.1.2 * Push bounds for the container package
fastparser.cabal view
@@ -1,5 +1,5 @@ name: fastparser-version: 0.3.1.2+version: 0.3.2 synopsis: A fast, but bare bones, bytestring parser combinators library. description: Please see README.md homepage: https://github.com/bartavelle/fastparser#readme
src/ByteString/Parser/Fast.hs view
@@ -1,17 +1,17 @@ -- | A fast parser combinators module.--- +-- -- This module is extremely bare-bones, and provides only very limited -- functionality. -- -- Sample usage:--- +-- -- > module Syslog where--- > +-- > -- > import ByteString.Parser.Fast -- > import qualified Data.ByteString as BS -- > import Data.Thyme.Clock -- > import Control.Applicative--- > +-- > -- > data SyslogMsg -- > = SyslogMsg -- > { _syslogPrio :: {-# UNPACK #-} !Int@@ -21,8 +21,8 @@ -- > , _syslogPID :: !(Maybe Int) -- > , _syslogData :: !BS.ByteString -- > } deriving (Show, Eq)--- > --- > +-- >+-- > -- > syslogMsg :: Parser SyslogMsg -- > syslogMsg = do -- > char '<'@@ -37,15 +37,15 @@ -- > char ':' -- > dt <- remaining -- > return (SyslogMsg prio ts host program pid' dt)--- > +-- > -- > test :: BS.ByteString -> Either ParseError SyslogMsg -- > test = parseOnly syslogMsg --+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE DeriveFunctor #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RankNTypes #-} module ByteString.Parser.Fast ( Parser, ParserM(..), parseOnly,@@ -54,9 +54,9 @@ -- * Parsing numerical values decimal, num, hnum, onum, frac, scientific, -- * Parsing characters- satisfy, anyChar, char, string, quotedString,+ satisfy, anyChar, char, anyWord8, word8, string, quotedString, -- * Various combinators- takeN, remaining, charTakeWhile, charTakeWhile1, ByteString.Parser.Fast.takeWhile, takeWhile1, skipWhile,+ takeN, dropN, remaining, charTakeWhile, charTakeWhile1, ByteString.Parser.Fast.takeWhile, takeWhile1, skipWhile, -- * Parsing time-related values parseYMD, parseDTime, timestamp, rfc3339, -- * Interfacing with other libraries@@ -65,22 +65,22 @@ isLower, getOctal, getInt ) where -import qualified Data.ByteString as BS-import qualified Data.ByteString.Char8 as BS8-import Data.Set (Set)-import qualified Data.Set as S-import Data.AffineSpace ((.-^), (.+^))-import Control.Applicative-import Control.Monad-import Data.Word-import Data.Thyme-import Data.Thyme.Time.Core-import Lens.Micro-import Data.Semigroup+import Control.Applicative+import Control.Monad+import Control.Monad.Codensity (Codensity, lowerCodensity)+import Control.Monad.Trans.Class (lift)+import Data.AffineSpace ((.+^), (.-^))+import qualified Data.ByteString as BS+import qualified Data.ByteString.Char8 as BS8 import qualified Data.ByteString.Lex.Fractional as L-import Control.Monad.Codensity (Codensity, lowerCodensity)-import Control.Monad.Trans.Class (lift)-import Prelude+import Data.Semigroup+import Data.Set (Set)+import qualified Data.Set as S+import Data.Thyme+import Data.Thyme.Time.Core+import Data.Word+import Lens.Micro+import Prelude -- | A parser, church encoded. The arguments to the wrapped function are: --@@ -163,7 +163,7 @@ -- [bytestring-lexing](https://hackage.haskell.org/package/bytestring-lexing) library. wlex :: (BS.ByteString -> Maybe (a, BS.ByteString)) -> Parser a wlex p = lift $ Parser $ \i failure success -> case p i of- Nothing -> failure mempty+ Nothing -> failure mempty Just (a, i') -> success i' a {-# INLINABLE wlex #-} @@ -237,15 +237,33 @@ else let (a,rest) = BS.splitAt n input in success rest a +-- | Drops n bytes of input+dropN :: Int -> Parser ()+dropN n = lift $ Parser $ \input failure success+ -> if BS.length input < n+ then failure ueof+ else success (BS.drop n input) ()+ -- | Parses any character. anyChar :: Parser Char anyChar = lift $ Parser $ \input failure success -> if BS.null input then failure ueof else success (BS8.tail input) (BS8.head input)+{-# INLINE anyChar #-} -- | Parses a specific character. char :: Char -> Parser () char c = lift $ Parser $ \input failure success -> if BS.null input then failure ueof else if BS8.head input == c then success (BS.tail input) () else failure (parseError (BS8.take 1 input) (BS8.singleton c)) {-# INLINE char #-} +-- | Parses any byte.+anyWord8 :: Parser Char+anyWord8 = lift $ Parser $ \input failure success -> if BS.null input then failure ueof else success (BS8.tail input) (BS8.head input)+{-# INLINE anyWord8 #-}++-- | Parses a specific byte.+word8 :: Word8 -> Parser ()+word8 c = lift $ Parser $ \input failure success -> if BS.null input then failure ueof else if BS.head input == c then success (BS.tail input) () else failure (parseError (BS.take 1 input) (BS.singleton c))+{-# INLINE word8 #-}+ -- | Parses a character satisfying a predicate satisfy :: (Char -> Bool) -> Parser Char satisfy p = lift $ Parser $ \input failure success ->@@ -365,8 +383,8 @@ !tz <- takeWhile1 isUpper return $! case tz of "CEST" -> tm .-^ fromSeconds (7200 :: Int)- "CET" -> tm .-^ fromSeconds (3600 :: Int)- _ -> tm+ "CET" -> tm .-^ fromSeconds (3600 :: Int)+ _ -> tm -- | Parses RFC3339 compatible timestamps to UTCTime. rfc3339 :: Parser UTCTime@@ -386,7 +404,7 @@ 'Z' -> return tm '+' -> suboffset <$> getOffset '-' -> addoffset <$> getOffset- _ -> empty+ _ -> empty -- | Turns any parser into a 'SimpleFold'. pFold :: Parser a -> SimpleFold BS.ByteString a