@@ -5,6 +5,7 @@
5module Data.Yaml.Internal
5module Data.Yaml.Internal
7 ParseException(..)
7 ParseException(..)
8+ , prettyPrintParseException
9 , decodeHelper
10 , decodeHelper
10 , decodeHelper_
11 , decodeHelper_
@@ -52,7 +53,11 @@ data ParseException = NonScalarKey
52 | NonStringKeyAlias Y.AnchorName Value
53 | NonStringKeyAlias Y.AnchorName Value
53 | CyclicIncludes
54 | CyclicIncludes
54 deriving (Show, Typeable)
55 deriving (Show, Typeable)
55−instance Exception ParseException
57+instance Exception ParseException where
58+#if MIN_VERSION_base(4, 8, 0)
59+ displayException = prettyPrintParseException
57-- | Alternative to 'show' to display a 'ParseException' on the screen.
62-- | Alternative to 'show' to display a 'ParseException' on the screen.
58-- Instead of displaying the data constructors applied to their arguments,
63-- Instead of displaying the data constructors applied to their arguments,
@@ -66,15 +71,16 @@ instance Exception ParseException
67prettyPrintParseException :: ParseException -> String
72prettyPrintParseException :: ParseException -> String
68prettyPrintParseException NonScalarKey = "Non scalar key"
73prettyPrintParseException NonScalarKey = "Non scalar key"
69−prettyPrintParseException InvalidYaml mye =
74+prettyPrintParseException (InvalidYaml mye) =
70 case mye of
75 case mye of
71 Just ye -> "Invalid yaml: " ++ show ye
76 Just ye -> "Invalid yaml: " ++ show ye
72 _ -> "Invalid yaml"
77 _ -> "Invalid yaml"
73prettyPrintParseException (AesonException e) =
78prettyPrintParseException (AesonException e) =
74 "Aeson exception: " ++ e
79 "Aeson exception: " ++ e
80+prettyPrintParseException CyclicIncludes = "Cyclic includes"
81+prettyPrintParseException (OtherParseException e) =
82+ "Parse exception: " ++ show e
75prettyPrintParseException pe = show pe
83prettyPrintParseException pe = show pe
76−-- TODO: This is just a stab at the implementation.
77−-- If the idea is likely to be merged, I can develop it further.
79newtype PErrorT m a = PErrorT { runPErrorT :: m (Either ParseException a) }
85newtype PErrorT m a = PErrorT { runPErrorT :: m (Either ParseException a) }
80instance Monad m => Functor (PErrorT m) where
86instance Monad m => Functor (PErrorT m) where