{-# LANGUAGE CPP #-}{-# LANGUAGE ScopedTypeVariables #-}{-# LANGUAGE OverloadedStrings #-}-- | Provides a high-level interface for processing YAML files.---- This module reuses most of the infrastructure from the @aeson@ package.-- This means that you can use all of the existing tools for JSON-- processing for processing YAML files. As a result, much of the-- documentation below mentions JSON; do not let that confuse you, it's-- intentional.---- For the most part, YAML content translates directly into JSON, and-- therefore there is very little data loss. If you need to deal with YAML-- more directly (e.g., directly deal with aliases), you should use the-- "Text.Libyaml" module instead.---- For documentation on the @aeson@ types, functions, classes, and-- operators, please see the @Data.Aeson@ module of the @aeson@ package.---- Look in the examples directory of the source repository for some initial-- pointers on how to use this library.#if (defined (ghcjs_HOST_OS))moduleData.Yaml{-# WARNING "GHCJS is not supported yet (will break at runtime once called)." #-}#elsemoduleData.Yaml#endif(-- * TypesValue(..),Parser,Object,Array,ParseException(..),prettyPrintParseException,YamlException(..),YamlMark(..)-- * Constructors and accessors,object,array,(.=),(.:),(.:?),(.!=)-- * Parsing,parseMonad,parseEither,parseMaybe-- * Classes,ToJSON(..),FromJSON(..)-- * Encoding/decoding,encode,encodeFile,decode,decodeFile-- ** Better error information,decodeEither,decodeEither',decodeFileEither-- ** More control over decoding,decodeHelper)where#if !MIN_VERSION_base(4,8,0)importControl.Applicative((<$>))#endifimportControl.ExceptionimportControl.Monad.Trans.Resource(runResourceT)importData.Aeson(Value(..),ToJSON(..),FromJSON(..),object,(.=),(.:),(.:?),(.!=),Object,Array)importData.Aeson.Encode(encodeToTextBuilder)importData.Aeson.Types(Pair,parseMaybe,parseEither,Parser)importData.ByteString(ByteString)importqualifiedData.ConduitasCimportqualifiedData.Conduit.ListasCLimportqualifiedData.HashMap.StrictasMimportqualifiedData.HashSetasHashSetimportData.Text.Encoding(encodeUtf8)importqualifiedData.Text.EncodingasTEimportqualifiedData.Text.LazyasTLimportData.Text.Lazy.Builder(toLazyText)importqualifiedData.VectorasVimportSystem.IO.Unsafe(unsafePerformIO)importData.Yaml.InternalimportText.Libyamlhiding(encode,decode,encodeFile,decodeFile)importqualifiedText.LibyamlasYencode::ToJSONa=>a->ByteStringencodeobj=unsafePerformIO$runResourceT$CL.sourceList(objToEvents$toJSONobj)C.$$Y.encodeencodeFile::ToJSONa=>FilePath->a->IO()encodeFilefpobj=runResourceT$CL.sourceList(objToEvents$toJSONobj)C.$$Y.encodeFilefpobjToEvents::Value->[Y.Event]objToEventso=(:)EventStreamStart.(:)EventDocumentStart$objToEvents'o[EventDocumentEnd,EventStreamEnd]{- FIXME
scalarToEvent :: YamlScalar -> Event
scalarToEvent (YamlScalar v t s) = EventScalar v t s Nothing
-}objToEvents'::Value->[Y.Event]->[Y.Event]--objToEvents' (Scalar s) rest = scalarToEvent s : restobjToEvents'(Arraylist)rest=EventSequenceStartNothing:foldrobjToEvents'(EventSequenceEnd:rest)(V.toListlist)objToEvents'(Objectpairs)rest=EventMappingStartNothing:foldrpairToEvents(EventMappingEnd:rest)(M.toListpairs)-- Empty strings need special handling to ensure they get quoted. This avoids:-- https://github.com/snoyberg/yaml/issues/24objToEvents'(String"")rest=EventScalar""NoTagSingleQuotedNothing:restobjToEvents'(Strings)rest=event:restwhereevent-- Make sure that special strings are encoded as strings properly.-- See: https://github.com/snoyberg/yaml/issues/31|s`HashSet.member`specialStrings||isNumerics=EventScalar(encodeUtf8s)NoTagSingleQuotedNothing|otherwise=EventScalar(encodeUtf8s)StrTagPlainNoTagNothingobjToEvents'Nullrest=EventScalar"null"NullTagPlainNoTagNothing:restobjToEvents'(BoolTrue)rest=EventScalar"true"BoolTagPlainNoTagNothing:restobjToEvents'(BoolFalse)rest=EventScalar"false"BoolTagPlainNoTagNothing:rest-- Use aeson's implementation which gets rid of annoying decimal pointsobjToEvents'n@Number{}rest=EventScalar(TE.encodeUtf8$TL.toStrict$toLazyText$encodeToTextBuildern)IntTagPlainNoTagNothing:restpairToEvents::Pair->[Y.Event]->[Y.Event]pairToEvents(k,v)rest=EventScalar(encodeUtf8k)StrTagPlainNoTagNothing:objToEvents'vrestdecode::FromJSONa=>ByteString->Maybeadecodebs=unsafePerformIO$either(constNothing)id<$>decodeHelper_(Y.decodebs)decodeFile::FromJSONa=>FilePath->IO(Maybea)decodeFilefp=decodeHelper(Y.decodeFilefp)>>=eitherthrowIO(return.either(constNothing)id)-- | A version of 'decodeFile' which should not throw runtime exceptions.---- Since 0.8.4decodeFileEither::FromJSONa=>FilePath->IO(EitherParseExceptiona)decodeFileEither=decodeHelper_.Y.decodeFiledecodeEither::FromJSONa=>ByteString->EitherStringadecodeEitherbs=unsafePerformIO$either(Left.prettyPrintParseException)id<$>decodeHelper(Y.decodebs)-- | More helpful version of 'decodeEither' which returns the 'YamlException'.---- Since 0.8.3decodeEither'::FromJSONa=>ByteString->EitherParseExceptionadecodeEither'=eitherLeft(either(Left.AesonException)Right).unsafePerformIO.decodeHelper.Y.decodearray::[Value]->Valuearray=Array.V.fromListparseMonad::Monadm=>(a->Parserb)->a->mbparseMonadp=eitherfailreturn.parseEitherp