@@ -70,11 +70,11 @@ import qualified Data.ByteString.Lazy.Char8 as C
70
70
import qualified Data.ByteString.Unsafe as B
71
71
import qualified Data.Scientific as Sci
72
72
import qualified Data.Vector as Vector (empty , fromList , fromListN , reverse )
73
+ import qualified Data.Word8.Patterns as W8
73
74
74
75
import Data.Aeson.Types (IResult (.. ), JSONPath , Object , Result (.. ), Value (.. ), Key )
75
76
import Data.Aeson.Internal.Text
76
77
import Data.Aeson.Decoding (unescapeText )
77
- import Data.Aeson.Internal.Word8
78
78
79
79
-- $setup
80
80
-- >>> :set -XOverloadedStrings
@@ -142,7 +142,7 @@ objectValues :: ([(Key, Value)] -> Either String Object)
142
142
objectValues mkObject str val = do
143
143
skipSpace
144
144
w <- A. peekWord8'
145
- if w == W8_CLOSE_CURLY
145
+ if w == W8. RIGHT_CURLY
146
146
then A. anyWord8 >> return KM. empty
147
147
else loop []
148
148
where
@@ -153,9 +153,9 @@ objectValues mkObject str val = do
153
153
loop acc = do
154
154
k <- (str A. <?> " object key" ) <* skipSpace <* (char ' :' A. <?> " ':'" )
155
155
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 '}'"
157
157
let acc' = (k, v) : acc
158
- if ch == W8_COMMA
158
+ if ch == W8. COMMA
159
159
then skipSpace >> loop acc'
160
160
else case mkObject acc' of
161
161
Left err -> fail err
@@ -176,14 +176,14 @@ arrayValues :: Parser Value -> Parser (Vector Value)
176
176
arrayValues val = do
177
177
skipSpace
178
178
w <- A. peekWord8'
179
- if w == W8_CLOSE_SQUARE
179
+ if w == W8. RIGHT_SQUARE
180
180
then A. anyWord8 >> return Vector. empty
181
181
else loop [] 1
182
182
where
183
183
loop acc ! len = do
184
184
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
187
187
then skipSpace >> loop (v: acc) (len+ 1 )
188
188
else return (Vector. reverse (Vector. fromListN len (v: acc)))
189
189
{-# INLINE arrayValues #-}
@@ -230,13 +230,13 @@ jsonWith mkObject = fix $ \value_ -> do
230
230
skipSpace
231
231
w <- A. peekWord8'
232
232
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
240
240
-> Number <$> scientific
241
241
| otherwise -> fail " not a valid json value"
242
242
{-# INLINE jsonWith #-}
@@ -282,15 +282,15 @@ jsonWith' mkObject = fix $ \value_ -> do
282
282
skipSpace
283
283
w <- A. peekWord8'
284
284
case w of
285
- W8_DOUBLE_QUOTE -> do
285
+ W8. DOUBLE_QUOTE -> do
286
286
! s <- A. anyWord8 *> jstring_
287
287
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
294
294
-> do
295
295
! n <- scientific
296
296
return (Number n)
@@ -312,7 +312,7 @@ jsonNoDup' = jsonWith' parseListNoDup
312
312
313
313
-- | Parse a quoted JSON string.
314
314
jstring :: Parser Text
315
- jstring = A. word8 W8_DOUBLE_QUOTE *> jstring_
315
+ jstring = A. word8 W8. DOUBLE_QUOTE *> jstring_
316
316
317
317
-- | Parse a JSON Key
318
318
key :: Parser Key
@@ -322,11 +322,11 @@ key = Key.fromText <$> jstring
322
322
jstring_ :: Parser Text
323
323
{-# INLINE jstring_ #-}
324
324
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 )
326
326
mw <- A. peekWord8
327
327
case mw of
328
328
Nothing -> fail " string without end"
329
- Just W8_DOUBLE_QUOTE -> A. anyWord8 $> unsafeDecodeASCII s
329
+ Just W8. DOUBLE_QUOTE -> A. anyWord8 $> unsafeDecodeASCII s
330
330
Just w | w < 0x20 -> fail " unescaped control character"
331
331
_ -> jstringSlow s
332
332
@@ -341,8 +341,8 @@ jstringSlow s' = do
341
341
startState = False
342
342
go a c
343
343
| 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
346
346
in Just a'
347
347
348
348
decodeWith :: Parser Value -> (Value -> Result a ) -> L. ByteString -> Maybe a
@@ -438,7 +438,7 @@ jsonEOF' = json' <* skipSpace <* endOfInput
438
438
-- | The only valid whitespace in a JSON document is space, newline,
439
439
-- carriage return, and tab.
440
440
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
442
442
{-# INLINE skipSpace #-}
443
443
444
444
------------------ Copy-pasted and adapted from attoparsec ------------------
@@ -449,33 +449,33 @@ data SP = SP !Integer {-# UNPACK #-}!Int
449
449
decimal0 :: Parser Integer
450
450
decimal0 = do
451
451
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
453
453
then fail " leading zero"
454
454
else return (byteStringToInteger digits)
455
455
456
456
-- | Parse a JSON number.
457
457
scientific :: Parser Scientific
458
458
scientific = do
459
459
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 ) $
462
462
void A. anyWord8
463
463
464
464
n <- decimal0
465
465
466
466
let f fracDigits = SP (B. foldl' step n fracDigits)
467
467
(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 )
469
469
470
470
dotty <- A. peekWord8
471
471
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 )
474
474
475
475
let ! signedCoeff | positive = c
476
476
| otherwise = - c
477
477
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 ) *>
479
479
fmap (Sci. scientific signedCoeff . (e + )) (signed decimal)) <|>
480
480
return (Sci. scientific signedCoeff e)
481
481
{-# INLINE scientific #-}
0 commit comments