git.iko.soy/typeable/attoparsec
on 2fb688a help sign in
39 files changed+207−831
since splitsnapshots
unifiedsplit
.gitignore−1 .hgtags−4 .travis.yml−161 Data/Attoparsec/ByteString.hs−1 Data/Attoparsec/ByteString/Buffer.hs+8−10 Data/Attoparsec/ByteString/Char8.hs+5−4 Data/Attoparsec/ByteString/Internal.hs+16−30 Data/Attoparsec/Combinator.hs+3−2 Data/Attoparsec/Internal.hs+1−13 Data/Attoparsec/Internal/Types.hs+28−38 Data/Attoparsec/Text.hs+2−3 Data/Attoparsec/Text/Buffer.hs+8−12 Data/Attoparsec/Text/FastSet.hs+1−3 Data/Attoparsec/Text/Internal.hs+21−31 Data/Attoparsec/Zepto.hs+43−81 README.markdown+6 attoparsec.cabal+11−53 benchmarks/Aeson.hs+2−6 benchmarks/Benchmarks.hs−6 benchmarks/HeadersByteString.hs+1−10 benchmarks/HeadersByteString/Atto.hs+1−9 benchmarks/Links.hs+2−2 benchmarks/Numbers.hs−1 benchmarks/Sets.hs−21 benchmarks/TextFastSet.hs−121 benchmarks/attoparsec-benchmarks.cabal−4 benchmarks/http-request.txt+8−3 benchmarks/http-response.txt+4−2 benchmarks/warp-3.0.1.1/Network/Wai/Handler/Warp/RequestHeader.hs+1−1 changelog.md−35 tests/QC.hs+2−2 tests/QC/Buffer.hs+4−4 tests/QC/ByteString.hs+9−25 tests/QC/Combinator.hs+5−7 tests/QC/Common.hs+4−27 tests/QC/Simple.hs+3−3 tests/QC/Text.hs+8−26 tests/QC/Text/FastSet.hs−15 tests/QC/Text/Regressions.hs−54
.gitignore−1
@@ -3,4 +3,3 @@
33/dist/
44.cabal-sandbox
55cabal.sandbox.config
6−*.sw[op]
.hgtags−4
@@ -57,7 +57,3 @@ c9c2b05707b2fffcd749d5817e3e0d04e6ad6d0d 0.12.1.0
5757682ba515f7ba62500ad79371b37b90932e0c0e3d 0.12.1.2
58582066a72b79b478f59a9c7f1839c522fc59ba9af7 0.12.1.3
5959ef875ad3bebef2b6fb1bd7063de6a46a06d0d4b4 0.12.1.4
60−dc1fcff28d13a508f677c7b06af6420877842493 0.12.1.5
61−013e04e4526bfd5e9e4a611b42e6f03c413bea91 0.12.1.6
62−0ddbce995b77b8db391b4d6519f13feddf4b5bf3 0.13.0.0
63−46c16463ec20ad46c9cd0bfb1050c4268f34b749 0.13.0.1
.travis.ymldeleted−161
@@ -1,161 +0,0 @@
1−# This Travis job script has been generated by a script via
2−#
3−# haskell-ci '--tests-jobs=>=7.4' '--no-benchmarks' 'attoparsec.cabal'
4−#
5−# For more information, see https://github.com/haskell-CI/haskell-ci
6−#
7−# version: 0.3.20190815
8−#
9−language: c
10−dist: xenial
11−git:
12− # whether to recursively clone submodules
13− submodules: false
14−cache:
15− directories:
16− - $HOME/.cabal/packages
17− - $HOME/.cabal/store
18−before_cache:
19− - rm -fv $CABALHOME/packages/hackage.haskell.org/build-reports.log
20− # remove files that are regenerated by 'cabal update'
21− - rm -fv $CABALHOME/packages/hackage.haskell.org/00-index.*
22− - rm -fv $CABALHOME/packages/hackage.haskell.org/*.json
23− - rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.cache
24− - rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.tar
25− - rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.tar.idx
26− - rm -rfv $CABALHOME/packages/head.hackage
27−matrix:
28− include:
29− - compiler: ghc-8.8.1
30− addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.8.1","cabal-install-3.0"]}}
31− - compiler: ghc-8.6.5
32− addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.6.5","cabal-install-2.4"]}}
33− - compiler: ghc-8.4.4
34− addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.4.4","cabal-install-2.4"]}}
35− - compiler: ghc-8.2.2
36− addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.2.2","cabal-install-2.4"]}}
37− - compiler: ghc-8.0.2
38− addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.0.2","cabal-install-2.4"]}}
39− - compiler: ghc-7.10.3
40− addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-7.10.3","cabal-install-2.4"]}}
41− - compiler: ghc-7.8.4
42− addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-7.8.4","cabal-install-2.4"]}}
43− - compiler: ghc-7.6.3
44− addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-7.6.3","cabal-install-2.4"]}}
45− - compiler: ghc-7.4.2
46− addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-7.4.2","cabal-install-2.4"]}}
47− - compiler: ghc-7.2.2
48− addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-7.2.2","cabal-install-2.4"]}}
49− - compiler: ghc-7.0.4
50− addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-7.0.4","cabal-install-2.4"]}}
51−before_install:
52− - HC=$(echo "/opt/$CC/bin/ghc" | sed 's/-/\//')
53− - WITHCOMPILER="-w $HC"
54− - HCPKG="$HC-pkg"
55− - unset CC
56− - CABAL=/opt/ghc/bin/cabal
57− - CABALHOME=$HOME/.cabal
58− - export PATH="$CABALHOME/bin:$PATH"
59− - TOP=$(pwd)
60− - "HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\\d+)\\.(\\d+)\\.(\\d+)(\\.(\\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')"
61− - echo $HCNUMVER
62− - CABAL="$CABAL -vnormal+nowrap+markoutput"
63− - set -o pipefail
64− - |
65− echo 'function blue(s) { printf "\033[0;34m" s "\033[0m " }' >> .colorful.awk
66− echo 'BEGIN { state = "output"; }' >> .colorful.awk
67− echo '/^-----BEGIN CABAL OUTPUT-----$/ { state = "cabal" }' >> .colorful.awk
68− echo '/^-----END CABAL OUTPUT-----$/ { state = "output" }' >> .colorful.awk
69− echo '!/^(-----BEGIN CABAL OUTPUT-----|-----END CABAL OUTPUT-----)/ {' >> .colorful.awk
70− echo ' if (state == "cabal") {' >> .colorful.awk
71− echo ' print blue($0)' >> .colorful.awk
72− echo ' } else {' >> .colorful.awk
73− echo ' print $0' >> .colorful.awk
74− echo ' }' >> .colorful.awk
75− echo '}' >> .colorful.awk
76− - cat .colorful.awk
77− - |
78− color_cabal_output () {
79− awk -f $TOP/.colorful.awk
80− }
81− - echo text | color_cabal_output
82−install:
83− - ${CABAL} --version
84− - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
85− - TEST=--enable-tests
86− - if [ $HCNUMVER -lt 70400 ] ; then TEST=--disable-tests ; fi
87− - BENCH=--enable-benchmarks
88− - BENCH=--disable-benchmarks
89− - HEADHACKAGE=false
90− - rm -f $CABALHOME/config
91− - |
92− echo "verbose: normal +nowrap +markoutput" >> $CABALHOME/config
93− echo "remote-build-reporting: anonymous" >> $CABALHOME/config
94− echo "write-ghc-environment-files: always" >> $CABALHOME/config
95− echo "remote-repo-cache: $CABALHOME/packages" >> $CABALHOME/config
96− echo "logs-dir: $CABALHOME/logs" >> $CABALHOME/config
97− echo "world-file: $CABALHOME/world" >> $CABALHOME/config
98− echo "extra-prog-path: $CABALHOME/bin" >> $CABALHOME/config
99− echo "symlink-bindir: $CABALHOME/bin" >> $CABALHOME/config
100− echo "installdir: $CABALHOME/bin" >> $CABALHOME/config
101− echo "build-summary: $CABALHOME/logs/build.log" >> $CABALHOME/config
102− echo "store-dir: $CABALHOME/store" >> $CABALHOME/config
103− echo "install-dirs user" >> $CABALHOME/config
104− echo " prefix: $CABALHOME" >> $CABALHOME/config
105− echo "repository hackage.haskell.org" >> $CABALHOME/config
106− echo " url: http://hackage.haskell.org/" >> $CABALHOME/config
107− - cat $CABALHOME/config
108− - rm -fv cabal.project cabal.project.local cabal.project.freeze
109− - travis_retry ${CABAL} v2-update -v
110− # Generate cabal.project
111− - rm -rf cabal.project cabal.project.local cabal.project.freeze
112− - touch cabal.project
113− - |
114− echo "packages: ." >> cabal.project
115− - |
116− - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(attoparsec)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
117− - cat cabal.project || true
118− - cat cabal.project.local || true
119− - if [ -f "./configure.ac" ]; then (cd "." && autoreconf -i); fi
120− - ${CABAL} v2-freeze $WITHCOMPILER ${TEST} ${BENCH} | color_cabal_output
121− - "cat cabal.project.freeze | sed -E 's/^(constraints: *| *)//' | sed 's/any.//'"
122− - rm cabal.project.freeze
123− - ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} --dep -j2 all | color_cabal_output
124− - ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks --dep -j2 all | color_cabal_output
125−script:
126− - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)
127− # Packaging...
128− - ${CABAL} v2-sdist all | color_cabal_output
129− # Unpacking...
130− - mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/
131− - cd ${DISTDIR} || false
132− - find . -maxdepth 1 -type f -name '*.tar.gz' -exec tar -xvf '{}' \;
133− - find . -maxdepth 1 -type f -name '*.tar.gz' -exec rm '{}' \;
134− - PKGDIR_attoparsec="$(find . -maxdepth 1 -type d -regex '.*/attoparsec-[0-9.]*')"
135− # Generate cabal.project
136− - rm -rf cabal.project cabal.project.local cabal.project.freeze
137− - touch cabal.project
138− - |
139− echo "packages: ${PKGDIR_attoparsec}" >> cabal.project
140− - |
141− - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(attoparsec)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
142− - cat cabal.project || true
143− - cat cabal.project.local || true
144− # Building...
145− # this builds all libraries and executables (without tests/benchmarks)
146− - ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks all | color_cabal_output
147− # Building with tests and benchmarks...
148− # build & run tests, build benchmarks
149− - ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output
150− # Testing...
151− - if [ $HCNUMVER -ge 70400 ] ; then ${CABAL} v2-test $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output ; fi
152− # cabal check...
153− - (cd ${PKGDIR_attoparsec} && ${CABAL} -vnormal check)
154− # haddock...
155− - ${CABAL} v2-haddock $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output
156− # Building without installed constraints for packages in global-db...
157− - rm -f cabal.project.local
158− - ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks all | color_cabal_output
159−
160−# REGENDATA ["--tests-jobs=>=7.4","--no-benchmarks","attoparsec.cabal"]
161−# EOF
Data/Attoparsec/ByteString.hs−1
@@ -63,7 +63,6 @@ module Data.Attoparsec.ByteString
6363 , I.skipWhile
6464 , I.take
6565 , I.scan
66− , I.runScanner
6766 , I.takeWhile
6867 , I.takeWhile1
6968 , I.takeTill
Data/Attoparsec/ByteString/Buffer.hs+8−10
@@ -1,4 +1,4 @@
1−{-# LANGUAGE BangPatterns #-}
1+{-# LANGUAGE BangPatterns, CPP #-}
22-- |
33-- Module : Data.Attoparsec.ByteString.Buffer
44-- Copyright : Bryan O'Sullivan 2007-2015
@@ -57,8 +57,9 @@ import Control.Exception (assert)
5757import Data.ByteString.Internal (ByteString(..), memcpy, nullForeignPtr)
5858import Data.Attoparsec.Internal.Fhthagn (inlinePerformIO)
5959import Data.List (foldl1')
60−import Data.Monoid as Mon (Monoid(..))
61−import Data.Semigroup (Semigroup(..))
60+#if !MIN_VERSION_base(4,8,0)
61+import Data.Monoid (Monoid(..))
62+#endif
6263import Data.Word (Word8)
6364import Foreign.ForeignPtr (ForeignPtr, withForeignPtr)
6465import Foreign.Ptr (castPtr, plusPtr)
@@ -87,17 +88,14 @@ buffer (PS fp off len) = Buf fp off len len 0
8788unbuffer :: Buffer -> ByteString
8889unbuffer (Buf fp off len _ _) = PS fp off len
8990
90−instance Semigroup Buffer where
91− (Buf _ _ _ 0 _) <> b = b
92− a <> (Buf _ _ _ 0 _) = a
93− buf <> (Buf fp off len _ _) = append buf fp off len
94−
9591instance Monoid Buffer where
9692 mempty = Buf nullForeignPtr 0 0 0 0
9793
98− mappend = (<>)
94+ mappend (Buf _ _ _ 0 _) b = b
95+ mappend a (Buf _ _ _ 0 _) = a
96+ mappend buf (Buf fp off len _ _) = append buf fp off len
9997
100− mconcat [] = Mon.mempty
98+ mconcat [] = mempty
10199 mconcat xs = foldl1' mappend xs
102100
103101pappend :: Buffer -> ByteString -> Buffer
Data/Attoparsec/ByteString/Char8.hs+5−4
@@ -128,10 +128,10 @@ module Data.Attoparsec.ByteString.Char8
128128 ) where
129129
130130#if !MIN_VERSION_base(4,8,0)
131−import Control.Applicative (pure, (*>), (<*), (<$>))
131+import Control.Applicative (pure, (*>), (<*))
132132import Data.Word (Word)
133133#endif
134−import Control.Applicative ((<|>))
134+import Control.Applicative ((<$>), (<|>))
135135import Control.Monad (void, when)
136136import Data.Attoparsec.ByteString.FastSet (charClass, memberChar)
137137import Data.Attoparsec.ByteString.Internal (Parser)
@@ -444,8 +444,9 @@ hexadecimal = B8.foldl' step 0 `fmap` I.takeWhile1 isHexDigit
444444
445445-- | Parse and decode an unsigned decimal number.
446446decimal :: Integral a => Parser a
447−decimal = B8.foldl' step 0 `fmap` I.takeWhile1 isDigit_w8
448− where step a w = a * 10 + fromIntegral (w - 48)
447+decimal = B8.foldl' step 0 `fmap` I.takeWhile1 isDig
448+ where isDig w = w >= 48 && w <= 57
449+ step a w = a * 10 + fromIntegral (w - 48)
449450{-# SPECIALISE decimal :: Parser Int #-}
450451{-# SPECIALISE decimal :: Parser Int8 #-}
451452{-# SPECIALISE decimal :: Parser Int16 #-}
Data/Attoparsec/ByteString/Internal.hs+16−30
@@ -1,5 +1,4 @@
1−{-# LANGUAGE BangPatterns, CPP, GADTs, OverloadedStrings, RankNTypes,
2− RecordWildCards #-}
1+{-# LANGUAGE BangPatterns, GADTs, OverloadedStrings, RankNTypes, RecordWildCards #-}
32-- |
43-- Module : Data.Attoparsec.ByteString.Internal
54-- Copyright : Bryan O'Sullivan 2007-2015
@@ -66,10 +65,7 @@ module Data.Attoparsec.ByteString.Internal
6665 , atEnd
6766 ) where
6867
69−#if !MIN_VERSION_base(4,8,0)
70−import Control.Applicative ((<$>))
71−#endif
72−import Control.Applicative ((<|>))
68+import Control.Applicative ((<|>), (<$>))
7369import Control.Monad (when)
7470import Data.Attoparsec.ByteString.Buffer (Buffer, buffer)
7571import Data.Attoparsec.ByteString.FastSet (charClass, memberWord8)
@@ -190,12 +186,11 @@ string_ suspended f s0 = T.Parser $ \t pos more lose succ ->
190186 let n = B.length s
191187 s = f s0
192188 in if lengthAtLeast pos n t
193− then let t' = substring pos (Pos n) t
194− in if s == f t'
195− then succ t (pos + Pos n) more t'
196− else lose t pos more [] "string"
189+ then if s == substring pos (Pos n) t
190+ then succ t (pos + Pos n) more s
191+ else lose t pos more [] "string"
197192 else let t' = Buf.unsafeDrop (fromPos pos) t
198− in if f t' `B.isPrefixOf` s
193+ in if t' `B.isPrefixOf` s
199194 then suspended s (B.drop (B.length t') s) t pos more lose succ
200195 else lose t pos more [] "string"
201196{-# INLINE string_ #-}
@@ -213,9 +208,7 @@ stringSuspended f s0 s t pos more lose succ =
213208 n = B.length s'
214209 in if n >= m
215210 then if B.unsafeTake m s' == s
216− then let o = Pos (B.length s0)
217− in succ' t' (pos' + o) more'
218− (substring pos' o t')
211+ then succ' t' (pos' + Pos (B.length s0)) more' s0
219212 else lose' t' pos' more' [] "string"
220213 else if s' == B.unsafeTake n s
221214 then stringSuspended f s0 (B.unsafeDrop n s)
@@ -257,24 +250,15 @@ takeTill p = takeWhile (not . p)
257250-- parsers loop until a failure occurs. Careless use will thus result
258251-- in an infinite loop.
259252takeWhile :: (Word8 -> Bool) -> Parser ByteString
260−takeWhile p = do
261− s <- B8.takeWhile p <$> get
262− continue <- inputSpansChunks (B.length s)
263− if continue
264− then takeWhileAcc p [s]
265− else return s
266−{-# INLINE takeWhile #-}
267−
268−takeWhileAcc :: (Word8 -> Bool) -> [ByteString] -> Parser ByteString
269−takeWhileAcc p = go
253+takeWhile p = (B.concat . reverse) `fmap` go []
270254 where
271255 go acc = do
272256 s <- B8.takeWhile p <$> get
273257 continue <- inputSpansChunks (B.length s)
274258 if continue
275259 then go (s:acc)
276− else return $ concatReverse (s:acc)
277−{-# INLINE takeWhileAcc #-}
260+ else return (s:acc)
261+{-# INLINE takeWhile #-}
278262
279263takeRest :: Parser [ByteString]
280264takeRest = go []
@@ -338,13 +322,16 @@ scan_ f s0 p = go [] s0
338322-- parsers loop until a failure occurs. Careless use will thus result
339323-- in an infinite loop.
340324scan :: s -> (s -> Word8 -> Maybe s) -> Parser ByteString
341−scan = scan_ $ \_ chunks -> return $! concatReverse chunks
325+scan = scan_ $ \_ chunks ->
326+ case chunks of
327+ [x] -> return x
328+ xs -> return $! B.concat $ reverse xs
342329{-# INLINE scan #-}
343330
344331-- | Like 'scan', but generalized to return the final state of the
345332-- scanner.
346333runScanner :: s -> (s -> Word8 -> Maybe s) -> Parser (ByteString, s)
347−runScanner = scan_ $ \s xs -> let !sx = concatReverse xs in return (sx, s)
334+runScanner = scan_ $ \s xs -> return (B.concat (reverse xs), s)
348335{-# INLINE runScanner #-}
349336
350337-- | Consume input as long as the predicate returns 'True', and return
@@ -364,9 +351,8 @@ takeWhile1 p = do
364351 advance len
365352 eoc <- endOfChunk
366353 if eoc
367− then takeWhileAcc p [s]
354+ then (s<>) `fmap` takeWhile p
368355 else return s
369−{-# INLINE takeWhile1 #-}
370356
371357-- | Match any byte in a set.
372358--
Data/Attoparsec/Combinator.hs+3−2
@@ -40,10 +40,11 @@ module Data.Attoparsec.Combinator
4040 ) where
4141
4242#if !MIN_VERSION_base(4,8,0)
43−import Control.Applicative (Applicative(..), (<$>))
43+import Control.Applicative (Applicative(..))
4444import Data.Monoid (Monoid(mappend))
4545#endif
46−import Control.Applicative (Alternative(..), empty, liftA2, many, (<|>))
46+import Control.Applicative (Alternative(..), empty, liftA2, many, (<|>),
47+ (<$>))
4748import Control.Monad (MonadPlus(..))
4849import Data.Attoparsec.Internal.Types (Parser(..), IResult(..))
4950import Data.Attoparsec.Internal (endOfInput, atEnd, satisfyElem)
Data/Attoparsec/Internal.hs+1−13
@@ -1,4 +1,4 @@
1−{-# LANGUAGE BangPatterns, CPP, ScopedTypeVariables #-}
1+{-# LANGUAGE BangPatterns, ScopedTypeVariables #-}
22-- |
33-- Module : Data.Attoparsec.Internal
44-- Copyright : Bryan O'Sullivan 2007-2015
@@ -20,13 +20,9 @@ module Data.Attoparsec.Internal
2020 , endOfInput
2121 , atEnd
2222 , satisfyElem
23− , concatReverse
2423 ) where
2524
26−#if !MIN_VERSION_base(4,8,0)
2725import Control.Applicative ((<$>))
28−import Data.Monoid (Monoid, mconcat)
29−#endif
3026import Data.Attoparsec.Internal.Types
3127import Data.ByteString (ByteString)
3228import Data.Text (Text)
@@ -161,11 +157,3 @@ satisfyElem p = Parser $ \t pos more lose succ ->
161157 | otherwise -> lose t pos more [] "satisfyElem"
162158 Nothing -> satisfySuspended p t pos more lose succ
163159{-# INLINE satisfyElem #-}
164−
165−-- | Concatenate a monoid after reversing its elements. Used to
166−-- glue together a series of textual chunks that have been accumulated
167−-- \"backwards\".
168−concatReverse :: Monoid m => [m] -> m
169−concatReverse [x] = x
170−concatReverse xs = mconcat (reverse xs)
171−{-# INLINE concatReverse #-}
Data/Attoparsec/Internal/Types.hs+28−38
@@ -1,4 +1,4 @@
1−{-# LANGUAGE CPP, BangPatterns, GeneralizedNewtypeDeriving, OverloadedStrings,
1+{-# LANGUAGE BangPatterns, CPP, GeneralizedNewtypeDeriving, OverloadedStrings,
22 Rank2Types, RecordWildCards, TypeFamilies #-}
33-- |
44-- Module : Data.Attoparsec.Internal.Types
@@ -25,13 +25,13 @@ module Data.Attoparsec.Internal.Types
2525 , Chunk(..)
2626 ) where
2727
28−import Control.Applicative as App (Applicative(..), (<$>))
29−import Control.Applicative (Alternative(..))
28+#if !MIN_VERSION_base(4,8,0)
29+import Control.Applicative (Applicative(..))
30+import Data.Monoid (Monoid(..))
31+#endif
32+import Control.Applicative (Alternative(..), (<$>))
3033import Control.DeepSeq (NFData(rnf))
3134import Control.Monad (MonadPlus(..))
32−import qualified Control.Monad.Fail as Fail (MonadFail(..))
33−import Data.Monoid as Mon (Monoid(..))
34−import Data.Semigroup (Semigroup(..))
3535import Data.Word (Word8)
3636import Data.ByteString (ByteString)
3737import qualified Data.ByteString as BS
@@ -39,7 +39,7 @@ import Data.ByteString.Internal (w2c)
3939import Data.Text (Text)
4040import qualified Data.Text as Text
4141import Data.Text.Unsafe (Iter(..))
42−import Prelude hiding (succ)
42+import Prelude hiding (getChar, succ)
4343import qualified Data.Attoparsec.ByteString.Buffer as B
4444import qualified Data.Attoparsec.Text.Buffer as T
4545
@@ -127,21 +127,17 @@ type Success i t a r = t -> Pos -> More -> a -> IResult i r
127127data More = Complete | Incomplete
128128 deriving (Eq, Show)
129129
130−instance Semigroup More where
131− c@Complete <> _ = c
132− _ <> m = m
133−
134−instance Mon.Monoid More where
135− mappend = (<>)
136− mempty = Incomplete
130+instance Monoid More where
131+ mappend c@Complete _ = c
132+ mappend _ m = m
133+ mempty = Incomplete
137134
138135instance Monad (Parser i) where
139−#if !(MIN_VERSION_base(4,13,0))
140− fail = Fail.fail
136+ fail err = Parser $ \t pos more lose _succ -> lose t pos more [] msg
137+ where msg = "Failed reading: " ++ err
141138 {-# INLINE fail #-}
142−#endif
143139
144− return = App.pure
140+ return v = Parser $ \t pos more _lose succ -> succ t pos more v
145141 {-# INLINE return #-}
146142
147143 m >>= k = Parser $ \t !pos more lose succ ->
@@ -149,15 +145,6 @@ instance Monad (Parser i) where
149145 in runParser m t pos more lose succ'
150146 {-# INLINE (>>=) #-}
151147
152− (>>) = (*>)
153− {-# INLINE (>>) #-}
154−
155−
156−instance Fail.MonadFail (Parser i) where
157− fail err = Parser $ \t pos more lose _succ -> lose t pos more [] msg
158− where msg = "Failed reading: " ++ err
159− {-# INLINE fail #-}
160−
161148plus :: Parser i a -> Parser i a -> Parser i a
162149plus f g = Parser $ \t pos more lose succ ->
163150 let lose' t' _pos' more' _ctx _msg = runParser g t' pos more' lose succ
@@ -182,23 +169,23 @@ apP d e = do
182169{-# INLINE apP #-}
183170
184171instance Applicative (Parser i) where
185− pure v = Parser $ \t !pos more _lose succ -> succ t pos more v
172+ pure = return
186173 {-# INLINE pure #-}
187174 (<*>) = apP
188175 {-# INLINE (<*>) #-}
189− m *> k = m >>= \_ -> k
176+
177+ -- These definitions are equal to the defaults, but this
178+ -- way the optimizer doesn't have to work so hard to figure
179+ -- that out.
180+ (*>) = (>>)
190181 {-# INLINE (*>) #-}
191− x <* y = x >>= \a -> y >> pure a
182+ x <* y = x >>= \a -> y >> return a
192183 {-# INLINE (<*) #-}
193184
194−instance Semigroup (Parser i a) where
195− (<>) = plus
196− {-# INLINE (<>) #-}
197−
198185instance Monoid (Parser i a) where
199186 mempty = fail "mempty"
200187 {-# INLINE mempty #-}
201− mappend = (<>)
188+ mappend = plus
202189 {-# INLINE mappend #-}
203190
204191instance Alternative (Parser i) where
@@ -209,9 +196,8 @@ instance Alternative (Parser i) where
209196 {-# INLINE (<|>) #-}
210197
211198 many v = many_v
212− where
213− many_v = some_v <|> pure []
214− some_v = (:) <$> v <*> many_v
199+ where many_v = some_v <|> pure []
200+ some_v = (:) <$> v <*> many_v
215201 {-# INLINE many #-}
216202
217203 some v = some_v
@@ -220,6 +206,10 @@ instance Alternative (Parser i) where
220206 some_v = (:) <$> v <*> many_v
221207 {-# INLINE some #-}
222208
209+(<>) :: (Monoid m) => m -> m -> m
210+(<>) = mappend
211+{-# INLINE (<>) #-}
212+
223213-- | A common interface for input chunks.
224214class Monoid c => Chunk c where
225215 type ChunkElem c
Data/Attoparsec/Text.hs+2−3
@@ -72,7 +72,6 @@ module Data.Attoparsec.Text
7272 , skipSpace
7373 , I.skipWhile
7474 , I.scan
75− , I.runScanner
7675 , I.take
7776 , I.takeWhile
7877 , I.takeWhile1
@@ -127,10 +126,10 @@ module Data.Attoparsec.Text
127126 ) where
128127
129128#if !MIN_VERSION_base(4,8,0)
130−import Control.Applicative (pure, (*>), (<*), (<$>))
129+import Control.Applicative (pure, (*>), (<*))
131130import Data.Word (Word)
132131#endif
133−import Control.Applicative ((<|>))
132+import Control.Applicative ((<$>), (<|>))
134133import Data.Attoparsec.Combinator
135134import Data.Attoparsec.Number (Number(..))
136135import Data.Scientific (Scientific)
Data/Attoparsec/Text/Buffer.hs+8−12
@@ -40,8 +40,9 @@ module Data.Attoparsec.Text.Buffer
4040import Control.Exception (assert)
4141import Data.Bits (shiftR)
4242import Data.List (foldl1')
43−import Data.Monoid as Mon (Monoid(..))
44−import Data.Semigroup (Semigroup(..))
43+#if !MIN_VERSION_base(4,8,0)
44+import Data.Monoid (Monoid(..))
45+#endif
4546import Data.Text ()
4647import Data.Text.Internal (Text(..))
4748import Data.Text.Internal.Encoding.Utf16 (chr2)
@@ -79,20 +80,15 @@ unbufferAt s (Buf arr off len _ _) =
7980 assert (s >= 0 && s <= len) $
8081 Text arr (off+s) (len-s)
8182
82−instance Semigroup Buffer where
83− (Buf _ _ _ 0 _) <> b = b
84− a <> (Buf _ _ _ 0 _) = a
85− buf <> (Buf arr off len _ _) = append buf arr off len
86− {-# INLINE (<>) #-}
87−
8883instance Monoid Buffer where
8984 mempty = Buf A.empty 0 0 0 0
90− {-# INLINE mempty #-}
9185
92− mappend = (<>)
86+ mappend (Buf _ _ _ 0 _) b = b
87+ mappend a (Buf _ _ _ 0 _) = a
88+ mappend buf (Buf arr off len _ _) = append buf arr off len
9389
94− mconcat [] = Mon.mempty
95− mconcat xs = foldl1' (<>) xs
90+ mconcat [] = mempty
91+ mconcat xs = foldl1' mappend xs
9692
9793pappend :: Buffer -> Text -> Buffer
9894pappend (Buf _ _ _ 0 _) t = buffer t
Data/Attoparsec/Text/FastSet.hs+1−3
@@ -62,9 +62,7 @@ resolveCollisions (a:b:entries) = a' : resolveCollisions (b' : entries)
6262
6363pad :: Int -> [Entry] -> [Entry]
6464pad = go 0
65− where -- ensure that we pad enough so that lookups beyond the
66− -- last hash in the table fall within the array
67− go !_ !m [] = replicate (max 1 m + 1) empty
65+ where go !_ !m [] = replicate (max 1 m) empty
6866 go k m (e:entries) = map (const empty) [k..i - 1] ++ e :
6967 go (i + 1) (m + i - k - 1) entries
7068 where i = index e
Data/Attoparsec/Text/Internal.hs+21−31
@@ -65,14 +65,14 @@ module Data.Attoparsec.Text.Internal
6565 , atEnd
6666 ) where
6767
68−import Control.Applicative ((<|>), (<$>), pure, (*>))
68+import Control.Applicative ((<|>), (<$>))
6969import Control.Monad (when)
7070import Data.Attoparsec.Combinator ((<?>))
7171import Data.Attoparsec.Internal
7272import Data.Attoparsec.Internal.Types hiding (Parser, Failure, Success)
7373import qualified Data.Attoparsec.Text.Buffer as Buf
7474import Data.Attoparsec.Text.Buffer (Buffer, buffer)
75−import Data.Char (isAsciiUpper, isAsciiLower, toUpper, toLower)
75+import Data.Char (chr, ord)
7676import Data.List (intercalate)
7777import Data.String (IsString(..))
7878import Data.Text.Internal (Text(..))
@@ -222,16 +222,15 @@ stringCI s = go 0
222222
223223-- | Satisfy a literal string, ignoring case for characters in the ASCII range.
224224asciiCI :: Text -> Parser Text
225−asciiCI s = fmap fst $ match $ T.foldr ((*>) . asciiCharCI) (pure ()) s
225+asciiCI s = string_ (stringSuspended asciiToLower) asciiToLower s
226+ where
227+ asciiToLower = T.map f
228+ where
229+ offset = ord 'a' - ord 'A'
230+ f c | 'A' <= c && c <= 'Z' = chr (ord c + offset)
231+ | otherwise = c
226232{-# INLINE asciiCI #-}
227233
228−asciiCharCI :: Char -> Parser Char
229−asciiCharCI c
230− | isAsciiUpper c = char c <|> char (toLower c)
231− | isAsciiLower c = char c <|> char (toUpper c)
232− | otherwise = char c
233−{-# INLINE asciiCharCI #-}
234−
235234-- | Skip past input for as long as the predicate returns 'True'.
236235skipWhile :: (Char -> Bool) -> Parser ()
237236skipWhile p = go
@@ -267,25 +266,14 @@ takeTill p = takeWhile (not . p)
267266-- parsers loop until a failure occurs. Careless use will thus result
268267-- in an infinite loop.
269268takeWhile :: (Char -> Bool) -> Parser Text
270−takeWhile p = do
271− h <- T.takeWhile p <$> get
272− continue <- inputSpansChunks (size h)
273− -- only use slow concat path if necessary
274− if continue
275− then takeWhileAcc p [h]
276− else return h
277−{-# INLINE takeWhile #-}
278−
279−takeWhileAcc :: (Char -> Bool) -> [Text] -> Parser Text
280−takeWhileAcc p = go
269+takeWhile p = (T.concat . reverse) `fmap` go []
281270 where
282271 go acc = do
283272 h <- T.takeWhile p <$> get
284273 continue <- inputSpansChunks (size h)
285274 if continue
286275 then go (h:acc)
287− else return $ concatReverse (h:acc)
288−{-# INLINE takeWhileAcc #-}
276+ else return (h:acc)
289277
290278takeRest :: Parser [Text]
291279takeRest = go []
@@ -308,7 +296,7 @@ takeLazyText :: Parser L.Text
308296takeLazyText = L.fromChunks `fmap` takeRest
309297
310298data Scan s = Continue s
311− | Finished s {-# UNPACK #-} !Int Text
299+ | Finished {-# UNPACK #-} !Int Text
312300
313301scan_ :: (s -> [Text] -> Parser r) -> s -> (s -> Char -> Maybe s) -> Parser r
314302scan_ f s0 p = go [] s0
@@ -317,7 +305,7 @@ scan_ f s0 p = go [] s0
317305 case T.uncons t of
318306 Just (c,t') -> case p s c of
319307 Just s' -> scanner s' (n+1) t'
320− Nothing -> Finished s n t
308+ Nothing -> Finished n t
321309 Nothing -> Continue s
322310 go acc s = do
323311 input <- get
@@ -326,8 +314,8 @@ scan_ f s0 p = go [] s0
326314 if continue
327315 then go (input : acc) s'
328316 else f s' (input : acc)
329− Finished s' n t -> do advance (size input - size t)
330− f s' (T.take n input : acc)
317+ Finished n t -> do advance (size input - size t)
318+ f s (T.take n input : acc)
331319{-# INLINE scan_ #-}
332320
333321-- | A stateful scanner. The predicate consumes and transforms a
@@ -343,13 +331,16 @@ scan_ f s0 p = go [] s0
343331-- parsers loop until a failure occurs. Careless use will thus result
344332-- in an infinite loop.
345333scan :: s -> (s -> Char -> Maybe s) -> Parser Text
346−scan = scan_ $ \_ chunks -> return $! concatReverse chunks
334+scan = scan_ $ \_ chunks ->
335+ case chunks of
336+ [x] -> return x
337+ xs -> return . T.concat . reverse $ xs
347338{-# INLINE scan #-}
348339
349340-- | Like 'scan', but generalized to return the final state of the
350341-- scanner.
351342runScanner :: s -> (s -> Char -> Maybe s) -> Parser (Text, s)
352−runScanner = scan_ $ \s xs -> let !sx = concatReverse xs in return (sx, s)
343+runScanner = scan_ $ \s xs -> return (T.concat (reverse xs), s)
353344{-# INLINE runScanner #-}
354345
355346-- | Consume input as long as the predicate returns 'True', and return
@@ -367,9 +358,8 @@ takeWhile1 p = do
367358 advance size'
368359 eoc <- endOfChunk
369360 if eoc
370− then takeWhileAcc p [h]
361+ then (h<>) `fmap` takeWhile p
371362 else return h
372−{-# INLINE takeWhile1 #-}
373363
374364-- | Match any character in a set.
375365--
Data/Attoparsec/Zepto.hs+43−81
@@ -2,7 +2,7 @@
22#if __GLASGOW_HASKELL__ >= 702
33{-# LANGUAGE Trustworthy #-} -- Data.ByteString.Unsafe
44#endif
5−{-# LANGUAGE BangPatterns #-}
5+{-# LANGUAGE BangPatterns, MagicHash, UnboxedTuples #-}
66
77-- |
88-- Module : Data.Attoparsec.Zepto
@@ -27,139 +27,101 @@
2727module Data.Attoparsec.Zepto
2828 (
2929 Parser
30− , ZeptoT
3130 , parse
32− , parseT
3331 , atEnd
3432 , string
3533 , take
3634 , takeWhile
3735 ) where
3836
39−import Control.Applicative
40−import Control.Monad (MonadPlus(..), ap)
41−import qualified Control.Monad.Fail as Fail
42−import Control.Monad.IO.Class (MonadIO(..))
43−import Data.ByteString (ByteString)
44−import Data.Functor.Identity (Identity(runIdentity))
45−import Data.Monoid as Mon (Monoid(..))
46−import Data.Semigroup (Semigroup(..))
4737import Data.Word (Word8)
48−import Prelude hiding (take, takeWhile)
38+import Control.Applicative
39+import Control.Monad
40+import Data.Monoid
4941import qualified Data.ByteString as B
5042import qualified Data.ByteString.Unsafe as B
43+import Data.ByteString (ByteString)
44+import Prelude hiding (take, takeWhile)
5145
5246newtype S = S {
5347 input :: ByteString
5448 }
5549
5650data Result a = Fail String
57− | OK !a S
51+ | OK !a
5852
5953-- | A simple parser.
6054--
6155-- This monad is strict in its state, and the monadic bind operator
6256-- ('>>=') evaluates each result to weak head normal form before
6357-- passing it along.
64−newtype ZeptoT m a = Parser {
65− runParser :: S -> m (Result a)
58+newtype Parser a = Parser {
59+ runParser :: S -> (# Result a, S #)
6660 }
6761
68−type Parser a = ZeptoT Identity a
69−
70−instance Monad m => Functor (ZeptoT m) where
71− fmap f m = Parser $ \s -> do
72− result <- runParser m s
73− case result of
74− OK a s' -> return (OK (f a) s')
75− Fail err -> return (Fail err)
62+instance Functor Parser where
63+ fmap f m = Parser $ \s -> case runParser m s of
64+ (# OK a, s' #) -> (# OK (f a), s' #)
65+ (# Fail err, s' #) -> (# Fail err, s' #)
7666 {-# INLINE fmap #-}
7767
78−instance MonadIO m => MonadIO (ZeptoT m) where
79− liftIO act = Parser $ \s -> do
80− result <- liftIO act
81− return (OK result s)
82− {-# INLINE liftIO #-}
83−
84−instance Monad m => Monad (ZeptoT m) where
85− return = pure
68+instance Monad Parser where
69+ return a = Parser $ \s -> (# OK a, s #)
8670 {-# INLINE return #-}
8771
88− m >>= k = Parser $ \s -> do
89− result <- runParser m s
90− case result of
91− OK a s' -> runParser (k a) s'
92− Fail err -> return (Fail err)
72+ m >>= k = Parser $ \s -> case runParser m s of
73+ (# OK a, s' #) -> runParser (k a) s'
74+ (# Fail err, s' #) -> (# Fail err, s' #)
9375 {-# INLINE (>>=) #-}
9476
95−#if !(MIN_VERSION_base(4,13,0))
96− fail = Fail.fail
97− {-# INLINE fail #-}
98−#endif
77+ fail msg = Parser $ \s -> (# Fail msg, s #)
9978
100−instance Monad m => Fail.MonadFail (ZeptoT m) where
101− fail msg = Parser $ \_ -> return (Fail msg)
102− {-# INLINE fail #-}
103−
104−instance Monad m => MonadPlus (ZeptoT m) where
79+instance MonadPlus Parser where
10580 mzero = fail "mzero"
10681 {-# INLINE mzero #-}
10782
108− mplus a b = Parser $ \s -> do
109− result <- runParser a s
110− case result of
111− ok@(OK _ _) -> return ok
112− _ -> runParser b s
83+ mplus a b = Parser $ \s ->
84+ case runParser a s of
85+ (# ok@(OK _), s' #) -> (# ok, s' #)
86+ (# _, _ #) -> case runParser b s of
87+ (# ok@(OK _), s'' #) -> (# ok, s'' #)
88+ (# err, s'' #) -> (# err, s'' #)
11389 {-# INLINE mplus #-}
11490
115−instance (Monad m) => Applicative (ZeptoT m) where
116− pure a = Parser $ \s -> return (OK a s)
91+instance Applicative Parser where
92+ pure = return
11793 {-# INLINE pure #-}
11894 (<*>) = ap
11995 {-# INLINE (<*>) #-}
12096
121−gets :: Monad m => (S -> a) -> ZeptoT m a
122−gets f = Parser $ \s -> return (OK (f s) s)
97+gets :: (S -> a) -> Parser a
98+gets f = Parser $ \s -> (# OK (f s), s #)
12399{-# INLINE gets #-}
124100
125−put :: Monad m => S -> ZeptoT m ()
126−put s = Parser $ \_ -> return (OK () s)
101+put :: S -> Parser ()
102+put s = Parser $ \_ -> (# OK (), s #)
127103{-# INLINE put #-}
128104
129105-- | Run a parser.
130106parse :: Parser a -> ByteString -> Either String a
131−parse p bs = case runIdentity (runParser p (S bs)) of
132− (OK a _) -> Right a
133− (Fail err) -> Left err
134−{-# INLINE parse #-}
135−
136−-- | Run a parser on top of the given base monad.
137−parseT :: Monad m => ZeptoT m a -> ByteString -> m (Either String a)
138−parseT p bs = do
139− result <- runParser p (S bs)
140− case result of
141− OK a _ -> return (Right a)
142− Fail err -> return (Left err)
143−{-# INLINE parseT #-}
144−
145−instance Monad m => Semigroup (ZeptoT m a) where
146− (<>) = mplus
147− {-# INLINE (<>) #-}
148−
149−instance Monad m => Mon.Monoid (ZeptoT m a) where
107+parse p bs = case runParser p (S bs) of
108+ (# OK a, _ #) -> Right a
109+ (# Fail err, _ #) -> Left err
110+
111+instance Monoid (Parser a) where
150112 mempty = fail "mempty"
151113 {-# INLINE mempty #-}
152− mappend = (<>)
114+ mappend = mplus
153115 {-# INLINE mappend #-}
154116
155−instance Monad m => Alternative (ZeptoT m) where
117+instance Alternative Parser where
156118 empty = fail "empty"
157119 {-# INLINE empty #-}
158120 (<|>) = mplus
159121 {-# INLINE (<|>) #-}
160122
161123-- | Consume input while the predicate returns 'True'.
162−takeWhile :: Monad m => (Word8 -> Bool) -> ZeptoT m ByteString
124+takeWhile :: (Word8 -> Bool) -> Parser ByteString
163125takeWhile p = do
164126 (h,t) <- gets (B.span p . input)
165127 put (S t)
@@ -167,7 +129,7 @@ takeWhile p = do
167129{-# INLINE takeWhile #-}
168130
169131-- | Consume @n@ bytes of input.
170−take :: Monad m => Int -> ZeptoT m ByteString
132+take :: Int -> Parser ByteString
171133take !n = do
172134 s <- gets input
173135 if B.length s >= n
@@ -176,7 +138,7 @@ take !n = do
176138{-# INLINE take #-}
177139
178140-- | Match a string exactly.
179−string :: Monad m => ByteString -> ZeptoT m ()
141+string :: ByteString -> Parser ()
180142string s = do
181143 i <- gets input
182144 if s `B.isPrefixOf` i
@@ -185,7 +147,7 @@ string s = do
185147{-# INLINE string #-}
186148
187149-- | Indicate whether the end of the input has been reached.
188−atEnd :: Monad m => ZeptoT m Bool
150+atEnd :: Parser Bool
189151atEnd = do
190152 i <- gets input
191153 return $! B.null i
README.markdown+6
@@ -16,6 +16,12 @@ Master [git repository](https://github.com/bos/attoparsec):
1616
1717* `git clone git://github.com/bos/attoparsec.git`
1818
19+There's also a [Mercurial mirror](https://bitbucket.org/bos/attoparsec):
20+
21+* `hg clone https://bitbucket.org/bos/attoparsec`
22+
23+(You can create and contribute changes using either Mercurial or git.)
24+
1925Authors
2026-------
2127
attoparsec.cabal+11−53
@@ -1,13 +1,12 @@
11name: attoparsec
2−version: 0.13.2.2
3−x-revision: 3
2+version: 0.12.1.5
43license: BSD3
54license-file: LICENSE
65category: Text, Parsing
76author: Bryan O'Sullivan <bos@serpentine.com>
8−maintainer: Bryan O'Sullivan <bos@serpentine.com>, Ben Gamari <ben@smart-cactus.org>
7+maintainer: Bryan O'Sullivan <bos@serpentine.com>
98stability: experimental
10−tested-with: GHC == 7.0.4, GHC == 7.2.2, GHC == 7.4.2, GHC ==7.6.3, GHC ==7.8.4, GHC ==7.10.3, GHC ==8.0.2, GHC ==8.2.2, GHC==8.4.4, GHC==8.6.5, GHC==8.8.1
9+tested-with: GHC == 7.0, GHC == 7.2, GHC == 7.4, GHC == 7.6, GHC == 7.8, GHC == 7.10
1110synopsis: Fast combinator parsing for bytestrings and text
1211cabal-version: >= 1.8
1312homepage: https://github.com/bos/attoparsec
@@ -22,7 +21,6 @@ extra-source-files:
2221 benchmarks/*.cabal
2322 benchmarks/*.hs
2423 benchmarks/*.txt
25− benchmarks/json-data/*.json
2624 benchmarks/Makefile
2725 benchmarks/med.txt.bz2
2826 changelog.md
@@ -40,22 +38,16 @@ Flag developer
4038
4139library
4240 build-depends: array,
43− base >= 4.3 && < 5,
41+ base >= 4.2 && < 5,
4442 bytestring,
4543 containers,
4644 deepseq,
4745 scientific >= 0.3.1 && < 0.4,
48− transformers >= 0.2 && (< 0.4 || >= 0.4.1.0) && < 0.6,
4946 text >= 1.1.1.3
5047 if impl(ghc < 7.4)
5148 build-depends:
5249 bytestring < 0.10.4.0
5350
54− if !impl(ghc >= 8.0)
55− -- Data.Semigroup && Control.Monad.Fail are available in base-4.9+
56− build-depends: fail == 4.9.*,
57− semigroups >=0.16.1 && <0.20
58−
5951 exposed-modules: Data.Attoparsec
6052 Data.Attoparsec.ByteString
6153 Data.Attoparsec.ByteString.Char8
@@ -96,26 +88,6 @@ test-suite tests
9688 QC.Rechunked
9789 QC.Simple
9890 QC.Text
99− QC.Text.FastSet
100− QC.Text.Regressions
101−
102− other-modules: Data.Attoparsec.ByteString
103− Data.Attoparsec.ByteString.Buffer
104− Data.Attoparsec.ByteString.Char8
105− Data.Attoparsec.ByteString.FastSet
106− Data.Attoparsec.ByteString.Internal
107− Data.Attoparsec.ByteString.Lazy
108− Data.Attoparsec.Combinator
109− Data.Attoparsec.Internal
110− Data.Attoparsec.Internal.Fhthagn
111− Data.Attoparsec.Internal.Types
112− Data.Attoparsec.Number
113− Data.Attoparsec.Text
114− Data.Attoparsec.Text.Buffer
115− Data.Attoparsec.Text.FastSet
116− Data.Attoparsec.Text.Internal
117− Data.Attoparsec.Text.Lazy
118− Data.Attoparsec.Zepto
11991
12092 ghc-options:
12193 -Wall -threaded -rtsopts
@@ -125,23 +97,17 @@ test-suite tests
12597
12698 build-depends:
12799 array,
128− base,
100+ base >= 4 && < 5,
129101 bytestring,
130102 deepseq >= 1.1,
131− QuickCheck >= 2.13.2 && < 2.14,
103+ QuickCheck >= 2.7,
132104 quickcheck-unicode,
133105 scientific,
134− tasty >= 0.11,
135− tasty-quickcheck >= 0.8,
106+ test-framework >= 0.8.0.2,
107+ test-framework-quickcheck2 >= 0.3.0.3,
136108 text,
137− transformers >= 0.2 && (< 0.4 || >= 0.4.1.0) && < 0.6,
138109 vector
139110
140− if !impl(ghc >= 8.0)
141− -- Data.Semigroup && Control.Monad.Fail are available in base-4.9+
142− build-depends: fail == 4.9.*,
143− semigroups >=0.16.1 && <0.20
144−
145111benchmark benchmarks
146112 type: exitcode-stdio-1.0
147113 hs-source-dirs: benchmarks benchmarks/warp-3.0.1.1 .
@@ -153,11 +119,7 @@ benchmark benchmarks
153119 HeadersByteString.Atto
154120 HeadersText
155121 Links
156− Network.Wai.Handler.Warp.ReadInt
157− Network.Wai.Handler.Warp.RequestHeader
158122 Numbers
159− Sets
160− TextFastSet
161123 Warp
162124 ghc-options: -O2 -Wall
163125
@@ -169,7 +131,6 @@ benchmark benchmarks
169131 base == 4.*,
170132 bytestring >= 0.10.4.0,
171133 case-insensitive,
172− containers,
173134 criterion >= 1.0,
174135 deepseq >= 1.1,
175136 directory,
@@ -179,16 +140,13 @@ benchmark benchmarks
179140 parsec >= 3.1.2,
180141 scientific,
181142 text >= 1.1.1.0,
182− transformers >= 0.2 && (< 0.4 || >= 0.4.1.0) && < 0.6,
183143 unordered-containers,
184144 vector
185145
186− if !impl(ghc >= 8.0)
187− -- Data.Semigroup && Control.Monad.Fail are available in base-4.9+
188− build-depends: fail == 4.9.*,
189− semigroups >=0.16.1 && <0.19
190−
191146source-repository head
192147 type: git
193148 location: https://github.com/bos/attoparsec
194149
150+source-repository head
151+ type: mercurial
152+ location: https://bitbucket.org/bos/attoparsec
benchmarks/Aeson.hs+2−6
@@ -10,13 +10,8 @@ module Aeson
1010import Data.ByteString.Builder
1111 (Builder, byteString, toLazyByteString, charUtf8, word8)
1212
13−#if !MIN_VERSION_base(4,8,0)
14−import Control.Applicative ((*>), (<$>), (<*), pure)
15−import Data.Monoid (mappend, mempty)
16−#endif
17−
1813import Common (pathTo)
19−import Control.Applicative (liftA2)
14+import Control.Applicative ((*>), (<$>), (<*), liftA2, pure)
2015import Control.DeepSeq (NFData(..))
2116import Control.Monad (forM)
2217import Data.Attoparsec.ByteString.Char8 (Parser, char, endOfInput, scientific,
@@ -25,6 +20,7 @@ import Data.Bits ((.|.), shiftL)
2520import Data.ByteString (ByteString)
2621import Data.Char (chr)
2722import Data.List (sort)
23+import Data.Monoid (mappend, mempty)
2824import Data.Scientific (Scientific)
2925import Data.Text (Text)
3026import Data.Text.Encoding (decodeUtf8')
benchmarks/Benchmarks.hs−6
@@ -28,7 +28,6 @@ import qualified HeadersByteString
2828import qualified HeadersText
2929import qualified Links
3030import qualified Text.Parsec as P
31−import qualified Sets
3231
3332main :: IO ()
3433main = do
@@ -71,14 +70,10 @@ main = do
7170 , bench "isAlpha_ascii" $ nf (ABL.parse (AC.takeWhile AC.isAlpha_ascii)) bl
7271 , bench "isAlpha_iso8859_15" $
7372 nf (ABL.parse (AC.takeWhile AC.isAlpha_iso8859_15)) bl
74− , bench "T isAlpha" $ nf (AT.parse (AT.takeWhile isAlpha)) t
75− , bench "TL isAlpha" $ nf (ATL.parse (AT.takeWhile isAlpha)) tl
7673 ]
7774 , bgroup "takeWhile1" [
7875 bench "isAlpha" $ nf (ABL.parse (AC.takeWhile1 isAlpha)) bl
7976 , bench "isAlpha_ascii" $ nf (ABL.parse (AC.takeWhile1 AC.isAlpha_ascii)) bl
80− , bench "T isAlpha" $ nf (AT.parse (AT.takeWhile1 isAlpha)) t
81− , bench "TL isAlpha" $ nf (ATL.parse (AT.takeWhile1 isAlpha)) tl
8277 ]
8378 , bench "word32LE" $ nf (AB.parse word32LE) b
8479 , bgroup "scan" [
@@ -91,7 +86,6 @@ main = do
9186 , headersT
9287 , Links.links
9388 , numbers
94− , Sets.benchmarks
9589 , Warp.benchmarks
9690 ]
9791
benchmarks/HeadersByteString.hs+1−10
@@ -9,15 +9,6 @@ import qualified Data.Attoparsec.ByteString.Char8 as B
99import qualified Data.Attoparsec.ByteString.Lazy as BL
1010import qualified Data.ByteString.Char8 as B
1111
12−-- Note: In the benchmarks for parsing an http request
13−-- from a strict bytestring, we consider warp's implementation,
14−-- which has highly optimized code for handling the first
15−-- line in particular. It's treatment of the headers
16−-- is more relaxed from the treatment they are given by the
17−-- attoparsec parser benchmarked here. Consequently, it
18−-- is should not be possible to match its performance since
19−-- it accepts header names with disallowed characters.
20−
2112headers :: IO Benchmark
2213headers = do
2314 req <- B.readFile =<< pathTo "http-request.txt"
@@ -27,7 +18,7 @@ headers = do
2718 return $ bgroup "headers" [
2819 bgroup "B" [
2920 bench "request" $ nf (B.parseOnly request) req
30− , bench "warp" $ nfIO (parseHeaderLines (B.split '\n' req))
21+ , bench "warp" $ nfIO (parseHeaderLines [req])
3122 , bench "response" $ nf (B.parseOnly response) resp
3223 ]
3324 , bgroup "BL" [
benchmarks/HeadersByteString/Atto.hs+1−9
@@ -15,16 +15,8 @@ import qualified Data.ByteString.Char8 as B
1515instance NFData HttpVersion where
1616 rnf !_ = ()
1717
18−isHeaderChar :: Char -> Bool
19−isHeaderChar c =
20− (c >= 'a' && c <= 'z') ||
21− (c >= 'A' && c <= 'Z') ||
22− (c >= '0' && c <= '9') ||
23− (c == '_') ||
24− (c == '-')
25−
2618header = do
27− name <- B.takeWhile1 isHeaderChar <* B.char ':' <* B.skipSpace
19+ name <- B.takeWhile1 (B.inClass "a-zA-Z0-9_-") <* B.char ':' <* B.skipSpace
2820 body <- bodyLine
2921 return (name, body)
3022
benchmarks/Links.hs+2−2
@@ -5,8 +5,8 @@ module Links (links) where
55import Control.Applicative
66import Control.DeepSeq (NFData(..))
77import Criterion.Main (Benchmark, bench, nf)
8−import Data.Attoparsec.ByteString as A
9−import Data.Attoparsec.ByteString.Char8 as A8
8+import Data.Attoparsec as A
9+import Data.Attoparsec.Char8 as A8
1010import Data.ByteString.Char8 as B8
1111
1212data Link = Link {
benchmarks/Numbers.hs−1
@@ -1,5 +1,4 @@
11{-# LANGUAGE BangPatterns #-}
2−{-# OPTIONS_GHC -fno-warn-deprecations #-}
32
43module Numbers (numbers) where
54
benchmarks/Sets.hsdeleted−21
@@ -1,21 +0,0 @@
1−module Sets (benchmarks) where
2−
3−import Criterion
4−import Data.Char (ord)
5−import qualified Data.Attoparsec.Text.FastSet as FastSet
6−import qualified TextFastSet
7−import qualified Data.HashSet as HashSet
8−import qualified Data.IntSet as IntSet
9−
10−smallSet :: String
11−smallSet = ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9']
12−
13−benchmarks :: Benchmark
14−benchmarks = bgroup "sets" [
15− bench "Fast" $ whnf (FastSet.member '*') (FastSet.fromList smallSet)
16− , bench "Hash" $ whnf (HashSet.member '*') (HashSet.fromList smallSet)
17− , bench "Int" $ whnf (IntSet.member (ord '*'))
18− (IntSet.fromList (map ord smallSet))
19− , bench "TextFast" $ whnf (TextFastSet.member '*')
20− (TextFastSet.fromList smallSet)
21− ]
benchmarks/TextFastSet.hsdeleted−121
@@ -1,121 +0,0 @@
1−{-# LANGUAGE BangPatterns #-}
2−
3−------------------------------------------------------------------------------
4−-- |
5−-- Module : Data.Attoparsec.FastSet
6−-- Copyright : Felipe Lessa 2010, Bryan O'Sullivan 2007-2015
7−-- License : BSD3
8−--
9−-- Maintainer : felipe.lessa@gmail.com
10−-- Stability : experimental
11−-- Portability : unknown
12−--
13−-- Fast set membership tests for 'Char' values. We test for
14−-- membership using a hashtable implemented with Robin Hood
15−-- collision resolution. The set representation is unboxed,
16−-- and the characters and hashes interleaved, for efficiency.
17−--
18−--
19−-----------------------------------------------------------------------------
20−module TextFastSet
21− (
22− -- * Data type
23− FastSet
24− -- * Construction
25− , fromList
26− , set
27− -- * Lookup
28− , member
29− -- * Handy interface
30− , charClass
31− ) where
32−
33−import Data.Bits ((.|.), (.&.), shiftR)
34−import Data.Function (on)
35−import Data.List (sort, sortBy)
36−import qualified Data.Array.Base as AB
37−import qualified Data.Array.Unboxed as A
38−import qualified Data.Text as T
39−
40−data FastSet = FastSet {
41− table :: {-# UNPACK #-} !(A.UArray Int Int)
42− , mask :: {-# UNPACK #-} !Int
43− }
44−
45−data Entry = Entry {
46− key :: {-# UNPACK #-} !Char
47− , initialIndex :: {-# UNPACK #-} !Int
48− , index :: {-# UNPACK #-} !Int
49− }
50−
51−offset :: Entry -> Int
52−offset e = index e - initialIndex e
53−
54−resolveCollisions :: [Entry] -> [Entry]
55−resolveCollisions [] = []
56−resolveCollisions [e] = [e]
57−resolveCollisions (a:b:entries) = a' : resolveCollisions (b' : entries)
58− where (a', b')
59− | index a < index b = (a, b)
60− | offset a < offset b = (b { index=index a }, a { index=index a + 1 })
61− | otherwise = (a, b { index=index a + 1 })
62−
63−pad :: Int -> [Entry] -> [Entry]
64−pad = go 0
65− where -- ensure that we pad enough so that lookups beyond the
66− -- last hash in the table fall within the array
67− go !_ !m [] = replicate (max 1 m + 1) empty
68− go k m (e:entries) = map (const empty) [k..i - 1] ++ e :
69− go (i + 1) (m + i - k - 1) entries
70− where i = index e
71− empty = Entry '\0' maxBound 0
72−
73−nextPowerOf2 :: Int -> Int
74−nextPowerOf2 0 = 1
75−nextPowerOf2 x = go (x - 1) 1
76− where go y 32 = y + 1
77− go y k = go (y .|. (y `shiftR` k)) $ k * 2
78−
79−fastHash :: Char -> Int
80−fastHash = fromEnum
81−
82−fromList :: String -> FastSet
83−fromList s = FastSet (AB.listArray (0, length interleaved - 1) interleaved)
84− mask'
85− where s' = ordNub (sort s)
86− l = length s'
87− mask' = nextPowerOf2 ((5 * l) `div` 4) - 1
88− entries = pad mask' .
89− resolveCollisions .
90− sortBy (compare `on` initialIndex) .
91− zipWith (\c i -> Entry c i i) s' .
92− map ((.&. mask') . fastHash) $ s'
93− interleaved = concatMap (\e -> [fromEnum $ key e, initialIndex e])
94− entries
95−
96−ordNub :: Eq a => [a] -> [a]
97−ordNub [] = []
98−ordNub (y:ys) = go y ys
99− where go x (z:zs)
100− | x == z = go x zs
101− | otherwise = x : go z zs
102− go x [] = [x]
103−
104−set :: T.Text -> FastSet
105−set = fromList . T.unpack
106−
107−-- | Check the set for membership.
108−member :: Char -> FastSet -> Bool
109−member c a = go (2 * i)
110− where i = fastHash c .&. mask a
111− lookupAt j b = (i' <= i) && (c == c' || b)
112− where c' = toEnum $ AB.unsafeAt (table a) j
113− i' = AB.unsafeAt (table a) $ j + 1
114− go j = lookupAt j . lookupAt (j + 2) . lookupAt (j + 4) .
115− lookupAt (j + 6) . go $ j + 8
116−
117−charClass :: String -> FastSet
118−charClass = fromList . go
119− where go (a:'-':b:xs) = [a..b] ++ go xs
120− go (x:xs) = x : go xs
121− go _ = ""
benchmarks/attoparsec-benchmarks.cabal−4
@@ -16,8 +16,6 @@ executable attoparsec-benchmarks
1616 Links
1717 Numbers
1818 Network.Wai.Handler.Warp.ReadInt
19− Sets
20− TextFastSet
2119 Warp
2220 hs-source-dirs: .. . warp-3.0.1.1
2321 ghc-options: -O2 -Wall -rtsopts
@@ -26,7 +24,6 @@ executable attoparsec-benchmarks
2624 base == 4.*,
2725 bytestring >= 0.10.4.0,
2826 case-insensitive,
29− containers,
3027 criterion >= 1.0,
3128 deepseq >= 1.1,
3229 directory,
@@ -36,6 +33,5 @@ executable attoparsec-benchmarks
3633 parsec >= 3.1.2,
3734 scientific >= 0.3.1,
3835 text >= 1.1.1.0,
39− transformers,
4036 unordered-containers,
4137 vector
benchmarks/http-request.txt+8−3
@@ -1,9 +1,14 @@
11GET / HTTP/1.1
22Host: twitter.com
3−Accept: text/html, application/xhtml+xml, application/xml; q=0.9, image/webp, */*; q=0.8
3+Accept: text/html, application/xhtml+xml, application/xml; q=0.9,
4+ image/webp, */*; q=0.8
45Accept-Encoding: gzip,deflate,sdch
56Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
67Cache-Control: max-age=0
7−Cookie: guest_id=v1%3A139; _twitter_sess=BAh7CSIKZmxhc2hJQz-e1e1; __utma=43838368.452555194.1399611824.1; __utmb=43838368; __utmc=43838368; __utmz=1399611824.1.1.utmcsr=(direct)|utmcmd=(none)
8−User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.86 Safari/537.36
8+Cookie: guest_id=v1%3A139; _twitter_sess=BAh7CSIKZmxhc2hJQz-e1e1;
9+ __utma=43838368.452555194.1399611824.1; __utmb=43838368;
10+ __utmc=43838368; __utmz=1399611824.1.1.utmcsr=(direct)|utmcmd=(none)
11+User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5)
12+ AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.86
13+ Safari/537.36
914
benchmarks/http-response.txt+4−2
@@ -3,8 +3,10 @@ Date: Fri, 09 May 2014 04:24:57 GMT
33Expires: -1
44Cache-Control: private, max-age=0
55Content-Type: text/html; charset=ISO-8859-1
6−Set-Cookie: PREF=ID=1a871afc4240db5e:FF:LM=1399609497:S=e5MZ0itEekjVwNcU; expires=Sun, 08-May-2016 04:24:57 GMT; path=/; domain=.google.com
7−Set-Cookie: NID=67=-WlfaDG6VSEPk7abAjrK98HBSoCD2ID6JKkUR95tEumzDmg7Fc8pSQ8; expires=Sat, 08-Nov-2014 04:24:57 GMT; path=/; domain=.google.com; HttpOnly
6+Set-Cookie: PREF=ID=1a871afc4240db5e:FF:LM=1399609497:S=e5MZ0itEekjVwNcU;
7+ expires=Sun, 08-May-2016 04:24:57 GMT; path=/; domain=.google.com
8+Set-Cookie: NID=67=-WlfaDG6VSEPk7abAjrK98HBSoCD2ID6JKkUR95tEumzDmg7Fc8pSQ8;
9+ expires=Sat, 08-Nov-2014 04:24:57 GMT; path=/; domain=.google.com; HttpOnly
810P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
911Server: gws
1012X-XSS-Protection: 1; mode=block
benchmarks/warp-3.0.1.1/Network/Wai/Handler/Warp/RequestHeader.hs+1−1
@@ -139,7 +139,7 @@ parseRequestLine requestLine@(PS fptr off len) = withForeignPtr fptr $ \ptr -> d
139139
140140parseHeader :: ByteString -> H.Header
141141parseHeader s =
142− let (k, rest) = S.break (== 58) s -- ':'
142+ let (k, rest) = S.breakByte 58 s -- ':'
143143 rest' = S.dropWhile (\c -> c == 32 || c == 9) $ S.drop 1 rest
144144 in (CI.mk k, rest')
145145
changelog.md−35
@@ -1,38 +1,3 @@
1−0.13.2.1
2−
3−* Improved performance of `Data.Attoparsec.Text.asciiCI`
4−
5−0.13.2.0
6−
7−* `pure` is now strict in `Position`
8−
9−0.13.1.0
10−
11−* `runScanner` now correctly returns the final state
12− (https://github.com/bos/attoparsec/issues/105).
13−* `Parser`, `ZeptoT`, `Buffer`, and `More` now expose `Semigroup` instances.
14−* `Parser`, and `ZeptoT` now expose `MonadFail` instances.
15−
16−0.13.0.2
17−
18−* Restore the fast specialised character set implementation for Text
19−* Move testsuite from test-framework to tasty
20−* Performance optimization of takeWhile and takeWhile1
21−
22−0.13.0.1
23−
24−* Fixed a bug in the implementations of inClass and notInClass for
25− Text (https://github.com/bos/attoparsec/issues/103)
26−
27−0.13.0.0
28−
29−* Made the parser type in the Zepto module a monad transformer
30− (needed by aeson's string unescaping parser).
31−
32−0.12.1.6
33−
34−* Fixed a case folding bug in the ByteString version of stringCI.
35−
3610.12.1.5
372
383* Fixed an indexing bug in the new Text implementation of string,
tests/QC.hs+2−2
@@ -6,11 +6,11 @@ import qualified QC.ByteString as ByteString
66import qualified QC.Combinator as Combinator
77import qualified QC.Simple as Simple
88import qualified QC.Text as Text
9−import Test.Tasty (defaultMain, testGroup)
9+import Test.Framework (defaultMain, testGroup)
1010
1111main = defaultMain tests
1212
13−tests = testGroup "tests" [
13+tests = [
1414 testGroup "bs" ByteString.tests
1515 , testGroup "buf" Buffer.tests
1616 , testGroup "combinator" Combinator.tests
tests/QC/Buffer.hs+4−4
@@ -3,13 +3,13 @@
33
44module QC.Buffer (tests) where
55
6−#if !MIN_VERSION_base(4,8,0)
76import Control.Applicative ((<$>))
7+#if !MIN_VERSION_base(4,8,0)
88import Data.Monoid (Monoid(mconcat))
99#endif
1010import QC.Common ()
11−import Test.Tasty (TestTree)
12−import Test.Tasty.QuickCheck (testProperty)
11+import Test.Framework (Test)
12+import Test.Framework.Providers.QuickCheck2 (testProperty)
1313import Test.QuickCheck
1414import qualified Data.Attoparsec.ByteString.Buffer as BB
1515import qualified Data.Attoparsec.Text.Buffer as BT
@@ -82,7 +82,7 @@ t_dropWord16 (BP _ts t buf) = do
8282 i <- choose (0, T.lengthWord16 t)
8383 return $ T.dropWord16 i t === BT.dropWord16 i buf
8484
85−tests :: [TestTree]
85+tests :: [Test]
8686tests = [
8787 testProperty "b_unbuffer" b_unbuffer
8888 , testProperty "t_unbuffer" t_unbuffer
tests/QC/ByteString.hs+9−25
@@ -2,22 +2,22 @@
22module QC.ByteString (tests) where
33
44#if !MIN_VERSION_base(4,8,0)
5−import Control.Applicative ((<*>), (<$>))
5+import Control.Applicative ((<*>))
66#endif
7−import Data.Char (chr, ord, toUpper)
7+import Control.Applicative ((<$>))
8+import Data.Char (chr, ord)
89import Data.Int (Int64)
910import Data.Word (Word8)
1011import Prelude hiding (take, takeWhile)
11−import QC.Common (ASCII(..), liftOp, parseBS, toStrictBS)
12−import Test.Tasty (TestTree)
13−import Test.Tasty.QuickCheck (testProperty)
12+import QC.Common (liftOp, parseBS, toStrictBS)
13+import Test.Framework (Test)
14+import Test.Framework.Providers.QuickCheck2 (testProperty)
1415import Test.QuickCheck
1516import qualified Data.Attoparsec.ByteString as P
1617import qualified Data.Attoparsec.ByteString.Char8 as P8
1718import qualified Data.Attoparsec.ByteString.FastSet as S
1819import qualified Data.Attoparsec.ByteString.Lazy as PL
1920import qualified Data.ByteString as B
20−import qualified Data.ByteString.Char8 as B8
2121import qualified Data.ByteString.Lazy as L
2222import qualified Data.ByteString.Lazy.Char8 as L8
2323
@@ -26,11 +26,9 @@ import qualified Data.ByteString.Lazy.Char8 as L8
2626satisfy :: Word8 -> L.ByteString -> Property
2727satisfy w s = parseBS (P.satisfy (<=w)) (L.cons w s) === Just w
2828
29−satisfyWith :: Word8 -> L.ByteString -> Property
30−satisfyWith w s = parseBS (P.satisfyWith (chr . fromIntegral) (<=c))
29+satisfyWith :: Char -> L.ByteString -> Property
30+satisfyWith c s = parseBS (P.satisfyWith (chr . fromIntegral) (<=c))
3131 (L.cons (fromIntegral (ord c)) s) === Just c
32− where
33− c = chr (fromIntegral w)
3432
3533word8 :: Word8 -> L.ByteString -> Property
3634word8 w s = parseBS (P.word8 w) (L.cons w s) === Just w
@@ -68,18 +66,6 @@ string :: L.ByteString -> L.ByteString -> Property
6866string s t = parseBS (P.string s') (s `L.append` t) === Just s'
6967 where s' = toStrictBS s
7068
71−stringCI :: ASCII L.ByteString -> ASCII L.ByteString -> Property
72−stringCI (ASCII s) (ASCII t) =
73− parseBS (P8.stringCI up) (s `L.append` t) === Just s'
74− where s' = toStrictBS s
75− up = B8.map toUpper s'
76−
77−strings :: L.ByteString -> L.ByteString -> L.ByteString -> Property
78−strings s t u =
79− parseBS (P.string (toStrictBS s) >> P.string t') (L.concat [s,t,u])
80− === Just t'
81− where t' = toStrictBS t
82−
8369skipWhile :: Word8 -> L.ByteString -> Property
8470skipWhile w s =
8571 let t = L.dropWhile (<=w) s
@@ -157,7 +143,7 @@ nonmembers :: [Word8] -> [Word8] -> Property
157143nonmembers s s' = property . not . any (`S.memberWord8` set) $ filter (not . (`elem` s)) s'
158144 where set = S.fromList s
159145
160−tests :: [TestTree]
146+tests :: [Test]
161147tests = [
162148 testProperty "anyWord8" anyWord8
163149 , testProperty "endOfInput" endOfInput
@@ -171,8 +157,6 @@ tests = [
171157 , testProperty "skip" skip
172158 , testProperty "skipWhile" skipWhile
173159 , testProperty "string" string
174− , testProperty "stringCI" stringCI
175− , testProperty "strings" strings
176160 , testProperty "take" take
177161 , testProperty "takeByteString" takeByteString
178162 , testProperty "takeCount" takeCount
tests/QC/Combinator.hs+5−7
@@ -1,15 +1,13 @@
1−{-# LANGUAGE CPP, OverloadedStrings #-}
1+{-# LANGUAGE OverloadedStrings #-}
22
33module QC.Combinator where
44
5−#if !MIN_VERSION_base(4,8,0)
6−import Control.Applicative ((<*>), (<$>), (<*), (*>))
7−#endif
5+import Control.Applicative
86import Data.Maybe (fromJust, isJust)
97import Data.Word (Word8)
108import QC.Common (Repack, parseBS, repackBS, toLazyBS)
11−import Test.Tasty (TestTree)
12−import Test.Tasty.QuickCheck (testProperty)
9+import Test.Framework (Test)
10+import Test.Framework.Providers.QuickCheck2 (testProperty)
1311import Test.QuickCheck
1412import qualified Data.Attoparsec.ByteString.Char8 as P
1513import qualified Data.Attoparsec.Combinator as C
@@ -43,7 +41,7 @@ match n (NonNegative x) (NonNegative y) rs =
4341 B8.replicate x 'x', B8.pack (show n), B8.replicate y 'y'
4442 ]
4543
46−tests :: [TestTree]
44+tests :: [Test]
4745tests = [
4846 testProperty "choice" choice
4947 , testProperty "count" count
tests/QC/Common.hs+4−27
@@ -1,9 +1,8 @@
1−{-# LANGUAGE CPP, FlexibleInstances #-}
1+{-# LANGUAGE CPP #-}
22{-# OPTIONS_GHC -fno-warn-orphans #-}
33module QC.Common
44 (
5− ASCII(..)
6− , parseBS
5+ parseBS
76 , parseT
87 , toLazyBS
98 , toStrictBS
@@ -16,8 +15,9 @@ module QC.Common
1615 ) where
1716
1817#if !MIN_VERSION_base(4,8,0)
19−import Control.Applicative ((<*>), (<$>))
18+import Control.Applicative ((<*>))
2019#endif
20+import Control.Applicative ((<$>))
2121import Data.Char (isAlpha)
2222import Test.QuickCheck
2323import Test.QuickCheck.Unicode (shrinkChar, string)
@@ -28,16 +28,6 @@ import qualified Data.Text.Lazy as TL
2828import qualified Data.Attoparsec.ByteString.Lazy as BL
2929import qualified Data.Attoparsec.Text.Lazy as TL
3030
31−#if !MIN_VERSION_base(4,4,0)
32−-- This should really be a dependency on the random package :-(
33−instance Random Word8 where
34− randomR = integralRandomR
35− random = randomR (minBound,maxBound)
36−
37−instance Arbitrary Word8 where
38− arbitrary = choose (minBound, maxBound)
39−#endif
40−
4131parseBS :: BL.Parser r -> BL.ByteString -> Maybe r
4232parseBS p = BL.maybeResult . BL.parse p
4333
@@ -52,22 +42,9 @@ toLazyBS = BL.fromChunks . (:[])
5242
5343instance Arbitrary B.ByteString where
5444 arbitrary = B.pack <$> arbitrary
55− shrink = map B.pack . shrink . B.unpack
5645
5746instance Arbitrary BL.ByteString where
5847 arbitrary = repackBS <$> arbitrary <*> arbitrary
59− shrink = map BL.pack . shrink . BL.unpack
60−
61−newtype ASCII a = ASCII { fromASCII :: a }
62− deriving (Eq, Ord, Show)
63−
64−instance Arbitrary (ASCII B.ByteString) where
65− arbitrary = (ASCII . B.pack) <$> listOf (choose (0,127))
66− shrink = map (ASCII . B.pack) . shrink . B.unpack . fromASCII
67−
68−instance Arbitrary (ASCII BL.ByteString) where
69− arbitrary = ASCII <$> (repackBS <$> arbitrary <*> (fromASCII <$> arbitrary))
70− shrink = map (ASCII . BL.pack) . shrink . BL.unpack . fromASCII
7148
7249type Repack = NonEmptyList (Positive (Small Int))
7350
tests/QC/Simple.hs+3−3
@@ -10,8 +10,8 @@ import Data.ByteString (ByteString)
1010import Data.List (foldl')
1111import Data.Maybe (fromMaybe)
1212import QC.Rechunked (rechunkBS)
13−import Test.Tasty (TestTree)
14−import Test.Tasty.QuickCheck (testProperty)
13+import Test.Framework (Test)
14+import Test.Framework.Providers.QuickCheck2 (testProperty)
1515import Test.QuickCheck (Property, counterexample, forAll)
1616import qualified Data.Attoparsec.ByteString.Char8 as A
1717
@@ -31,7 +31,7 @@ parse :: A.Parser r -> [ByteString] -> A.Result r
3131parse p (x:xs) = foldl' A.feed (A.parse p x) xs
3232parse p [] = A.parse p ""
3333
34−tests :: [TestTree]
34+tests :: [Test]
3535tests = [
3636 testProperty "issue75" t_issue75
3737 ]
tests/QC/Text.hs+8−26
@@ -3,24 +3,20 @@
33module QC.Text (tests) where
44
55#if !MIN_VERSION_base(4,8,0)
6−import Control.Applicative ((<*>), (<$>))
6+import Control.Applicative ((<*>))
77#endif
8+import Control.Applicative ((<$>))
89import Data.Int (Int64)
9−import Data.Word (Word8)
1010import Prelude hiding (take, takeWhile)
1111import QC.Common (liftOp, parseT)
12−import qualified QC.Text.FastSet as FastSet
13−import qualified QC.Text.Regressions as Regressions
14−import Test.Tasty (TestTree, testGroup)
15−import Test.Tasty.QuickCheck (testProperty)
12+import Test.Framework (Test)
13+import Test.Framework.Providers.QuickCheck2 (testProperty)
1614import Test.QuickCheck
1715import qualified Data.Attoparsec.Text as P
1816import qualified Data.Attoparsec.Text.Lazy as PL
1917import qualified Data.Attoparsec.Text.FastSet as S
20−import qualified Data.ByteString as BS
2118import qualified Data.Char as Char
2219import qualified Data.Text as T
23−import qualified Data.Text.Encoding as TE
2420import qualified Data.Text.Lazy as L
2521
2622-- Basic byte-level combinators.
@@ -67,18 +63,9 @@ string :: L.Text -> L.Text -> Property
6763string s t = parseT (P.string s') (s `L.append` t) === Just s'
6864 where s' = toStrict s
6965
70−strings :: L.Text -> L.Text -> L.Text -> Property
71−strings s t u =
72− parseT (P.string (toStrict s) >> P.string t') (L.concat [s,t,u])
73− === Just t'
74− where t' = toStrict t
75−
76−-- | Note: "simple, and efficient" works for well formed input...
77−-- i.e. e.g. Latin1 texts
78−stringCI :: [Word8] -> Property
79−stringCI ws = P.parseOnly (P.stringCI fs) s === Right s
66+stringCI :: T.Text -> Property
67+stringCI s = P.parseOnly (P.stringCI fs) s === Right s
8068 where fs = T.toCaseFold s
81− s = TE.decodeLatin1 (BS.pack ws)
8269
8370asciiCI :: T.Text -> Gen Bool
8471asciiCI x =
@@ -156,9 +143,7 @@ endOfLine s =
156143 (c, fst <$> L.uncons s') === ('\r', Just '\n')
157144
158145scan :: L.Text -> Positive Int64 -> Property
159−-- for some reason, if counterexample is removed, this test fails?
160−scan s (Positive k) = counterexample (show s)
161− $ parseT p s === Just (toStrict $ L.take k s)
146+scan s (Positive k) = parseT p s === Just (toStrict $ L.take k s)
162147 where p = P.scan k $ \ n _ ->
163148 if n > 0 then let !n' = n - 1 in Just n' else Nothing
164149
@@ -170,7 +155,7 @@ nonmembers :: String -> String -> Property
170155nonmembers s s' = property . not . any (`S.member` set) $ filter (not . (`elem` s)) s'
171156 where set = S.fromList s
172157
173−tests :: [TestTree]
158+tests :: [Test]
174159tests = [
175160 testProperty "anyChar" anyChar
176161 , testProperty "asciiCI" asciiCI
@@ -186,7 +171,6 @@ tests = [
186171 , testProperty "skip" skip
187172 , testProperty "skipWhile" skipWhile
188173 , testProperty "string" string
189− , testProperty "strings" strings
190174 , testProperty "stringCI" stringCI
191175 , testProperty "take" take
192176 , testProperty "takeText" takeText
@@ -198,6 +182,4 @@ tests = [
198182 , testProperty "takeWhile1_empty" takeWhile1_empty
199183 , testProperty "members" members
200184 , testProperty "nonmembers" nonmembers
201− , testGroup "FastSet" FastSet.tests
202− , testGroup "Regressions" Regressions.tests
203185 ]
tests/QC/Text/FastSet.hsdeleted−15
@@ -1,15 +0,0 @@
1−module QC.Text.FastSet where
2−
3−import Test.Tasty (TestTree)
4−import Test.Tasty.QuickCheck (testProperty)
5−import Test.QuickCheck
6−import qualified Data.Attoparsec.Text.FastSet as FastSet
7−
8−membershipCorrect :: String -> String -> Property
9−membershipCorrect members others =
10− let fs = FastSet.fromList members
11− correct c = (c `FastSet.member` fs) == (c `elem` members)
12− in property $ all correct (members ++ others)
13−
14−tests :: [TestTree]
15−tests = [ testProperty "membership is correct" membershipCorrect ]
tests/QC/Text/Regressions.hsdeleted−54
@@ -1,54 +0,0 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−
3−module QC.Text.Regressions (
4− tests
5− ) where
6−
7−import Data.Text (Text)
8−import qualified Data.Text as T
9−import Data.List (foldl')
10−import Data.Maybe (fromMaybe)
11−import Data.Char (isLower)
12−import Data.Monoid ((<>))
13−import QC.Rechunked (rechunkT)
14−import Test.Tasty (TestTree)
15−import Test.Tasty.QuickCheck (testProperty)
16−import Test.QuickCheck (Property, counterexample, forAll)
17−import qualified Data.Attoparsec.Text as A
18−
19−
20−--------------------------------------------------------------------------------
21−-- 105 was about runScanner not always returning the final state. The result
22−-- did depend on how the data was fed to the parser.
23−
24−t_issue105 :: Property
25−t_issue105 = expect issue105 "lowER" (A.Done "ER" "low")
26−
27−issue105 :: A.Parser Text
28−issue105 = do
29− (_, firstFourLowercaseLetters) <- A.runScanner "" f
30− return $ firstFourLowercaseLetters
31−
32− where
33− f :: Text -> Char -> Maybe Text
34− f acc c = if T.length acc < 4 && isLower c
35− then Just $ acc <> T.singleton c
36− else Nothing
37−
38−
39−expect :: (Show r, Eq r) => A.Parser r -> Text -> A.Result r -> Property
40−expect p input wanted =
41− forAll (rechunkT input) $ \in' ->
42− let result = parse p in'
43− in counterexample (show result ++ " /= " ++ show wanted) $
44− fromMaybe False (A.compareResults result wanted)
45−
46−parse :: A.Parser r -> [Text] -> A.Result r
47−parse p (x:xs) = foldl' A.feed (A.parse p x) xs
48−parse p [] = A.parse p ""
49−
50−
51−tests :: [TestTree]
52−tests = [
53− testProperty "issue105" t_issue105
54− ]