@@ -13,40 +13,36 @@ module Data.Yaml.Internal
1313 , isNumeric
1414 ) where
1515
16−import qualified Text.Libyaml as Y
17−import Data.Aeson
18−import Data.Aeson.Types hiding (parse)
19−import Text.Libyaml hiding (encode, decode, encodeFile, decodeFile)
20−import Data.ByteString (ByteString)
21−import qualified Data.Map as Map
16+#if !MIN_VERSION_base(4,8,0)
17+import Control.Applicative ((<$>), Applicative(..))
18+#endif
2219import Control.Exception
2320import Control.Exception.Enclosed
21+import Control.Monad (liftM, ap, unless)
22+import Control.Monad.IO.Class (MonadIO, liftIO)
23+import Control.Monad.Trans.Class (MonadTrans, lift)
24+import Control.Monad.Trans.Resource (ResourceT, runResourceT)
2425import Control.Monad.Trans.State
26+import Data.Aeson
27+import Data.Aeson.Types hiding (parse)
28+import qualified Data.Attoparsec.Text as Atto
29+import Data.ByteString (ByteString)
30+import Data.Char (toUpper)
2531import qualified Data.Conduit as C
2632import qualified Data.Conduit.List as CL
27−import Control.Monad.Trans.Class (MonadTrans, lift)
28−import Control.Monad.IO.Class (MonadIO, liftIO)
29−import Control.Monad (liftM, ap)
30−#if !MIN_VERSION_base(4,8,0)
31−import Control.Applicative (Applicative(..))
32−#endif
33−import Data.Char (toUpper)
34−import qualified Data.Vector as V
33+import qualified Data.HashMap.Strict as M
34+import qualified Data.HashSet as HashSet
35+import qualified Data.Map as Map
36+import Data.Scientific (Scientific)
3537import Data.Text (Text, pack)
3638import qualified Data.Text as T
3739import Data.Text.Encoding (decodeUtf8With)
3840import Data.Text.Encoding.Error (lenientDecode)
39−import qualified Data.HashMap.Strict as M
4041import Data.Typeable
41−#if MIN_VERSION_aeson(0, 7, 0)
42−import qualified Data.Attoparsec.Text as Atto
43−import Data.Scientific (Scientific)
44−#else
45−import Data.Text.Read
46−import Data.Attoparsec.Number
47−#endif
48−import Control.Monad.Trans.Resource (ResourceT, runResourceT)
49−import qualified Data.HashSet as HashSet
42+import qualified Data.Vector as V
43+
44+import qualified Text.Libyaml as Y
45+import Text.Libyaml hiding (encode, decode, encodeFile, decodeFile)
5046
5147data ParseException = NonScalarKey
5248 | UnknownAlias { _anchorName :: Y.AnchorName }
@@ -131,9 +127,7 @@ type Parse = StateT (Map.Map String Value) (ResourceT IO)
131127requireEvent :: Event -> C.Sink Event Parse ()
132128requireEvent e = do
133129 f <- CL.head
134− if f == Just e
135− then return ()
136− else liftIO $ throwIO $ UnexpectedEvent f $ Just e
130+ unless (f == Just e) $ liftIO $ throwIO $ UnexpectedEvent f $ Just e
137131
138132parse :: C.Sink Event Parse Value
139133parse = do
@@ -163,26 +157,19 @@ textToValue _ _ t
163157 | t `elem` ["null", "Null", "NULL", "~", ""] = Null
164158 | any (t `isLike`) ["y", "yes", "on", "true"] = Bool True
165159 | any (t `isLike`) ["n", "no", "off", "false"] = Bool False
166−#if MIN_VERSION_aeson(0, 7, 0)
167160 | Right x <- textToScientific t = Number x
168−#else
169− | Right (x, "") <- signed decimal t = Number $ I x
170− | Right (x, "") <- double t = Number $ D x
171−#endif
172161 | otherwise = String t
173162 where x `isLike` ref = x `elem` [ref, T.toUpper ref, titleCased]
174163 where titleCased = toUpper (T.head ref) `T.cons` T.tail ref
175164
176−#if MIN_VERSION_aeson(0, 7, 0)
177165textToScientific :: Text -> Either String Scientific
178166textToScientific = Atto.parseOnly (Atto.scientific <* Atto.endOfInput)
179−#endif
180167
181168parseO :: C.Sink Event Parse Value
182169parseO = do
183170 me <- CL.head
184171 case me of
185− Just (EventScalar v tag style a) -> fmap (textToValue style tag) $ parseScalar v a style tag
172+ Just (EventScalar v tag style a) -> textToValue style tag <$> parseScalar v a style tag
186173 Just (EventSequenceStart a) -> parseS a id
187174 Just (EventMappingStart a) -> parseM a M.empty
188175 Just (EventAlias an) -> do