Bryan O'Sullivan committed 48827b2

An obvious simplification that potentially lets us avoid backtracking

Comments (0)

Files changed (1)


 import Data.Word (Word8)
 import qualified Data.Attoparsec as A
 import qualified Data.Attoparsec.Zepto as Z
+import qualified Data.ByteString.Char8 as B8
 import qualified Data.ByteString.Unsafe as B
 -- | Parse a top-level JSON value.  This must be either an object or
 value = most <|> (Number <$> number)
   most = do
-    c <- anyChar
+    c <- satisfy (`B8.elem` "{[\"ftn")
     case c of
       '{' -> object_
       '[' -> array_
       'f' -> string "alse" *> pure (Bool False)
       't' -> string "rue" *> pure (Bool True)
       'n' -> string "ull" *> pure Null
-      _   -> fail "not a valid JSON value"
+      _   -> error "attoparsec panic! the impossible happened!"
 doubleQuote, backslash :: Word8
 doubleQuote = 34
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.