{-# LANGUAGE CPP #-}{-# LANGUAGE RankNTypes #-}moduleData.Yaml.Include(decodeFile ,decodeFileEither ,decodeFileWithWarnings )where #if !MIN_VERSION_directory(1, 2, 3) importControl.Exception(handleJust)importControl.Monad(guard)importSystem.IO.Error(ioeGetFileName,ioeGetLocation,isDoesNotExistError) #endif importControl.Exception(throwIO)importControl.Monad(when)importControl.Monad.IO.Class(liftIO)importControl.Monad.Trans.Resource(MonadResource)importData.Aeson(FromJSON)importData.ConduitimportqualifiedData.Conduit.ListasCLimportData.Text(unpack)importData.Text.Encoding(decodeUtf8)importSystem.DirectoryimportSystem.FilePathimportData.Yaml.Internal (ParseException (..),Warning (..),decodeHelper_ ,decodeHelper )importText.Libyamlhiding(decodeFile)importqualifiedText.LibyamlasYeventsFromFile ::MonadResourcem =>FilePath->ConduitMi Eventm ()eventsFromFile :: forall (m :: * -> *) i. MonadResource m => FilePath -> ConduitM i Event m () eventsFromFile =forall (m :: * -> *) i. MonadResource m => [FilePath] -> FilePath -> ConduitM i Event m () go []wherego ::MonadResourcem =>[FilePath]->FilePath->ConduitMi Eventm ()go :: forall (m :: * -> *) i. MonadResource m => [FilePath] -> FilePath -> ConduitM i Event m () go [FilePath] seen FilePath fp =doFilePath cfp <-forall (m :: * -> *) a. MonadIO m => IO a -> m a liftIOforall a b. (a -> b) -> a -> b $forall {a}. a -> a handleNotFound forall a b. (a -> b) -> a -> b $FilePath -> IO FilePath canonicalizePathFilePath fp forall (f :: * -> *). Applicative f => Bool -> f () -> f () when(FilePath cfp forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool `elem`[FilePath] seen )forall a b. (a -> b) -> a -> b $doforall (m :: * -> *) a. MonadIO m => IO a -> m a liftIOforall a b. (a -> b) -> a -> b $forall e a. Exception e => e -> IO a throwIOParseException CyclicIncludes forall (m :: * -> *) i. MonadResource m => FilePath -> ConduitM i Event m () Y.decodeFileFilePath cfp forall (m :: * -> *) a b c r. Monad m => ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r .|doforall (m :: * -> *) i o r. Monad m => (i -> ConduitT i o m r) -> ConduitT i o m () awaitForeverforall a b. (a -> b) -> a -> b $\Event event ->caseEvent event ofEventScalarByteString f (UriTagFilePath "!include")Style _Anchor _->doletincludeFile :: FilePath includeFile =FilePath -> FilePath takeDirectoryFilePath cfp FilePath -> FilePath -> FilePath </>Text -> FilePath unpack(ByteString -> Text decodeUtf8ByteString f )forall (m :: * -> *) i. MonadResource m => [FilePath] -> FilePath -> ConduitM i Event m () go (FilePath cfp forall a. a -> [a] -> [a] :[FilePath] seen )FilePath includeFile forall (m :: * -> *) a b c r. Monad m => ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r .|forall (m :: * -> *) a. Monad m => (a -> Bool) -> ConduitT a a m () CL.filter(forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool `notElem`[Event] irrelevantEvents )Event _->forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m () yieldEvent event irrelevantEvents :: [Event] irrelevantEvents =[Event EventStreamStart,Event EventDocumentStart,Event EventDocumentEnd,Event EventStreamEnd] #if !MIN_VERSION_directory(1, 2, 3) handleNotFound=handleJust(\e->doguard(isDoesNotExistErrore)guard(ioeGetLocatione=="canonicalizePath")ioeGetFileNamee)(throwIO.YamlException.("Yaml file not found: "++)) #else handleNotFound :: a -> a handleNotFound =forall {a}. a -> a id #endif -- | Like `Data.Yaml.decodeFile` but with support for relative and absolute-- includes.---- The syntax for includes follows the form:---- > somekey: !include ./somefile.yamldecodeFile ::FromJSONa =>FilePath->IO(Maybea )decodeFile :: forall a. FromJSON a => FilePath -> IO (Maybe a) decodeFile FilePath fp =(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmapforall a b. (a, b) -> b sndforall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$>forall a. FromJSON a => ConduitM () Event Parse () -> IO (Either ParseException ([Warning], Either FilePath a)) decodeHelper (forall (m :: * -> *) i. MonadResource m => FilePath -> ConduitM i Event m () eventsFromFile FilePath fp ))forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>=forall a c b. (a -> c) -> (b -> c) -> Either a b -> c eitherforall e a. Exception e => e -> IO a throwIO(forall (m :: * -> *) a. Monad m => a -> m a returnforall b c a. (b -> c) -> (a -> b) -> a -> c .forall a c b. (a -> c) -> (b -> c) -> Either a b -> c either(forall a b. a -> b -> a constforall a. Maybe a Nothing)forall {a}. a -> a id)-- | Like `Data.Yaml.decodeFileEither` but with support for relative and-- absolute includes.---- The syntax for includes follows the form:---- > somekey: !include ./somefile.yamldecodeFileEither ::FromJSONa =>FilePath->IO(EitherParseException a )decodeFileEither :: forall a. FromJSON a => FilePath -> IO (Either ParseException a) decodeFileEither =forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmapforall a b. (a, b) -> b snd)forall b c a. (b -> c) -> (a -> b) -> a -> c .forall a. FromJSON a => FilePath -> IO (Either ParseException ([Warning], a)) decodeFileWithWarnings -- | A version of `decodeFileEither` that returns warnings along with the parse-- result.---- @since 0.10.0decodeFileWithWarnings ::FromJSONa =>FilePath->IO(EitherParseException ([Warning ],a ))decodeFileWithWarnings :: forall a. FromJSON a => FilePath -> IO (Either ParseException ([Warning], a)) decodeFileWithWarnings =forall a. FromJSON a => ConduitM () Event Parse () -> IO (Either ParseException ([Warning], a)) decodeHelper_ forall b c a. (b -> c) -> (a -> b) -> a -> c .forall (m :: * -> *) i. MonadResource m => FilePath -> ConduitM i Event m () eventsFromFile