Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update haskell/Lich.hs

Pretty up error messages.
  • Loading branch information...
commit c566ccc25a0f96c5dd066f9471149e0d02ddb11e 1 parent da79944
@cbarrett cbarrett authored
Showing with 5 additions and 5 deletions.
  1. +5 −5 haskell/Lich.hs
View
10 haskell/Lich.hs
@@ -33,17 +33,17 @@ parseElement = try parseData <|> try parseArray <|> try parseDict
parseData = do
size <- parseSize
- data' <- between (char '<') (char '>') $ count size anyChar
+ data' <- between (char '<') (char '>' <?> "closing marker") (count size anyChar <?> "incomplete data")
return $ Data (C.pack data')
parseArray = do
size <- parseSize
- text <- between (char '[') (char ']') $ C.pack <$> count size anyChar
+ text <- between (char '[') (char ']' <?> "closing marker") (C.pack <$> count size anyChar <?> "incomplete data")
Array <$> recurWith parseElement text
parseDict = do
size <- parseSize
- elems <- between (char '{') (char '}') $ C.pack <$> count size anyChar
+ elems <- between (char '{') (char '}' <?> "closing marker") (C.pack <$> count size anyChar <?> "incomplete data")
Dict <$> M.fromList <$> recurWith parseKey elems
parseKey :: Parser (LichData, Lich)
@@ -53,7 +53,7 @@ parseKey = liftM2 (,) parseDataRaw parseElement
go x = unexpected (show x)
parseSize :: Parser Int
-parseSize = read <$> (some digit)
+parseSize = read <$> (some digit) <?> "size prefix"
lichTest :: String -> IO ()
lichTest s = parseTest parseDocument $ C.pack s
@@ -72,4 +72,4 @@ prettyLich (Dict m) = docLength contents <> braces contents
go (k, v) = prettyLich (Data k) <> prettyLich v
docLength = P.int . length . P.render
-angleBrackets d = P.char '<' <> d <> P.char '>'
+angleBrackets d = P.char '<' <> d <> P.char '>'
Please sign in to comment.
Something went wrong with that request. Please try again.