on master help sign in
Make it compile with prettyPrintParseException, export this function from Data.Yaml, and implement displayException for recent versions o base.
91203d2Daniel Díaz
Data/Yaml.hs+1
@@ -24,6 +24,7 @@ module Data.Yaml
24 , Object
24 , Object
25 , Array
25 , Array
26 , ParseException(..)
26 , ParseException(..)
27+ , prettyPrintParseException
27 , YamlException (..)
28 , YamlException (..)
28 , YamlMark (..)
29 , YamlMark (..)
29 -- * Constructors and accessors
30 -- * Constructors and accessors
Data/Yaml/Internal.hs+10−4
@@ -5,6 +5,7 @@
5module Data.Yaml.Internal
5module Data.Yaml.Internal
6 (
6 (
7 ParseException(..)
7 ParseException(..)
8+ , prettyPrintParseException
8 , parse
9 , parse
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)
56+
55−instance Exception ParseException
57+instance Exception ParseException where
58+#if MIN_VERSION_base(4, 8, 0)
59+ displayException = prettyPrintParseException
60+#endif
56
61
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
66--
71--
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.
78
84
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