Skip to content

Commit c5ea24c

Browse files
committed
Cleanups for new version release.
1 parent 1b1cbd0 commit c5ea24c

File tree

5 files changed

+18
-34
lines changed

5 files changed

+18
-34
lines changed

Data/JsonStream/Parser.hs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{-# LANGUAGE BangPatterns #-}
22
{-# LANGUAGE OverloadedStrings #-}
3-
{-# LANGUAGE TupleSections #-}
43
{-# LANGUAGE PatternGuards #-}
4+
{-# LANGUAGE TupleSections #-}
55

66
-- |
77
-- Module : Data.JsonStream.Parser
@@ -43,7 +43,6 @@ module Data.JsonStream.Parser (
4343
-- * FromJSON parser
4444
, value
4545
, string
46-
, bytestring
4746
-- * Constant space parsers
4847
, safeString
4948
, number
@@ -82,8 +81,7 @@ import qualified Data.HashMap.Strict as HMap
8281
import Data.Scientific (Scientific, isInteger,
8382
toBoundedInteger, toRealFloat)
8483
import qualified Data.Text as T
85-
import Data.Text.Encoding (encodeUtf8)
86-
import Data.Text.Encoding (decodeUtf8')
84+
import Data.Text.Encoding (decodeUtf8')
8785
import qualified Data.Vector as Vec
8886

8987
import Data.JsonStream.CLexer
@@ -377,25 +375,13 @@ longString mbounds = Parser $ moreData (handle [] 0)
377375
| otherwise -> Failed "Error decoding UTF8"
378376
_ -> callParse ignoreVal tok
379377

380-
-- | Match string as a ByteString without decoding the data from UTF8 and unescaping the contents
381-
-- (strings larger than input chunk, small get always decoded).
382-
bytestring :: Parser BL.ByteString
383-
bytestring = Parser $ moreData (handle [])
384-
where
385-
handle acc tok el ntok =
386-
case el of
387-
JValue (AE.String str) -> Yield (BL.fromChunks [encodeUtf8 str]) (Done "" ntok)
388-
StringContent str -> moreData (handle (str:acc)) ntok
389-
StringEnd -> Yield (BL.fromChunks $ reverse acc) (Done "" ntok)
390-
_ -> callParse ignoreVal tok
391-
392-
393378
-- | Parse string value, skip parsing otherwise.
394379
string :: Parser T.Text
395380
string = longString Nothing
396381

397382
-- | Stops parsing string after the limit is reached. The string will not be matched
398-
-- if it exceeds the size.
383+
-- if it exceeds the size. The size is the size of escaped string including escape
384+
-- characters.
399385
safeString :: Int -> Parser T.Text
400386
safeString limit = longString (Just limit)
401387

benchmarks/aeson-benchmarks.cabal

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ build-type: Simple
44

55
cabal-version: >=1.8
66

7-
flag old-locale
8-
description: If false then depend on time >= 1.5.
9-
.
10-
If true then depend on time < 1.5 together with old-locale.
11-
default: False
12-
137
library
148
hs-source-dirs: ..
159
c-sources: ../c_lib/lexer.c, ../c_lib/unescape_string.c
@@ -27,7 +21,7 @@ library
2721
build-depends: base >=4.7 && <4.9
2822
, bytestring
2923
, text
30-
, aeson (>=0.9)
24+
, aeson (>=0.7)
3125
, vector
3226
, unordered-containers
3327
, scientific
@@ -39,7 +33,7 @@ executable aeson-benchmark-jstream-parse
3933
ghc-options: -Wall -O2 -rtsopts
4034
build-depends:
4135
aeson-benchmarks,
42-
aeson (>=0.9),
36+
aeson (>=0.7),
4337
base,
4438
bytestring,
4539
time

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.3.2.0
2+
- Changed string parsing; parsing of escaped strings is now very vast
3+
- Removed bytestring parser
4+
15
# 0.3.0.4
26
- Fixed bug in safestring
37
- Fixed test so it doesn't depend on versions of other packages

json-stream.cabal

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json-stream
2-
version: 0.3.1.0
2+
version: 0.3.2.0
33
synopsis: Incremental applicative JSON parser
44
description: Easy to use JSON parser fully supporting incremental parsing.
55
Parsing grammar in applicative form.
@@ -36,12 +36,13 @@ library
3636
build-depends: base >=4.7 && <4.9
3737
, bytestring
3838
, text
39-
, aeson
39+
, aeson >= 0.7
4040
, vector
4141
, unordered-containers
4242
, scientific
4343
default-language: Haskell2010
4444

45+
4546
test-suite spec
4647
main-is: Spec.hs
4748
other-modules: Data.JsonStream.CLexType, ParserSpec
@@ -51,6 +52,7 @@ test-suite spec
5152
type: exitcode-stdio-1.0
5253
hs-source-dirs: test, .
5354
default-language: Haskell2010
55+
ghc-options: -Wall
5456
build-depends: base >=4.7 && <4.9
5557
, bytestring
5658
, text

test/ParserSpec.hs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ import Data.Aeson (Value(..))
88
import qualified Data.ByteString.Char8 as BS
99
import qualified Data.ByteString.Lazy as BL
1010
import qualified Data.Text as T
11-
import Data.Text.Encoding (encodeUtf8)
1211
import Control.Monad (forM_)
1312
import Data.Text.Encoding (encodeUtf8)
1413
import qualified Data.Vector as Vec
1514
import qualified Data.HashMap.Strict as HMap
1615
import System.Directory (getDirectoryContents)
1716

1817
import Data.JsonStream.Parser
19-
import Data.JsonStream.TokenParser
20-
import Data.JsonStream.CLexer
2118

2219
-- During the tests the single quotes are replaced with double quotes in the strings as
2320
-- otherwise it would be unreadable in haskell
@@ -28,7 +25,7 @@ todquotes = BS.map squotes
2825
squotes '\'' = '"'
2926
squotes x = x
3027

31-
28+
parse :: Parser a -> BS.ByteString -> [a]
3229
parse parser text = parseByteString parser (todquotes text)
3330

3431
testRemaining :: Parser a -> BS.ByteString -> BS.ByteString
@@ -331,10 +328,11 @@ aeCompare = describe "Compare parsing of strings aeason vs json-stream" $ do
331328
let Just resAeson = AE.decode (BL.fromChunks [test])
332329
resStream `shouldBe` resAeson
333330

331+
readBenchFiles :: FilePath -> IO [BS.ByteString]
334332
readBenchFiles dirname =
335-
getDirectoryContents dirname >>= return . (filter isJson) >>= mapM readFile
333+
getDirectoryContents dirname >>= return . (filter isJson) >>= mapM readFile'
336334
where
337-
readFile fname = BS.readFile (dirname ++ "/" ++ fname)
335+
readFile' fname = BS.readFile (dirname ++ "/" ++ fname)
338336
isJson fname = take 5 (reverse fname) == "nosj."
339337

340338
aeCompareBench :: Spec

0 commit comments

Comments
 (0)