Skip to content

Commit f9a11f3

Browse files
authored
Merge pull request #1078 from haskell/character-ps
Use pattern synonyms from character-ps
2 parents 8901f7a + d64dd4f commit f9a11f3

File tree

10 files changed

+205
-354
lines changed

10 files changed

+205
-354
lines changed

aeson.cabal

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
cabal-version: 2.2
12
name: aeson
2-
version: 2.2.1.0
3-
x-revision: 1
4-
license: BSD3
3+
version: 2.2.2.0
4+
license: BSD-3-Clause
55
license-file: LICENSE
66
category: Text, Web, JSON
77
copyright:
@@ -24,7 +24,6 @@ tested-with:
2424
|| ==9.8.1
2525

2626
synopsis: Fast JSON parsing and encoding
27-
cabal-version: 1.12
2827
homepage: https://github.com/haskell/aeson
2928
bug-reports: https://github.com/haskell/aeson/issues
3029
build-type: Simple
@@ -85,8 +84,6 @@ library
8584
Data.Aeson.Internal.TH
8685
Data.Aeson.Internal.Unescape
8786
Data.Aeson.Internal.UnescapeFromText
88-
Data.Aeson.Internal.Word8
89-
Data.Aeson.Internal.Word16
9087
Data.Aeson.Parser.Time
9188
Data.Aeson.Types.Class
9289
Data.Aeson.Types.FromJSON
@@ -119,7 +116,8 @@ library
119116

120117
-- Other dependencies
121118
build-depends:
122-
data-fix >=0.3.2 && <0.4
119+
, character-ps ^>=0.1
120+
, data-fix >=0.3.2 && <0.4
123121
, dlist >=1.0 && <1.1
124122
, hashable >=1.4.2.0 && <1.5
125123
, indexed-traversable >=0.1.2 && <0.2

attoparsec-aeson/attoparsec-aeson.cabal

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
cabal-version: 1.12
1+
cabal-version: 2.2
22
name: attoparsec-aeson
3-
version: 2.2.0.1
3+
version: 2.2.1.0
44
synopsis: Parsing of aeson's Value with attoparsec
55
description:
66
Parsing of aeson's Value with attoparsec, originally from aeson.
77

8-
license: BSD3
8+
license: BSD-3-Clause
99
license-file: LICENSE
1010
category: Parsing
1111
copyright:
@@ -41,13 +41,13 @@ library
4141
other-modules:
4242
Data.Aeson.Internal.ByteString
4343
Data.Aeson.Internal.Text
44-
Data.Aeson.Internal.Word8
4544

4645
build-depends:
47-
aeson >=2.2.0.0 && <2.3
46+
, aeson >=2.2.0.0 && <2.3
4847
, attoparsec >=0.14.2 && <0.15
4948
, base >=4.10.0.0 && <5
5049
, bytestring >=0.10.8.2 && <0.13
50+
, character-ps ^>=0.1
5151
, integer-conversion >=0.1 && <0.2
5252
, primitive >=0.8.0.0 && <0.10
5353
, scientific >=0.3.7.0 && <0.4

attoparsec-aeson/src/Data/Aeson/Parser/Internal.hs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ import qualified Data.ByteString.Lazy.Char8 as C
7070
import qualified Data.ByteString.Unsafe as B
7171
import qualified Data.Scientific as Sci
7272
import qualified Data.Vector as Vector (empty, fromList, fromListN, reverse)
73+
import qualified Data.Word8.Patterns as W8
7374

7475
import Data.Aeson.Types (IResult(..), JSONPath, Object, Result(..), Value(..), Key)
7576
import Data.Aeson.Internal.Text
7677
import Data.Aeson.Decoding (unescapeText)
77-
import Data.Aeson.Internal.Word8
7878

7979
-- $setup
8080
-- >>> :set -XOverloadedStrings
@@ -142,7 +142,7 @@ objectValues :: ([(Key, Value)] -> Either String Object)
142142
objectValues mkObject str val = do
143143
skipSpace
144144
w <- A.peekWord8'
145-
if w == W8_CLOSE_CURLY
145+
if w == W8.RIGHT_CURLY
146146
then A.anyWord8 >> return KM.empty
147147
else loop []
148148
where
@@ -153,9 +153,9 @@ objectValues mkObject str val = do
153153
loop acc = do
154154
k <- (str A.<?> "object key") <* skipSpace <* (char ':' A.<?> "':'")
155155
v <- (val A.<?> "object value") <* skipSpace
156-
ch <- A.satisfy (\w -> w == W8_COMMA || w == W8_CLOSE_CURLY) A.<?> "',' or '}'"
156+
ch <- A.satisfy (\w -> w == W8.COMMA || w == W8.RIGHT_CURLY) A.<?> "',' or '}'"
157157
let acc' = (k, v) : acc
158-
if ch == W8_COMMA
158+
if ch == W8.COMMA
159159
then skipSpace >> loop acc'
160160
else case mkObject acc' of
161161
Left err -> fail err
@@ -176,14 +176,14 @@ arrayValues :: Parser Value -> Parser (Vector Value)
176176
arrayValues val = do
177177
skipSpace
178178
w <- A.peekWord8'
179-
if w == W8_CLOSE_SQUARE
179+
if w == W8.RIGHT_SQUARE
180180
then A.anyWord8 >> return Vector.empty
181181
else loop [] 1
182182
where
183183
loop acc !len = do
184184
v <- (val A.<?> "json list value") <* skipSpace
185-
ch <- A.satisfy (\w -> w == W8_COMMA || w == W8_CLOSE_SQUARE) A.<?> "',' or ']'"
186-
if ch == W8_COMMA
185+
ch <- A.satisfy (\w -> w == W8.COMMA || w == W8.RIGHT_SQUARE) A.<?> "',' or ']'"
186+
if ch == W8.COMMA
187187
then skipSpace >> loop (v:acc) (len+1)
188188
else return (Vector.reverse (Vector.fromListN len (v:acc)))
189189
{-# INLINE arrayValues #-}
@@ -230,13 +230,13 @@ jsonWith mkObject = fix $ \value_ -> do
230230
skipSpace
231231
w <- A.peekWord8'
232232
case w of
233-
W8_DOUBLE_QUOTE -> A.anyWord8 *> (String <$> jstring_)
234-
W8_OPEN_CURLY -> A.anyWord8 *> object_ mkObject value_
235-
W8_OPEN_SQUARE -> A.anyWord8 *> array_ value_
236-
W8_f -> string "false" $> Bool False
237-
W8_t -> string "true" $> Bool True
238-
W8_n -> string "null" $> Null
239-
_ | w >= W8_0 && w <= W8_9 || w == W8_MINUS
233+
W8.DOUBLE_QUOTE -> A.anyWord8 *> (String <$> jstring_)
234+
W8.LEFT_CURLY -> A.anyWord8 *> object_ mkObject value_
235+
W8.LEFT_SQUARE -> A.anyWord8 *> array_ value_
236+
W8.LOWER_F -> string "false" $> Bool False
237+
W8.LOWER_T -> string "true" $> Bool True
238+
W8.LOWER_N -> string "null" $> Null
239+
_ | w >= W8.DIGIT_0 && w <= W8.DIGIT_9 || w == W8.HYPHEN
240240
-> Number <$> scientific
241241
| otherwise -> fail "not a valid json value"
242242
{-# INLINE jsonWith #-}
@@ -282,15 +282,15 @@ jsonWith' mkObject = fix $ \value_ -> do
282282
skipSpace
283283
w <- A.peekWord8'
284284
case w of
285-
W8_DOUBLE_QUOTE -> do
285+
W8.DOUBLE_QUOTE -> do
286286
!s <- A.anyWord8 *> jstring_
287287
return (String s)
288-
W8_OPEN_CURLY -> A.anyWord8 *> object_' mkObject value_
289-
W8_OPEN_SQUARE -> A.anyWord8 *> array_' value_
290-
W8_f -> string "false" $> Bool False
291-
W8_t -> string "true" $> Bool True
292-
W8_n -> string "null" $> Null
293-
_ | w >= W8_0 && w <= W8_9 || w == W8_MINUS
288+
W8.LEFT_CURLY -> A.anyWord8 *> object_' mkObject value_
289+
W8.LEFT_SQUARE -> A.anyWord8 *> array_' value_
290+
W8.LOWER_F -> string "false" $> Bool False
291+
W8.LOWER_T -> string "true" $> Bool True
292+
W8.LOWER_N -> string "null" $> Null
293+
_ | w >= W8.DIGIT_0 && w <= W8.DIGIT_9 || w == W8.HYPHEN
294294
-> do
295295
!n <- scientific
296296
return (Number n)
@@ -312,7 +312,7 @@ jsonNoDup' = jsonWith' parseListNoDup
312312

313313
-- | Parse a quoted JSON string.
314314
jstring :: Parser Text
315-
jstring = A.word8 W8_DOUBLE_QUOTE *> jstring_
315+
jstring = A.word8 W8.DOUBLE_QUOTE *> jstring_
316316

317317
-- | Parse a JSON Key
318318
key :: Parser Key
@@ -322,11 +322,11 @@ key = Key.fromText <$> jstring
322322
jstring_ :: Parser Text
323323
{-# INLINE jstring_ #-}
324324
jstring_ = do
325-
s <- A.takeWhile (\w -> w /= W8_DOUBLE_QUOTE && w /= W8_BACKSLASH && w >= 0x20 && w < 0x80)
325+
s <- A.takeWhile (\w -> w /= W8.DOUBLE_QUOTE && w /= W8.BACKSLASH && w >= 0x20 && w < 0x80)
326326
mw <- A.peekWord8
327327
case mw of
328328
Nothing -> fail "string without end"
329-
Just W8_DOUBLE_QUOTE -> A.anyWord8 $> unsafeDecodeASCII s
329+
Just W8.DOUBLE_QUOTE -> A.anyWord8 $> unsafeDecodeASCII s
330330
Just w | w < 0x20 -> fail "unescaped control character"
331331
_ -> jstringSlow s
332332

@@ -341,8 +341,8 @@ jstringSlow s' = do
341341
startState = False
342342
go a c
343343
| a = Just False
344-
| c == W8_DOUBLE_QUOTE = Nothing
345-
| otherwise = let a' = c == W8_BACKSLASH
344+
| c == W8.DOUBLE_QUOTE = Nothing
345+
| otherwise = let a' = c == W8.BACKSLASH
346346
in Just a'
347347

348348
decodeWith :: Parser Value -> (Value -> Result a) -> L.ByteString -> Maybe a
@@ -438,7 +438,7 @@ jsonEOF' = json' <* skipSpace <* endOfInput
438438
-- | The only valid whitespace in a JSON document is space, newline,
439439
-- carriage return, and tab.
440440
skipSpace :: Parser ()
441-
skipSpace = A.skipWhile $ \w -> w == W8_SPACE || w == W8_NL || w == W8_CR || w == W8_TAB
441+
skipSpace = A.skipWhile $ \w -> w == W8.SPACE || w == W8.LF || w == W8.CR || w == W8.TAB
442442
{-# INLINE skipSpace #-}
443443

444444
------------------ Copy-pasted and adapted from attoparsec ------------------
@@ -449,33 +449,33 @@ data SP = SP !Integer {-# UNPACK #-}!Int
449449
decimal0 :: Parser Integer
450450
decimal0 = do
451451
digits <- A.takeWhile1 isDigit_w8
452-
if B.length digits > 1 && B.unsafeHead digits == W8_0
452+
if B.length digits > 1 && B.unsafeHead digits == W8.DIGIT_0
453453
then fail "leading zero"
454454
else return (byteStringToInteger digits)
455455

456456
-- | Parse a JSON number.
457457
scientific :: Parser Scientific
458458
scientific = do
459459
sign <- A.peekWord8'
460-
let !positive = not (sign == W8_MINUS)
461-
when (sign == W8_PLUS || sign == W8_MINUS) $
460+
let !positive = not (sign == W8.HYPHEN)
461+
when (sign == W8.PLUS || sign == W8.HYPHEN) $
462462
void A.anyWord8
463463

464464
n <- decimal0
465465

466466
let f fracDigits = SP (B.foldl' step n fracDigits)
467467
(negate $ B.length fracDigits)
468-
step a w = a * 10 + fromIntegral (w - W8_0)
468+
step a w = a * 10 + fromIntegral (w - W8.DIGIT_0)
469469

470470
dotty <- A.peekWord8
471471
SP c e <- case dotty of
472-
Just W8_DOT -> A.anyWord8 *> (f <$> A.takeWhile1 isDigit_w8)
473-
_ -> pure (SP n 0)
472+
Just W8.PERIOD -> A.anyWord8 *> (f <$> A.takeWhile1 isDigit_w8)
473+
_ -> pure (SP n 0)
474474

475475
let !signedCoeff | positive = c
476476
| otherwise = -c
477477

478-
(A.satisfy (\ex -> case ex of W8_e -> True; W8_E -> True; _ -> False) *>
478+
(A.satisfy (\ex -> case ex of W8.LOWER_E -> True; W8.UPPER_E -> True; _ -> False) *>
479479
fmap (Sci.scientific signedCoeff . (e +)) (signed decimal)) <|>
480480
return (Sci.scientific signedCoeff e)
481481
{-# INLINE scientific #-}

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
For the latest version of this document, please see [https://github.com/haskell/aeson/blob/master/changelog.md](https://github.com/haskell/aeson/blob/master/changelog.md).
22

3+
### next
4+
5+
* Depend on `character-ps` instead of defining own Word8 pattern synonyms
6+
37
### 2.2.1.0
48

59
* Add `Data.Aeson.RFC8785`, a JSON Canonicalization Scheme implementation

0 commit comments

Comments
 (0)