on master help sign in
An obvious simplification that potentially lets us avoid backtracking
commit018ff4cc7f61f52a404c992533bc811a92e10728 authorBryan O'Sullivan <bos@mailrank.com> dateTue 24 May 2011, 16:12 (15 years ago) parent914bed2
1 file changed+3−2
Data/Aeson/Parser.hs+3−2
Data/Aeson/Parser.hs+3−2
@@ -33,6 +33,7 @@ import Data.Vector as Vector hiding ((++))
3333import Data.Word (Word8)
3434import qualified Data.Attoparsec as A
3535import qualified Data.Attoparsec.Zepto as Z
36+import qualified Data.ByteString.Char8 as B8
3637import qualified Data.ByteString.Unsafe as B
3738
3839-- | Parse a top-level JSON value. This must be either an object or
@@ -67,7 +68,7 @@ value :: Parser Value
6768value = most <|> (Number <$> number)
6869 where
6970 most = do
70− c <- anyChar
71+ c <- satisfy (`B8.elem` "{[\"ftn")
7172 case c of
7273 '{' -> object_
7374 '[' -> array_
@@ -75,7 +76,7 @@ value = most <|> (Number <$> number)
7576 'f' -> string "alse" *> pure (Bool False)
7677 't' -> string "rue" *> pure (Bool True)
7778 'n' -> string "ull" *> pure Null
78− _ -> fail "not a valid JSON value"
79+ _ -> error "attoparsec panic! the impossible happened!"
7980
8081doubleQuote, backslash :: Word8
8182doubleQuote = 34