packages feed

flatparse 0.4.0.0 → 0.4.0.1

raw patch · 9 files changed

+26/−92 lines, 9 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- FlatParse.Common.Strings: isAsciiLetter :: Char -> Bool
- FlatParse.Common.Strings: isDigit :: Char -> Bool
- FlatParse.Common.Strings: isGreekLetter :: Char -> Bool
- FlatParse.Common.Strings: packBytes :: [Word] -> Word
- FlatParse.Common.Strings: splitBytes :: [Word] -> ([Word], [Word])
- FlatParse.Common.Strings: word16ToInt16 :: Word16 -> Int16
- FlatParse.Common.Strings: word32ToInt32 :: Word32 -> Int32
- FlatParse.Common.Strings: word64ToInt64 :: Word64 -> Int64
+ FlatParse.Basic: isDigit :: Char -> Bool
+ FlatParse.Basic: isGreekLetter :: Char -> Bool
+ FlatParse.Basic: isLatinLetter :: Char -> Bool
+ FlatParse.Stateful: isDigit :: Char -> Bool
+ FlatParse.Stateful: isGreekLetter :: Char -> Bool
+ FlatParse.Stateful: isLatinLetter :: Char -> Bool

Files

bench/FPBasic.hs view
@@ -5,7 +5,6 @@   , runNumcsv) where  import FlatParse.Basic-import FlatParse.Common.Assorted  ws, open, close, ident, sexp, src :: Parser () () ws      = skipMany $(switch [| case _ of " " -> pure (); "\n" -> pure () |])
bench/FPStateful.hs view
@@ -5,7 +5,6 @@   , runNumcsv) where  import FlatParse.Stateful-import FlatParse.Common.Assorted  ws, open, close, ident, sexp, src :: Parser () () () ws      = skipMany $(switch [| case _ of " " -> pure (); "\n" -> pure () |])
flatparse.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           flatparse-version:        0.4.0.0+version:        0.4.0.1 synopsis:       High-performance parsing from strict bytestrings description:    @Flatparse@ is a high-performance parsing library for strict bytestring input. See the README for more information:                 <https://github.com/AndrasKovacs/flatparse>.@@ -57,7 +57,6 @@       FlatParse.Common.Numbers       FlatParse.Common.Parser       FlatParse.Common.Position-      FlatParse.Common.Strings       FlatParse.Common.Switch       FlatParse.Examples.BasicLambda.Lexer       FlatParse.Examples.BasicLambda.Parser
src/FlatParse/Basic.hs view
@@ -35,6 +35,11 @@   , Common.strToUtf8   , Common.utf8ToStr +  -- * Character predicates+  , Common.isDigit+  , Common.isLatinLetter+  , Common.isGreekLetter+   -- * Parsers   -- ** Bytewise   , FP.Base.eof@@ -229,12 +234,12 @@ runParserUtf8 :: Parser e a -> String -> Result e a runParserUtf8 pa s = runParser pa (Common.strToUtf8 s) --- | Run an ST based parser.+-- | Run an `ST`-based parser. runParserST :: (forall s. ParserST s e a) -> B.ByteString -> Result e a runParserST pst buf = unsafeDupablePerformIO (runParserIO pst buf) {-# inlinable runParserST #-} --- | Run an IO based parser.+-- | Run an `IO`-based parser. runParserIO :: ParserIO e a -> B.ByteString -> IO (Result e a) runParserIO (ParserT f) b@(B.PS (ForeignPtr _ fp) _ (I# len)) = do   B.unsafeUseAsCString b \(Ptr buf) -> do
− src/FlatParse/Common/Strings.hs
@@ -1,69 +0,0 @@-module FlatParse.Common.Strings where--import Data.Bits-import Data.Foldable (foldl')--import Data.Word-import Data.Int--import qualified Data.Char---- | @isDigit c = \'0\' <= c && c <= \'9\'@--- TODO exists in Data.Char, but maybe loses inlining-isDigit :: Char -> Bool---isDigit c = '0' <= c && c <= '9'-isDigit = Data.Char.isDigit-{-# inline isDigit #-}---- | @isAsciiLetter c = (\'A\' <= c && c <= \'Z\') || (\'a\' <= c && c <= \'z\')@--- TODO exists in Data.Char, but maybe loses inlining-isAsciiLetter :: Char -> Bool---isAsciiLetter c = ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')-isAsciiLetter c = Data.Char.isAsciiUpper c || Data.Char.isAsciiLower c-{-# inline isAsciiLetter #-}---- | @isGreekLetter c = (\'Α\' <= c && c <= \'Ω\') || (\'α\' <= c && c <= \'ω\')@-isGreekLetter :: Char -> Bool-isGreekLetter c = ('Α' <= c && c <= 'Ω') || ('α' <= c && c <= 'ω')-{-# inline isGreekLetter #-}---- UTF conversions-----------------------------------------------------------------------------------packBytes :: [Word] -> Word-packBytes = fst . foldl' go (0, 0) where-  go (acc, shift) w | shift == 64 = error "packWords: too many bytes"-  go (acc, shift) w = (unsafeShiftL (fromIntegral w) shift .|. acc, shift+8)---- TODO chunks into 8-bytes for 64-bit performance-splitBytes :: [Word] -> ([Word], [Word])-splitBytes ws = case quotRem (length ws) 8 of-  (0, _) -> (ws, [])-  (_, r) -> (as, chunk8s bs) where-              (as, bs) = splitAt r ws-              chunk8s [] = []-              chunk8s ws = let (as, bs) = splitAt 8 ws in-                           packBytes as : chunk8s bs------------------------------------------------------------------------------------{- $boxed-integer-coercion--These functions should be no-ops. They correspond to the similarly-named GHC 9.4-primops which work on unboxed integers.--}---- | Coerce a 'Word16' to 'Int16'.-word16ToInt16 :: Word16 -> Int16-word16ToInt16 = fromIntegral-{-# inline word16ToInt16 #-}---- | Coerce a 'Word32' to 'Int32'.-word32ToInt32 :: Word32 -> Int32-word32ToInt32 = fromIntegral-{-# inline word32ToInt32 #-}---- | Coerce a 'Word64' to 'Int64'.-word64ToInt64 :: Word64 -> Int64-word64ToInt64 = fromIntegral-{-# inline word64ToInt64 #-}
src/FlatParse/Examples/BasicLambda/Lexer.hs view
@@ -9,7 +9,6 @@ module FlatParse.Examples.BasicLambda.Lexer where  import FlatParse.Basic hiding (Parser, runParser, string, char, cut)-import FlatParse.Common.Strings  import qualified FlatParse.Basic as FP import qualified Data.ByteString as B@@ -152,12 +151,12 @@  -- | Read a starting character of an identifier. identStartChar :: Parser Char-identStartChar = satisfyAscii isAsciiLetter+identStartChar = satisfyAscii isLatinLetter {-# inline identStartChar #-}  -- | Read a non-starting character of an identifier. identChar :: Parser Char-identChar = satisfyAscii (\c -> isAsciiLetter c || isDigit c)+identChar = satisfyAscii (\c -> isLatinLetter c || isDigit c) {-# inline identChar #-}  -- | Check whether a `Span` contains exactly a keyword. Does not change parsing state.
src/FlatParse/Examples/BasicLambda/Parser.hs view
@@ -12,7 +12,6 @@ import qualified Data.ByteString as B  import FlatParse.Basic hiding (Parser, runParser, string, char, cut)-import FlatParse.Common.Strings import FlatParse.Examples.BasicLambda.Lexer  --------------------------------------------------------------------------------
src/FlatParse/Stateful.hs view
@@ -44,6 +44,11 @@   , Common.strToUtf8   , Common.utf8ToStr +  -- * Character predicates+  , Common.isDigit+  , Common.isLatinLetter+  , Common.isGreekLetter+   -- * Parsers   -- ** Bytewise   , FP.Base.eof@@ -237,12 +242,12 @@ runParserUtf8 :: Parser r e a -> r -> Int -> String -> Result e a runParserUtf8 pa r !n s = runParser pa r n (Common.strToUtf8 s) --- | Run an ST-based parser. The `Int` argument is the initial state.+-- | Run an `ST`-based parser. The `Int` argument is the initial state. runParserST :: (forall s. ParserST s r e a) -> r -> Int -> B.ByteString -> Result e a runParserST pst !r i buf = unsafeDupablePerformIO (runParserIO pst r i buf) {-# inlinable runParserST #-} --- | Run an IO-based parser. The `Int` argument is the initial state.+-- | Run an `IO`-based parser. The `Int` argument is the initial state. runParserIO :: ParserIO r e a -> r -> Int -> B.ByteString -> IO (Result e a) runParserIO (ParserT f) !r (I# n) b@(B.PS (ForeignPtr _ fp) _ (I# len)) = do   B.unsafeUseAsCString b \(Ptr buf) -> do
test/Test.hs view
@@ -7,8 +7,6 @@ import qualified Data.ByteString as B import qualified Data.Char import qualified FlatParse.Basic as FB-import qualified FlatParse.Common.Strings as FB--- import qualified FlatParse.Stateful as FS import Test.HUnit import Test.Hspec import Test.Hspec.QuickCheck@@ -397,7 +395,7 @@       it "agrees with Data.Char" $         property $           \c ->-            FB.isAsciiLetter c+            FB.isLatinLetter c               === (Data.Char.isAsciiUpper c || Data.Char.isAsciiLower c)      describe "anyAsciiDecimalInt" $ do@@ -568,33 +566,33 @@      describe "many" $ do       it "parses many chars" $-        FB.many (FB.satisfy FB.isAsciiLetter) `shouldParseWith` ("abc", "abc")+        FB.many (FB.satisfy FB.isLatinLetter) `shouldParseWith` ("abc", "abc")       it "accepts FB.empty input" $-        FB.many (FB.satisfy FB.isAsciiLetter) `shouldParseWith` ("", "")+        FB.many (FB.satisfy FB.isLatinLetter) `shouldParseWith` ("", "")       it "is greedy" $         (FB.many (FB.satisfy FB.isDigit) *> FB.satisfy FB.isDigit) `shouldParseFail` "123"      describe "skipMany" $ do       it "parses many chars" $-        FB.skipMany (FB.satisfy FB.isAsciiLetter) `shouldParseWith` ("abc", ())+        FB.skipMany (FB.satisfy FB.isLatinLetter) `shouldParseWith` ("abc", ())       it "accepts FB.empty input" $-        FB.skipMany (FB.satisfy FB.isAsciiLetter) `shouldParseWith` ("", ())+        FB.skipMany (FB.satisfy FB.isLatinLetter) `shouldParseWith` ("", ())       it "is greedy" $         (FB.skipMany (FB.satisfy FB.isDigit) *> FB.satisfy FB.isDigit) `shouldParseFail` "123"      describe "some" $ do       it "parses some chars" $-        FB.some (FB.satisfy FB.isAsciiLetter) `shouldParseWith` ("abc", "abc")+        FB.some (FB.satisfy FB.isLatinLetter) `shouldParseWith` ("abc", "abc")       it "rejects FB.empty input" $-        FB.some (FB.satisfy FB.isAsciiLetter) `shouldParseFail` ""+        FB.some (FB.satisfy FB.isLatinLetter) `shouldParseFail` ""       it "is greedy" $         (FB.some (FB.satisfy FB.isDigit) *> FB.satisfy FB.isDigit) `shouldParseFail` "123"      describe "skipSome" $ do       it "parses some chars" $-        FB.skipSome (FB.satisfy FB.isAsciiLetter) `shouldParseWith` ("abc", ())+        FB.skipSome (FB.satisfy FB.isLatinLetter) `shouldParseWith` ("abc", ())       it "rejects FB.empty input" $-        FB.skipSome (FB.satisfy FB.isAsciiLetter) `shouldParseFail` ""+        FB.skipSome (FB.satisfy FB.isLatinLetter) `shouldParseFail` ""       it "is greedy" $         (FB.skipSome (FB.satisfy FB.isDigit) *> FB.satisfy FB.isDigit) `shouldParseFail` "123"