Skip to content

Commit

Permalink
Cleanups for new version release.
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrap committed Sep 1, 2015
1 parent 1b1cbd0 commit c5ea24c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 34 deletions.
22 changes: 4 additions & 18 deletions Data/JsonStream/Parser.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE TupleSections #-}

-- |
-- Module : Data.JsonStream.Parser
Expand Down Expand Up @@ -43,7 +43,6 @@ module Data.JsonStream.Parser (
-- * FromJSON parser
, value
, string
, bytestring
-- * Constant space parsers
, safeString
, number
Expand Down Expand Up @@ -82,8 +81,7 @@ import qualified Data.HashMap.Strict as HMap
import Data.Scientific (Scientific, isInteger,
toBoundedInteger, toRealFloat)
import qualified Data.Text as T
import Data.Text.Encoding (encodeUtf8)
import Data.Text.Encoding (decodeUtf8')
import Data.Text.Encoding (decodeUtf8')
import qualified Data.Vector as Vec

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

-- | Match string as a ByteString without decoding the data from UTF8 and unescaping the contents
-- (strings larger than input chunk, small get always decoded).
bytestring :: Parser BL.ByteString
bytestring = Parser $ moreData (handle [])
where
handle acc tok el ntok =
case el of
JValue (AE.String str) -> Yield (BL.fromChunks [encodeUtf8 str]) (Done "" ntok)
StringContent str -> moreData (handle (str:acc)) ntok
StringEnd -> Yield (BL.fromChunks $ reverse acc) (Done "" ntok)
_ -> callParse ignoreVal tok


-- | Parse string value, skip parsing otherwise.
string :: Parser T.Text
string = longString Nothing

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

Expand Down
10 changes: 2 additions & 8 deletions benchmarks/aeson-benchmarks.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ build-type: Simple

cabal-version: >=1.8

flag old-locale
description: If false then depend on time >= 1.5.
.
If true then depend on time < 1.5 together with old-locale.
default: False

library
hs-source-dirs: ..
c-sources: ../c_lib/lexer.c, ../c_lib/unescape_string.c
Expand All @@ -27,7 +21,7 @@ library
build-depends: base >=4.7 && <4.9
, bytestring
, text
, aeson (>=0.9)
, aeson (>=0.7)
, vector
, unordered-containers
, scientific
Expand All @@ -39,7 +33,7 @@ executable aeson-benchmark-jstream-parse
ghc-options: -Wall -O2 -rtsopts
build-depends:
aeson-benchmarks,
aeson (>=0.9),
aeson (>=0.7),
base,
bytestring,
time
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.3.2.0
- Changed string parsing; parsing of escaped strings is now very vast
- Removed bytestring parser

# 0.3.0.4
- Fixed bug in safestring
- Fixed test so it doesn't depend on versions of other packages
Expand Down
6 changes: 4 additions & 2 deletions json-stream.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json-stream
version: 0.3.1.0
version: 0.3.2.0
synopsis: Incremental applicative JSON parser
description: Easy to use JSON parser fully supporting incremental parsing.
Parsing grammar in applicative form.
Expand Down Expand Up @@ -36,12 +36,13 @@ library
build-depends: base >=4.7 && <4.9
, bytestring
, text
, aeson
, aeson >= 0.7
, vector
, unordered-containers
, scientific
default-language: Haskell2010


test-suite spec
main-is: Spec.hs
other-modules: Data.JsonStream.CLexType, ParserSpec
Expand All @@ -51,6 +52,7 @@ test-suite spec
type: exitcode-stdio-1.0
hs-source-dirs: test, .
default-language: Haskell2010
ghc-options: -Wall
build-depends: base >=4.7 && <4.9
, bytestring
, text
Expand Down
10 changes: 4 additions & 6 deletions test/ParserSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ import Data.Aeson (Value(..))
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy as BL
import qualified Data.Text as T
import Data.Text.Encoding (encodeUtf8)
import Control.Monad (forM_)
import Data.Text.Encoding (encodeUtf8)
import qualified Data.Vector as Vec
import qualified Data.HashMap.Strict as HMap
import System.Directory (getDirectoryContents)

import Data.JsonStream.Parser
import Data.JsonStream.TokenParser
import Data.JsonStream.CLexer

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


parse :: Parser a -> BS.ByteString -> [a]
parse parser text = parseByteString parser (todquotes text)

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

readBenchFiles :: FilePath -> IO [BS.ByteString]
readBenchFiles dirname =
getDirectoryContents dirname >>= return . (filter isJson) >>= mapM readFile
getDirectoryContents dirname >>= return . (filter isJson) >>= mapM readFile'
where
readFile fname = BS.readFile (dirname ++ "/" ++ fname)
readFile' fname = BS.readFile (dirname ++ "/" ++ fname)
isJson fname = take 5 (reverse fname) == "nosj."

aeCompareBench :: Spec
Expand Down

0 comments on commit c5ea24c

Please sign in to comment.