yaml 0.8.10.1 → 0.8.11
raw patch · 5 files changed
+52/−9 lines, 5 files
Files
- ChangeLog.md +4/−0
- Data/Yaml.hs +1/−0
- Data/Yaml/Internal.hs +41/−1
- exe/yaml2json.hs +5/−7
- yaml.cabal +1/−1
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.8.11++* Function to print prettier parse exceptions [#59](https://github.com/snoyberg/yaml/pull/59)+ ## 0.8.10 Add the Data.Yaml.Include module
Data/Yaml.hs view
@@ -24,6 +24,7 @@ , Object , Array , ParseException(..)+ , prettyPrintParseException , YamlException (..) , YamlMark (..) -- * Constructors and accessors
Data/Yaml/Internal.hs view
@@ -5,6 +5,7 @@ module Data.Yaml.Internal ( ParseException(..)+ , prettyPrintParseException , parse , decodeHelper , decodeHelper_@@ -52,7 +53,46 @@ | NonStringKeyAlias Y.AnchorName Value | CyclicIncludes deriving (Show, Typeable)-instance Exception ParseException++instance Exception ParseException where+#if MIN_VERSION_base(4, 8, 0)+ displayException = prettyPrintParseException+#endif++-- | Alternative to 'show' to display a 'ParseException' on the screen.+-- Instead of displaying the data constructors applied to their arguments,+-- a more textual output is returned. For example, instead of printing:+--+-- > AesonException "The key \"foo\" was not found"+--+-- It looks more pleasant to print:+--+-- > Aeson exception: The key "foo" was not found+--+-- Since 0.8.11+prettyPrintParseException :: ParseException -> String+prettyPrintParseException NonScalarKey = "Non scalar key"+prettyPrintParseException (UnknownAlias n) =+ "Unknown alias: " ++ n+prettyPrintParseException (UnexpectedEvent r e) = unlines+ [ "Unexpected event:"+ , " Received: " ++ maybe "None" show r+ , " Expected: " ++ maybe "None" show e+ ]+prettyPrintParseException (InvalidYaml mye) =+ case mye of+ Just ye -> "Invalid yaml: " ++ show ye+ _ -> "Invalid yaml"+prettyPrintParseException (AesonException e) =+ "Aeson exception: " ++ e+prettyPrintParseException (OtherParseException e) =+ "Parse exception: " ++ show e+prettyPrintParseException (NonStringKeyAlias n v) = unlines+ [ "Non-string key alias:"+ , " Anchor name: " ++ n+ , " Value: " ++ show v + ]+prettyPrintParseException CyclicIncludes = "Cyclic includes" newtype PErrorT m a = PErrorT { runPErrorT :: m (Either ParseException a) } instance Monad m => Functor (PErrorT m) where
exe/yaml2json.hs view
@@ -1,5 +1,3 @@-{-# LANGUAGE ScopedTypeVariables #-}- import Data.Yaml (decodeFileEither, decodeEither') import System.Environment (getArgs) import System.Exit@@ -11,18 +9,18 @@ helpMessage :: IO () helpMessage = putStrLn "yaml2json FILE\n use - as FILE to indicate stdin" >> exitFailure +showJSON :: Show a => Either a Value -> IO b showJSON ejson = case ejson of Left err -> print err >> exitFailure- Right (res :: Value) -> putStr (encode res) >> exitSuccess+ Right res -> putStr (encode (res :: Value)) >> exitSuccess main :: IO () main = do args <- getArgs case args of- [] -> helpMessage- (f:a:_) -> helpMessage -- strict getContents will read in all of stdin at once- ("-":[]) -> getContents >>= showJSON . decodeEither'- (f:[]) -> decodeFileEither f >>= showJSON+ (["-"]) -> getContents >>= showJSON . decodeEither'+ ([f]) -> decodeFileEither f >>= showJSON+ _ -> helpMessage
yaml.cabal view
@@ -1,5 +1,5 @@ name: yaml-version: 0.8.10.1+version: 0.8.11 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov