git.iko.soy/typeable/attoparsec
on master help sign in
Merge from 0.11
commit7600fe910fc9b93b25a324307b079ddd7091e760 authorBryan O'Sullivan <bos@serpentine.com> dateThu 15 May 2014, 08:54 (12 years ago) parent6bca967a3e555e
3 files changed+31−4
attoparsec.cabal−1 benchmarks/Aeson.hs+31−2 benchmarks/attoparsec-benchmarks.cabal−1
attoparsec.cabal−1
@@ -111,7 +111,6 @@ benchmark benchmarks
111111 ghc-options: -Werror
112112
113113 build-depends:
114− aeson,
115114 array,
116115 base == 4.*,
117116 bytestring >= 0.10.4.0,
benchmarks/Aeson.hs+31−2
@@ -11,8 +11,8 @@ import Data.ByteString.Builder
1111 (Builder, byteString, toLazyByteString, charUtf8, word8)
1212
1313import Control.Applicative ((*>), (<$>), (<*), liftA2, pure)
14+import Control.DeepSeq (NFData(..))
1415import Control.Monad (forM)
15−import Data.Aeson.Types (Result(..), Value(..))
1616import Data.Attoparsec.ByteString.Char8 (Parser, char, endOfInput, scientific,
1717 skipSpace, string)
1818import Data.Bits ((.|.), shiftL)
@@ -20,9 +20,10 @@ import Data.ByteString (ByteString)
2020import Data.Char (chr)
2121import Data.List (sort)
2222import Data.Monoid (mappend, mempty)
23+import Data.Scientific (Scientific)
2324import Data.Text (Text)
2425import Data.Text.Encoding (decodeUtf8')
25−import Data.Vector as Vector (Vector, fromList)
26+import Data.Vector as Vector (Vector, foldl', fromList)
2627import Data.Word (Word8)
2728import System.Directory (getDirectoryContents)
2829import System.FilePath ((</>), dropExtension)
@@ -51,6 +52,34 @@ import Criterion.Main
5152#define C_n 110
5253#define C_t 116
5354
55+data Result a = Error String
56+ | Success a
57+ deriving (Eq, Show)
58+
59+
60+-- | A JSON \"object\" (key\/value map).
61+type Object = H.HashMap Text Value
62+
63+-- | A JSON \"array\" (sequence).
64+type Array = Vector Value
65+
66+-- | A JSON value represented as a Haskell value.
67+data Value = Object !Object
68+ | Array !Array
69+ | String !Text
70+ | Number !Scientific
71+ | Bool !Bool
72+ | Null
73+ deriving (Eq, Show)
74+
75+instance NFData Value where
76+ rnf (Object o) = rnf o
77+ rnf (Array a) = Vector.foldl' (\x y -> rnf y `seq` x) () a
78+ rnf (String s) = rnf s
79+ rnf (Number n) = rnf n
80+ rnf (Bool b) = rnf b
81+ rnf Null = ()
82+
5483-- | Parse a top-level JSON value. This must be either an object or
5584-- an array, per RFC 4627.
5685--
benchmarks/attoparsec-benchmarks.cabal−1
@@ -17,7 +17,6 @@ executable attoparsec-benchmarks
1717 hs-source-dirs: .. .
1818 ghc-options: -O2 -Wall
1919 build-depends:
20− aeson,
2120 array,
2221 base == 4.*,
2322 bytestring >= 0.10.4.0,