@@ -70,11 +70,11 @@ import qualified Data.ByteString.Lazy.Char8 as C
7070import qualified Data.ByteString.Unsafe as B
7171import qualified Data.Scientific as Sci
7272import qualified Data.Vector as Vector (empty , fromList , fromListN , reverse )
73+ import qualified Data.Word8.Patterns as W8
7374
7475import Data.Aeson.Types (IResult (.. ), JSONPath , Object , Result (.. ), Value (.. ), Key )
7576import Data.Aeson.Internal.Text
7677import 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)
142142objectValues 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)
176176arrayValues 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.
314314jstring :: Parser Text
315- jstring = A. word8 W8_DOUBLE_QUOTE *> jstring_
315+ jstring = A. word8 W8. DOUBLE_QUOTE *> jstring_
316316
317317-- | Parse a JSON Key
318318key :: Parser Key
@@ -322,11 +322,11 @@ key = Key.fromText <$> jstring
322322jstring_ :: Parser Text
323323{-# INLINE jstring_ #-}
324324jstring_ = 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
348348decodeWith :: 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.
440440skipSpace :: 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
449449decimal0 :: Parser Integer
450450decimal0 = 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.
457457scientific :: Parser Scientific
458458scientific = 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 #-}
0 commit comments