yaml 0.6.0 → 0.6.1
raw patch · 2 files changed
+14/−5 lines, 2 files
Files
- Data/Yaml.hs +13/−4
- yaml.cabal +1/−1
Data/Yaml.hs view
@@ -31,6 +31,8 @@ , encodeFile , decode , decodeFile+ -- ** Better error information+ , decodeEither ) where import qualified Text.Libyaml as Y@@ -231,16 +233,23 @@ decode :: FromJSON a => ByteString -> Maybe a-decode bs = unsafePerformIO $ fmap (either (const Nothing) id) $ decodeHelper (Y.decode bs)+decode bs = unsafePerformIO+ $ fmap (either (const Nothing) (either (const Nothing) Just))+ $ decodeHelper (Y.decode bs) decodeFile :: FromJSON a => FilePath -> IO (Maybe a)-decodeFile fp = decodeHelper (Y.decodeFile fp) >>= either throwIO return+decodeFile fp = decodeHelper (Y.decodeFile fp) >>= either throwIO (return . either (const Nothing) id) +decodeEither :: FromJSON a => ByteString -> Either String a+decodeEither bs = unsafePerformIO+ $ fmap (either (Left . show) id)+ $ decodeHelper (Y.decode bs)+ decodeHelper :: FromJSON a => C.Source Parse Y.Event- -> IO (Either ParseException (Maybe a))+ -> IO (Either ParseException (Either String a)) decodeHelper src = do x <- try $ C.runResourceT $ flip evalStateT Map.empty $ src C.$$ parse case x of@@ -248,7 +257,7 @@ | Just pe <- fromException e -> return $ Left pe | Just ye <- fromException e -> return $ Left $ InvalidYaml $ Just $ show (ye :: YamlException) | otherwise -> throwIO e- Right y -> return $ Right $ parseMaybe parseJSON y+ Right y -> return $ Right $ parseEither parseJSON y array :: [Value] -> Value array = Array . V.fromList
yaml.cabal view
@@ -1,5 +1,5 @@ name: yaml-version: 0.6.0+version: 0.6.1 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov