@@ -75,6 +75,8 @@ import qualified Data.HashMap.Strict as H
75#define C_F 70
75#define C_F 70
76#define C_a 97
76#define C_a 97
77#define C_f 102
77#define C_f 102
79-- | Parse a top-level JSON value. This must be either an object or
81-- | Parse a top-level JSON value. This must be either an object or
80-- an array, per RFC 4627.
82-- an array, per RFC 4627.
@@ -162,18 +164,18 @@ arrayValues val = do
162-- implementations in other languages conform to that same restriction
164-- implementations in other languages conform to that same restriction
163-- to preserve interoperability and security.
165-- to preserve interoperability and security.
164value :: Parser Value
166value :: Parser Value
165−value = most <|> (Number <$> rational)
167+value = do
166− where
168+ w <- A.peekWord8'
168− c <- satisfy (`B8.elem` "{[\"ftn")
169− case c of
169+ case w of
172− '"' -> String <$> jstring_
170+ DOUBLE_QUOTE -> char '"' *> (String <$> jstring_)
171+ OPEN_CURLY -> char '{' *> object_
172+ OPEN_SQUARE -> char '[' *> array_
173− 'f' -> string "alse" *> pure (Bool False)
173+ C_f -> string "false" *> pure (Bool False)
174− 't' -> string "rue" *> pure (Bool True)
174+ C_t -> string "true" *> pure (Bool True)
175− 'n' -> string "ull" *> pure Null
175+ C_n -> string "null" *> pure Null
176− _ -> error "attoparsec panic! the impossible happened!"
176+ _ | w >= 48 && w <= 57 || w == 45
177+ -> Number <$> rational
178+ | otherwise -> fail "not a valid json value"
178-- | Strict version of 'value'. See also 'json''.
180-- | Strict version of 'value'. See also 'json''.
179value' :: Parser Value
181value' :: Parser Value