{-# LANGUAGE CPP #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE Safe #-}
module Data.YAML
(
decode
, decode1
, decodeStrict
, decode1Strict
, FromYAML(..)
, Parser
, parseEither
, failAtNode
, typeMismatch
, Mapping
, (.:), (.:?), (.:!), (.!=)
, encode
, encode1
, encodeStrict
, encode1Strict
, ToYAML(..)
, Pair
, mapping
, (.=)
, withScalar
, withSeq
, withBool
, withFloat
, withInt
, withNull
, withStr
, withMap
, decodeNode
, decodeNode'
, encodeNode
, encodeNode'
, Doc(Doc,docRoot)
, Node(..)
, Scalar(..)
, Pos(..)
, prettyPosWithSource
, SchemaResolver
, failsafeSchemaResolver
, jsonSchemaResolver
, coreSchemaResolver
, SchemaEncoder
, failsafeSchemaEncoder
, jsonSchemaEncoder
, coreSchemaEncoder
, decodeLoader
, Loader(..)
, LoaderT
, NodeId
) where
import qualified Control.Monad.Fail as Fail
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BS.L
import qualified Data.Map as Map
import qualified Data.Text as T
import Data.YAML.Dumper
import Data.YAML.Event (isUntagged, tagToText)
import Data.YAML.Internal
import Data.YAML.Loader
import Data.YAML.Pos
import Data.YAML.Schema.Internal
import Util
(.:) :: FromYAML a => Mapping Pos -> Text -> Parser a
Mapping Pos
m .: :: forall a. FromYAML a => Mapping Pos -> Text -> Parser a
.: Text
k = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail forall a b. (a -> b) -> a -> b
$ [Char]
"key " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Text
k forall a. [a] -> [a] -> [a]
++ [Char]
" not found") forall a. FromYAML a => Node Pos -> Parser a
parseYAML (forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (forall loc. loc -> Scalar -> Node loc
Scalar Pos
fakePos (Text -> Scalar
SStr Text
k)) Mapping Pos
m)
(.:?) :: FromYAML a => Mapping Pos -> Text -> Parser (Maybe a)
Mapping Pos
m .:? :: forall a. FromYAML a => Mapping Pos -> Text -> Parser (Maybe a)
.:? Text
k = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Maybe a
Nothing) forall a. FromYAML a => Node Pos -> Parser a
parseYAML (forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (forall loc. loc -> Scalar -> Node loc
Scalar Pos
fakePos (Text -> Scalar
SStr Text
k)) Mapping Pos
m)
(.:!) :: FromYAML a => Mapping Pos -> Text -> Parser (Maybe a)
Mapping Pos
m .:! :: forall a. FromYAML a => Mapping Pos -> Text -> Parser (Maybe a)
.:! Text
k = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Maybe a
Nothing) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. FromYAML a => Node Pos -> Parser a
parseYAML) (forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (forall loc. loc -> Scalar -> Node loc
Scalar Pos
fakePos (Text -> Scalar
SStr Text
k)) Mapping Pos
m)
(.!=) :: Parser (Maybe a) -> a -> Parser a
Parser (Maybe a)
mv .!= :: forall a. Parser (Maybe a) -> a -> Parser a
.!= a
def = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b a. b -> (a -> b) -> Maybe a -> b
maybe a
def forall a. a -> a
id) Parser (Maybe a)
mv
fakePos :: Pos
fakePos :: Pos
fakePos = Pos { posByteOffset :: Int
posByteOffset = -Int
1 , posCharOffset :: Int
posCharOffset = -Int
1 , posLine :: Int
posLine = Int
1 , posColumn :: Int
posColumn = Int
0 }
decodeNode :: BS.L.ByteString -> Either (Pos, String) [Doc (Node Pos)]
decodeNode :: ByteString -> Either (Pos, [Char]) [Doc (Node Pos)]
decodeNode = SchemaResolver
-> Bool
-> Bool
-> ByteString
-> Either (Pos, [Char]) [Doc (Node Pos)]
decodeNode' SchemaResolver
coreSchemaResolver Bool
False Bool
False
decodeNode' :: SchemaResolver
-> Bool
-> Bool
-> BS.L.ByteString
-> Either (Pos, String) [Doc (Node Pos)]
decodeNode' :: SchemaResolver
-> Bool
-> Bool
-> ByteString
-> Either (Pos, [Char]) [Doc (Node Pos)]
decodeNode' SchemaResolver{Bool
Tag -> Either [Char] Tag
Tag -> ScalarStyle -> Text -> Either [Char] Scalar
schemaResolverMappingDuplicates :: SchemaResolver -> Bool
schemaResolverMapping :: SchemaResolver -> Tag -> Either [Char] Tag
schemaResolverSequence :: SchemaResolver -> Tag -> Either [Char] Tag
schemaResolverScalar :: SchemaResolver
-> Tag -> ScalarStyle -> Text -> Either [Char] Scalar
schemaResolverMappingDuplicates :: Bool
schemaResolverMapping :: Tag -> Either [Char] Tag
schemaResolverSequence :: Tag -> Either [Char] Tag
schemaResolverScalar :: Tag -> ScalarStyle -> Text -> Either [Char] Scalar
..} Bool
anchorNodes Bool
allowCycles ByteString
bs0
= forall a b. (a -> b) -> [a] -> [b]
map forall n. n -> Doc n
Doc forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Identity a -> a
runIdentity (forall n (m :: * -> *).
MonadFix m =>
Loader m n -> ByteString -> m (Either (Pos, [Char]) [n])
decodeLoader Loader Identity (Node Pos)
failsafeLoader ByteString
bs0)
where
failsafeLoader :: Loader Identity (Node Pos)
failsafeLoader = Loader { yScalar :: Tag -> ScalarStyle -> Text -> LoaderT Identity (Node Pos)
yScalar = \Tag
t ScalarStyle
s Text
v Pos
pos-> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ case Tag -> ScalarStyle -> Text -> Either [Char] Scalar
schemaResolverScalar Tag
t ScalarStyle
s Text
v of
Left [Char]
e -> forall a b. a -> Either a b
Left (Pos
pos,[Char]
e)
Right Scalar
v' -> forall a b. b -> Either a b
Right (forall loc. loc -> Scalar -> Node loc
Scalar Pos
pos Scalar
v')
, ySequence :: Tag -> [Node Pos] -> LoaderT Identity (Node Pos)
ySequence = \Tag
t [Node Pos]
vs Pos
pos -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ case Tag -> Either [Char] Tag
schemaResolverSequence Tag
t of
Left [Char]
e -> forall a b. a -> Either a b
Left (Pos
pos,[Char]
e)
Right Tag
t' -> forall a b. b -> Either a b
Right (forall loc. loc -> Tag -> [Node loc] -> Node loc
Sequence Pos
pos Tag
t' [Node Pos]
vs)
, yMapping :: Tag -> [(Node Pos, Node Pos)] -> LoaderT Identity (Node Pos)
yMapping = \Tag
t [(Node Pos, Node Pos)]
kvs Pos
pos-> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ case Tag -> Either [Char] Tag
schemaResolverMapping Tag
t of
Left [Char]
e -> forall a b. a -> Either a b
Left (Pos
pos,[Char]
e)
Right Tag
t' -> forall loc. loc -> Tag -> Mapping loc -> Node loc
Mapping Pos
pos Tag
t' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Node Pos, Node Pos)] -> Either (Pos, [Char]) (Mapping Pos)
mkMap [(Node Pos, Node Pos)]
kvs
, yAlias :: NodeId -> Bool -> Node Pos -> LoaderT Identity (Node Pos)
yAlias = if Bool
allowCycles
then \NodeId
_ Bool
_ Node Pos
n Pos
_-> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a b. b -> Either a b
Right Node Pos
n
else \NodeId
_ Bool
c Node Pos
n Pos
pos -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ if Bool
c then forall a b. a -> Either a b
Left (Pos
pos,[Char]
"cycle detected") else forall a b. b -> Either a b
Right Node Pos
n
, yAnchor :: NodeId -> Node Pos -> LoaderT Identity (Node Pos)
yAnchor = if Bool
anchorNodes
then \NodeId
j Node Pos
n Pos
pos -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a b. b -> Either a b
Right (forall loc. loc -> NodeId -> Node loc -> Node loc
Anchor Pos
pos NodeId
j Node Pos
n)
else \NodeId
_ Node Pos
n Pos
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a b. b -> Either a b
Right Node Pos
n
}
mkMap :: [(Node Pos, Node Pos)] -> Either (Pos, String) (Map (Node Pos) (Node Pos))
mkMap :: [(Node Pos, Node Pos)] -> Either (Pos, [Char]) (Mapping Pos)
mkMap [(Node Pos, Node Pos)]
kvs
| Bool
schemaResolverMappingDuplicates = forall a b. b -> Either a b
Right forall a b. (a -> b) -> a -> b
$! forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Node Pos, Node Pos)]
kvs
| Bool
otherwise = case forall k a. Ord k => [(k, a)] -> Either (k, a) (Map k a)
mapFromListNoDupes [(Node Pos, Node Pos)]
kvs of
Left (Node Pos
k,Node Pos
_) -> forall a b. a -> Either a b
Left (forall loc. Node loc -> loc
nodeLoc Node Pos
k,[Char]
"Duplicate key in mapping: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Node Pos
k)
Right Mapping Pos
m -> forall a b. b -> Either a b
Right Mapping Pos
m
newtype Parser a = P { forall a. Parser a -> Either (Pos, [Char]) a
unP :: Either (Pos, String) a }
instance Functor Parser where
fmap :: forall a b. (a -> b) -> Parser a -> Parser b
fmap a -> b
f (P Either (Pos, [Char]) a
x) = forall a. Either (Pos, [Char]) a -> Parser a
P (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Either (Pos, [Char]) a
x)
a
x <$ :: forall a b. a -> Parser b -> Parser a
<$ P (Right b
_) = forall a. Either (Pos, [Char]) a -> Parser a
P (forall a b. b -> Either a b
Right a
x)
a
_ <$ P (Left (Pos, [Char])
e) = forall a. Either (Pos, [Char]) a -> Parser a
P (forall a b. a -> Either a b
Left (Pos, [Char])
e)
instance Applicative Parser where
pure :: forall a. a -> Parser a
pure = forall a. Either (Pos, [Char]) a -> Parser a
P forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. b -> Either a b
Right
P (Left (Pos, [Char])
e) <*> :: forall a b. Parser (a -> b) -> Parser a -> Parser b
<*> Parser a
_ = forall a. Either (Pos, [Char]) a -> Parser a
P (forall a b. a -> Either a b
Left (Pos, [Char])
e)
P (Right a -> b
f) <*> P Either (Pos, [Char]) a
r = forall a. Either (Pos, [Char]) a -> Parser a
P (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Either (Pos, [Char]) a
r)
P (Left (Pos, [Char])
e) *> :: forall a b. Parser a -> Parser b -> Parser b
*> Parser b
_ = forall a. Either (Pos, [Char]) a -> Parser a
P (forall a b. a -> Either a b
Left (Pos, [Char])
e)
P (Right a
_) *> Parser b
p = Parser b
p
instance Monad Parser where
return :: forall a. a -> Parser a
return = forall (f :: * -> *) a. Applicative f => a -> f a
pure
P Either (Pos, [Char]) a
m >>= :: forall a b. Parser a -> (a -> Parser b) -> Parser b
>>= a -> Parser b
k = forall a. Either (Pos, [Char]) a -> Parser a
P (Either (Pos, [Char]) a
m forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a. Parser a -> Either (Pos, [Char]) a
unP forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Parser b
k)
>> :: forall a b. Parser a -> Parser b -> Parser b
(>>) = forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)
#if !(MIN_VERSION_base(4,13,0))
fail = Fail.fail
#endif
instance Fail.MonadFail Parser where
fail :: forall a. [Char] -> Parser a
fail [Char]
s = forall a. Either (Pos, [Char]) a -> Parser a
P (forall a b. a -> Either a b
Left (Pos
fakePos, [Char]
s))
failAtNode :: Node Pos -> String -> Parser a
failAtNode :: forall a. Node Pos -> [Char] -> Parser a
failAtNode Node Pos
n [Char]
s = forall a. Either (Pos, [Char]) a -> Parser a
P (forall a b. a -> Either a b
Left (forall loc. Node loc -> loc
nodeLoc Node Pos
n, [Char]
s))
instance Alternative Parser where
empty :: forall a. Parser a
empty = forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"empty"
P (Left (Pos, [Char])
_) <|> :: forall a. Parser a -> Parser a -> Parser a
<|> Parser a
y = Parser a
y
Parser a
x <|> Parser a
_ = Parser a
x
instance MonadPlus Parser where
mzero :: forall a. Parser a
mzero = forall (f :: * -> *) a. Alternative f => f a
empty
mplus :: forall a. Parser a -> Parser a -> Parser a
mplus = forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>)
parseEither :: Parser a -> Either (Pos, String) a
parseEither :: forall a. Parser a -> Either (Pos, [Char]) a
parseEither = forall a. Parser a -> Either (Pos, [Char]) a
unP
typeMismatch :: String
-> Node Pos
-> Parser a
typeMismatch :: forall a. [Char] -> Node Pos -> Parser a
typeMismatch [Char]
expected Node Pos
node = forall a. Node Pos -> [Char] -> Parser a
failAtNode Node Pos
node ([Char]
"expected " forall a. [a] -> [a] -> [a]
++ [Char]
expected forall a. [a] -> [a] -> [a]
++ [Char]
" instead of " forall a. [a] -> [a] -> [a]
++ [Char]
got)
where
got :: [Char]
got = case Node Pos
node of
Scalar Pos
_ (SBool Bool
_) -> [Char]
"!!bool"
Scalar Pos
_ (SInt Integer
_) -> [Char]
"!!int"
Scalar Pos
_ Scalar
SNull -> [Char]
"!!null"
Scalar Pos
_ (SStr Text
_) -> [Char]
"!!str"
Scalar Pos
_ (SFloat Double
_) -> [Char]
"!!float"
Scalar Pos
_ (SUnknown Tag
t Text
v)
| Tag -> Bool
isUntagged Tag
t -> Tag -> [Char]
tagged Tag
t forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Text
v
| Bool
otherwise -> [Char]
"(unsupported) " forall a. [a] -> [a] -> [a]
++ Tag -> [Char]
tagged Tag
t forall a. [a] -> [a] -> [a]
++ [Char]
"scalar"
Anchor Pos
_ NodeId
_ Node Pos
_ -> [Char]
"anchor"
Mapping Pos
_ Tag
t Mapping Pos
_ -> Tag -> [Char]
tagged Tag
t forall a. [a] -> [a] -> [a]
++ [Char]
" mapping"
Sequence Pos
_ Tag
t [Node Pos]
_ -> Tag -> [Char]
tagged Tag
t forall a. [a] -> [a] -> [a]
++ [Char]
" sequence"
tagged :: Tag -> [Char]
tagged Tag
t0 = case Tag -> Maybe Text
tagToText Tag
t0 of
Maybe Text
Nothing -> [Char]
"non-specifically ? tagged (i.e. unresolved) "
Just Text
t -> Text -> [Char]
T.unpack Text
t forall a. [a] -> [a] -> [a]
++ [Char]
" tagged"
class FromYAML a where
parseYAML :: Node Pos -> Parser a
{-# INLINE fixupFailPos #-}
fixupFailPos :: Pos -> Parser a -> Parser a
fixupFailPos :: forall a. Pos -> Parser a -> Parser a
fixupFailPos Pos
pos (P (Left (Pos
pos0,[Char]
emsg)))
| Pos
pos0 forall a. Eq a => a -> a -> Bool
== Pos
fakePos = forall a. Either (Pos, [Char]) a -> Parser a
P (forall a b. a -> Either a b
Left (Pos
pos,[Char]
emsg))
fixupFailPos Pos
_ Parser a
p = Parser a
p
withNull :: String -> Parser a -> Node Pos -> Parser a
withNull :: forall a. [Char] -> Parser a -> Node Pos -> Parser a
withNull [Char]
_ Parser a
f (Scalar Pos
pos Scalar
SNull) = forall a. Pos -> Parser a -> Parser a
fixupFailPos Pos
pos Parser a
f
withNull [Char]
expected Parser a
_ Node Pos
v = forall a. [Char] -> Node Pos -> Parser a
typeMismatch [Char]
expected Node Pos
v
withScalar :: String -> (Scalar -> Parser a) -> Node Pos -> Parser a
withScalar :: forall a. [Char] -> (Scalar -> Parser a) -> Node Pos -> Parser a
withScalar [Char]
_ Scalar -> Parser a
f (Scalar Pos
pos Scalar
sca) = forall a. Pos -> Parser a -> Parser a
fixupFailPos Pos
pos (Scalar -> Parser a
f Scalar
sca)
withScalar [Char]
expected Scalar -> Parser a
_ Node Pos
v = forall a. [Char] -> Node Pos -> Parser a
typeMismatch [Char]
expected Node Pos
v
instance (loc ~ Pos) => FromYAML (Node loc) where
parseYAML :: Node Pos -> Parser (Node loc)
parseYAML = forall (f :: * -> *) a. Applicative f => a -> f a
pure
instance FromYAML Scalar where
parseYAML :: Node Pos -> Parser Scalar
parseYAML = forall a. [Char] -> (Scalar -> Parser a) -> Node Pos -> Parser a
withScalar [Char]
"scalar" forall (f :: * -> *) a. Applicative f => a -> f a
pure
instance FromYAML Bool where
parseYAML :: Node Pos -> Parser Bool
parseYAML = forall a. [Char] -> (Bool -> Parser a) -> Node Pos -> Parser a
withBool [Char]
"!!bool" forall (f :: * -> *) a. Applicative f => a -> f a
pure
withBool :: String -> (Bool -> Parser a) -> Node Pos -> Parser a
withBool :: forall a. [Char] -> (Bool -> Parser a) -> Node Pos -> Parser a
withBool [Char]
_ Bool -> Parser a
f (Scalar Pos
pos (SBool Bool
b)) = forall a. Pos -> Parser a -> Parser a
fixupFailPos Pos
pos (Bool -> Parser a
f Bool
b)
withBool [Char]
expected Bool -> Parser a
_ Node Pos
v = forall a. [Char] -> Node Pos -> Parser a
typeMismatch [Char]
expected Node Pos
v
instance FromYAML Text where
parseYAML :: Node Pos -> Parser Text
parseYAML = forall a. [Char] -> (Text -> Parser a) -> Node Pos -> Parser a
withStr [Char]
"!!str" forall (f :: * -> *) a. Applicative f => a -> f a
pure
withStr :: String -> (Text -> Parser a) -> Node Pos -> Parser a
withStr :: forall a. [Char] -> (Text -> Parser a) -> Node Pos -> Parser a
withStr [Char]
_ Text -> Parser a
f (Scalar Pos
pos (SStr Text
b)) = forall a. Pos -> Parser a -> Parser a
fixupFailPos Pos
pos (Text -> Parser a
f Text
b)
withStr [Char]
expected Text -> Parser a
_ Node Pos
v = forall a. [Char] -> Node Pos -> Parser a
typeMismatch [Char]
expected Node Pos
v
instance FromYAML Integer where
parseYAML :: Node Pos -> Parser Integer
parseYAML = forall a. [Char] -> (Integer -> Parser a) -> Node Pos -> Parser a
withInt [Char]
"!!int" forall (f :: * -> *) a. Applicative f => a -> f a
pure
withInt :: String -> (Integer -> Parser a) -> Node Pos -> Parser a
withInt :: forall a. [Char] -> (Integer -> Parser a) -> Node Pos -> Parser a
withInt [Char]
_ Integer -> Parser a
f (Scalar Pos
pos (SInt Integer
b)) = forall a. Pos -> Parser a -> Parser a
fixupFailPos Pos
pos (Integer -> Parser a
f Integer
b)
withInt [Char]
expected Integer -> Parser a
_ Node Pos
v = forall a. [Char] -> Node Pos -> Parser a
typeMismatch [Char]
expected Node Pos
v
instance FromYAML Natural where
parseYAML :: Node Pos -> Parser Natural
parseYAML = forall a. [Char] -> (Integer -> Parser a) -> Node Pos -> Parser a
withInt [Char]
"!!int" forall a b. (a -> b) -> a -> b
$ \Integer
b -> if Integer
b forall a. Ord a => a -> a -> Bool
< Integer
0 then forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char]
"!!int " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Integer
b forall a. [a] -> [a] -> [a]
++ [Char]
" out of range for 'Natural'")
else forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a. Num a => Integer -> a
fromInteger Integer
b)
{-# INLINE parseInt #-}
parseInt :: (Integral a, Bounded a) => [Char] -> Node Pos -> Parser a
parseInt :: forall a. (Integral a, Bounded a) => [Char] -> Node Pos -> Parser a
parseInt [Char]
name = forall a. [Char] -> (Integer -> Parser a) -> Node Pos -> Parser a
withInt [Char]
"!!int" forall a b. (a -> b) -> a -> b
$ \Integer
b -> forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail forall a b. (a -> b) -> a -> b
$ [Char]
"!!int " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Integer
b forall a. [a] -> [a] -> [a]
++ [Char]
" out of range for '" forall a. [a] -> [a] -> [a]
++ [Char]
name forall a. [a] -> [a] -> [a]
++ [Char]
"'") forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$
forall n. (Integral n, Bounded n) => Integer -> Maybe n
fromIntegerMaybe Integer
b
instance FromYAML Int where parseYAML :: Node Pos -> Parser Int
parseYAML = forall a. (Integral a, Bounded a) => [Char] -> Node Pos -> Parser a
parseInt [Char]
"Int"
instance FromYAML Int8 where parseYAML :: Node Pos -> Parser Int8
parseYAML = forall a. (Integral a, Bounded a) => [Char] -> Node Pos -> Parser a
parseInt [Char]
"Int8"
instance FromYAML Int16 where parseYAML :: Node Pos -> Parser Int16
parseYAML = forall a. (Integral a, Bounded a) => [Char] -> Node Pos -> Parser a
parseInt [Char]
"Int16"
instance FromYAML Int32 where parseYAML :: Node Pos -> Parser Int32
parseYAML = forall a. (Integral a, Bounded a) => [Char] -> Node Pos -> Parser a
parseInt [Char]
"Int32"
instance FromYAML Int64 where parseYAML :: Node Pos -> Parser Int64
parseYAML = forall a. (Integral a, Bounded a) => [Char] -> Node Pos -> Parser a
parseInt [Char]
"Int64"
instance FromYAML Word where parseYAML :: Node Pos -> Parser NodeId
parseYAML = forall a. (Integral a, Bounded a) => [Char] -> Node Pos -> Parser a
parseInt [Char]
"Word"
instance FromYAML Word8 where parseYAML :: Node Pos -> Parser Word8
parseYAML = forall a. (Integral a, Bounded a) => [Char] -> Node Pos -> Parser a
parseInt [Char]
"Word8"
instance FromYAML Word16 where parseYAML :: Node Pos -> Parser Word16
parseYAML = forall a. (Integral a, Bounded a) => [Char] -> Node Pos -> Parser a
parseInt [Char]
"Word16"
instance FromYAML Word32 where parseYAML :: Node Pos -> Parser Word32
parseYAML = forall a. (Integral a, Bounded a) => [Char] -> Node Pos -> Parser a
parseInt [Char]
"Word32"
instance FromYAML Word64 where parseYAML :: Node Pos -> Parser Word64
parseYAML = forall a. (Integral a, Bounded a) => [Char] -> Node Pos -> Parser a
parseInt [Char]
"Word64"
instance FromYAML Double where
parseYAML :: Node Pos -> Parser Double
parseYAML = forall a. [Char] -> (Double -> Parser a) -> Node Pos -> Parser a
withFloat [Char]
"!!float" forall (f :: * -> *) a. Applicative f => a -> f a
pure
withFloat :: String -> (Double -> Parser a) -> Node Pos -> Parser a
withFloat :: forall a. [Char] -> (Double -> Parser a) -> Node Pos -> Parser a
withFloat [Char]
_ Double -> Parser a
f (Scalar Pos
pos (SFloat Double
b)) = forall a. Pos -> Parser a -> Parser a
fixupFailPos Pos
pos (Double -> Parser a
f Double
b)
withFloat [Char]
expected Double -> Parser a
_ Node Pos
v = forall a. [Char] -> Node Pos -> Parser a
typeMismatch [Char]
expected Node Pos
v
instance (Ord k, FromYAML k, FromYAML v) => FromYAML (Map k v) where
parseYAML :: Node Pos -> Parser (Map k v)
parseYAML = forall a.
[Char] -> (Mapping Pos -> Parser a) -> Node Pos -> Parser a
withMap [Char]
"!!map" forall a b. (a -> b) -> a -> b
$ \Mapping Pos
xs -> forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(Node Pos
a,Node Pos
b) -> (,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
b) (forall k a. Map k a -> [(k, a)]
Map.toList Mapping Pos
xs)
withMap :: String -> (Mapping Pos -> Parser a) -> Node Pos -> Parser a
withMap :: forall a.
[Char] -> (Mapping Pos -> Parser a) -> Node Pos -> Parser a
withMap [Char]
_ Mapping Pos -> Parser a
f (Mapping Pos
pos Tag
tag Mapping Pos
xs)
| Tag
tag forall a. Eq a => a -> a -> Bool
== Tag
tagMap = forall a. Pos -> Parser a -> Parser a
fixupFailPos Pos
pos (Mapping Pos -> Parser a
f Mapping Pos
xs)
withMap [Char]
expected Mapping Pos -> Parser a
_ Node Pos
v = forall a. [Char] -> Node Pos -> Parser a
typeMismatch [Char]
expected Node Pos
v
instance FromYAML v => FromYAML [v] where
parseYAML :: Node Pos -> Parser [v]
parseYAML = forall a.
[Char] -> ([Node Pos] -> Parser a) -> Node Pos -> Parser a
withSeq [Char]
"!!seq" (forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall a. FromYAML a => Node Pos -> Parser a
parseYAML)
withSeq :: String -> ([Node Pos] -> Parser a) -> Node Pos-> Parser a
withSeq :: forall a.
[Char] -> ([Node Pos] -> Parser a) -> Node Pos -> Parser a
withSeq [Char]
_ [Node Pos] -> Parser a
f (Sequence Pos
pos Tag
tag [Node Pos]
xs)
| Tag
tag forall a. Eq a => a -> a -> Bool
== Tag
tagSeq = forall a. Pos -> Parser a -> Parser a
fixupFailPos Pos
pos ([Node Pos] -> Parser a
f [Node Pos]
xs)
withSeq [Char]
expected [Node Pos] -> Parser a
_ Node Pos
v = forall a. [Char] -> Node Pos -> Parser a
typeMismatch [Char]
expected Node Pos
v
instance FromYAML a => FromYAML (Maybe a) where
parseYAML :: Node Pos -> Parser (Maybe a)
parseYAML (Scalar Pos
_ Scalar
SNull) = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Maybe a
Nothing
parseYAML Node Pos
j = forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
j
instance (FromYAML a, FromYAML b) => FromYAML (a,b) where
parseYAML :: Node Pos -> Parser (a, b)
parseYAML = forall a.
[Char] -> ([Node Pos] -> Parser a) -> Node Pos -> Parser a
withSeq [Char]
"!!seq" forall a b. (a -> b) -> a -> b
$ \[Node Pos]
xs ->
case [Node Pos]
xs of
[Node Pos
a,Node Pos
b] -> (,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
a
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
b
[Node Pos]
_ -> forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char]
"expected 2-sequence but got " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Node Pos]
xs) forall a. [a] -> [a] -> [a]
++ [Char]
"-sequence instead")
instance (FromYAML a, FromYAML b, FromYAML c) => FromYAML (a,b,c) where
parseYAML :: Node Pos -> Parser (a, b, c)
parseYAML = forall a.
[Char] -> ([Node Pos] -> Parser a) -> Node Pos -> Parser a
withSeq [Char]
"!!seq" forall a b. (a -> b) -> a -> b
$ \[Node Pos]
xs ->
case [Node Pos]
xs of
[Node Pos
a,Node Pos
b,Node Pos
c] -> (,,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
a
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
c
[Node Pos]
_ -> forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char]
"expected 3-sequence but got " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Node Pos]
xs) forall a. [a] -> [a] -> [a]
++ [Char]
"-sequence instead")
instance (FromYAML a, FromYAML b, FromYAML c, FromYAML d) => FromYAML (a,b,c,d) where
parseYAML :: Node Pos -> Parser (a, b, c, d)
parseYAML = forall a.
[Char] -> ([Node Pos] -> Parser a) -> Node Pos -> Parser a
withSeq [Char]
"!!seq" forall a b. (a -> b) -> a -> b
$ \[Node Pos]
xs ->
case [Node Pos]
xs of
[Node Pos
a,Node Pos
b,Node Pos
c,Node Pos
d] -> (,,,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
a
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
c
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
d
[Node Pos]
_ -> forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char]
"expected 4-sequence but got " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Node Pos]
xs) forall a. [a] -> [a] -> [a]
++ [Char]
"-sequence instead")
instance (FromYAML a, FromYAML b, FromYAML c, FromYAML d, FromYAML e) => FromYAML (a,b,c,d,e) where
parseYAML :: Node Pos -> Parser (a, b, c, d, e)
parseYAML = forall a.
[Char] -> ([Node Pos] -> Parser a) -> Node Pos -> Parser a
withSeq [Char]
"!!seq" forall a b. (a -> b) -> a -> b
$ \[Node Pos]
xs ->
case [Node Pos]
xs of
[Node Pos
a,Node Pos
b,Node Pos
c,Node Pos
d,Node Pos
e] -> (,,,,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
a
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
c
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
d
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
e
[Node Pos]
_ -> forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char]
"expected 5-sequence but got " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Node Pos]
xs) forall a. [a] -> [a] -> [a]
++ [Char]
"-sequence instead")
instance (FromYAML a, FromYAML b, FromYAML c, FromYAML d, FromYAML e, FromYAML f) => FromYAML (a,b,c,d,e,f) where
parseYAML :: Node Pos -> Parser (a, b, c, d, e, f)
parseYAML = forall a.
[Char] -> ([Node Pos] -> Parser a) -> Node Pos -> Parser a
withSeq [Char]
"!!seq" forall a b. (a -> b) -> a -> b
$ \[Node Pos]
xs ->
case [Node Pos]
xs of
[Node Pos
a,Node Pos
b,Node Pos
c,Node Pos
d,Node Pos
e,Node Pos
f] -> (,,,,,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
a
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
c
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
d
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
e
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
f
[Node Pos]
_ -> forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char]
"expected 6-sequence but got " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Node Pos]
xs) forall a. [a] -> [a] -> [a]
++ [Char]
"-sequence instead")
instance (FromYAML a, FromYAML b, FromYAML c, FromYAML d, FromYAML e, FromYAML f, FromYAML g) => FromYAML (a,b,c,d,e,f,g) where
parseYAML :: Node Pos -> Parser (a, b, c, d, e, f, g)
parseYAML = forall a.
[Char] -> ([Node Pos] -> Parser a) -> Node Pos -> Parser a
withSeq [Char]
"!!seq" forall a b. (a -> b) -> a -> b
$ \[Node Pos]
xs ->
case [Node Pos]
xs of
[Node Pos
a,Node Pos
b,Node Pos
c,Node Pos
d,Node Pos
e,Node Pos
f,Node Pos
g] -> (,,,,,,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
a
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
c
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
d
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
e
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
f
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromYAML a => Node Pos -> Parser a
parseYAML Node Pos
g
[Node Pos]
_ -> forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char]
"expected 7-sequence but got " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Node Pos]
xs) forall a. [a] -> [a] -> [a]
++ [Char]
"-sequence instead")
decode :: FromYAML v => BS.L.ByteString -> Either (Pos, String) [v]
decode :: forall v. FromYAML v => ByteString -> Either (Pos, [Char]) [v]
decode ByteString
bs0 = ByteString -> Either (Pos, [Char]) [Doc (Node Pos)]
decodeNode ByteString
bs0 forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall a. Parser a -> Either (Pos, [Char]) a
parseEither forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. FromYAML a => Node Pos -> Parser a
parseYAML forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\(Doc Node Pos
x) -> Node Pos
x))
decode1 :: FromYAML v => BS.L.ByteString -> Either (Pos, String) v
decode1 :: forall v. FromYAML v => ByteString -> Either (Pos, [Char]) v
decode1 ByteString
bs0 = do
[Doc (Node Pos)]
docs <- ByteString -> Either (Pos, [Char]) [Doc (Node Pos)]
decodeNode ByteString
bs0
case [Doc (Node Pos)]
docs of
[] -> forall a b. a -> Either a b
Left (Pos { posByteOffset :: Int
posByteOffset = Int
0, posCharOffset :: Int
posCharOffset = Int
0, posLine :: Int
posLine = Int
1, posColumn :: Int
posColumn = Int
0 }, [Char]
"empty YAML stream")
[Doc Node Pos
v] -> forall a. Parser a -> Either (Pos, [Char]) a
parseEither forall a b. (a -> b) -> a -> b
$ forall a. FromYAML a => Node Pos -> Parser a
parseYAML forall a b. (a -> b) -> a -> b
$ Node Pos
v
(Doc (Node Pos)
_:Doc Node Pos
n:[Doc (Node Pos)]
_) -> forall a b. a -> Either a b
Left (forall loc. Node loc -> loc
nodeLoc Node Pos
n, [Char]
"unexpected multiple YAML documents")
decodeStrict :: FromYAML v => BS.ByteString -> Either (Pos, String) [v]
decodeStrict :: forall v. FromYAML v => ByteString -> Either (Pos, [Char]) [v]
decodeStrict = forall v. FromYAML v => ByteString -> Either (Pos, [Char]) [v]
decode forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ByteString] -> ByteString
BS.L.fromChunks forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> [a] -> [a]
:[])
decode1Strict :: FromYAML v => BS.ByteString -> Either (Pos, String) v
decode1Strict :: forall v. FromYAML v => ByteString -> Either (Pos, [Char]) v
decode1Strict = forall v. FromYAML v => ByteString -> Either (Pos, [Char]) v
decode1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ByteString] -> ByteString
BS.L.fromChunks forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> [a] -> [a]
:[])
class ToYAML a where
toYAML :: a -> Node ()
instance Loc loc => ToYAML (Node loc) where
toYAML :: Node loc -> Node ()
toYAML = forall loc (f :: * -> *). (Loc loc, Functor f) => f loc -> f ()
toUnit
instance ToYAML Bool where
toYAML :: Bool -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Scalar
SBool
instance ToYAML Double where
toYAML :: Double -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Scalar
SFloat
instance ToYAML Int where toYAML :: Int -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Scalar
SInt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Integer
toInteger
instance ToYAML Int8 where toYAML :: Int8 -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Scalar
SInt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Integer
toInteger
instance ToYAML Int16 where toYAML :: Int16 -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Scalar
SInt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Integer
toInteger
instance ToYAML Int32 where toYAML :: Int32 -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Scalar
SInt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Integer
toInteger
instance ToYAML Int64 where toYAML :: Int64 -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Scalar
SInt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Integer
toInteger
instance ToYAML Word where toYAML :: NodeId -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Scalar
SInt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Integer
toInteger
instance ToYAML Word8 where toYAML :: Word8 -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Scalar
SInt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Integer
toInteger
instance ToYAML Word16 where toYAML :: Word16 -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Scalar
SInt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Integer
toInteger
instance ToYAML Word32 where toYAML :: Word32 -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Scalar
SInt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Integer
toInteger
instance ToYAML Word64 where toYAML :: Word64 -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Scalar
SInt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Integer
toInteger
instance ToYAML Natural where toYAML :: Natural -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Scalar
SInt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Integer
toInteger
instance ToYAML Integer where toYAML :: Integer -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Scalar
SInt
instance ToYAML Text where
toYAML :: Text -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar () forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Scalar
SStr
instance ToYAML Scalar where
toYAML :: Scalar -> Node ()
toYAML = forall loc. loc -> Scalar -> Node loc
Scalar ()
instance ToYAML a => ToYAML (Maybe a) where
toYAML :: Maybe a -> Node ()
toYAML Maybe a
Nothing = forall loc. loc -> Scalar -> Node loc
Scalar () Scalar
SNull
toYAML (Just a
a) = forall a. ToYAML a => a -> Node ()
toYAML a
a
instance ToYAML a => ToYAML [a] where
toYAML :: [a] -> Node ()
toYAML = forall loc. loc -> Tag -> [Node loc] -> Node loc
Sequence () Tag
tagSeq forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a. ToYAML a => a -> Node ()
toYAML
instance (Ord k, ToYAML k, ToYAML v) => ToYAML (Map k v) where
toYAML :: Map k v -> Node ()
toYAML Map k v
kv = forall loc. loc -> Tag -> Mapping loc -> Node loc
Mapping () Tag
tagMap (forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (\(k
k,v
v) -> (forall a. ToYAML a => a -> Node ()
toYAML k
k , forall a. ToYAML a => a -> Node ()
toYAML v
v)) (forall k a. Map k a -> [(k, a)]
Map.toList Map k v
kv))
instance (ToYAML a, ToYAML b) => ToYAML (a, b) where
toYAML :: (a, b) -> Node ()
toYAML (a
a,b
b) = forall a. ToYAML a => a -> Node ()
toYAML [forall a. ToYAML a => a -> Node ()
toYAML a
a, forall a. ToYAML a => a -> Node ()
toYAML b
b]
instance (ToYAML a, ToYAML b, ToYAML c) => ToYAML (a, b, c) where
toYAML :: (a, b, c) -> Node ()
toYAML (a
a,b
b,c
c) = forall a. ToYAML a => a -> Node ()
toYAML [forall a. ToYAML a => a -> Node ()
toYAML a
a, forall a. ToYAML a => a -> Node ()
toYAML b
b, forall a. ToYAML a => a -> Node ()
toYAML c
c]
instance (ToYAML a, ToYAML b, ToYAML c, ToYAML d) => ToYAML (a, b, c, d) where
toYAML :: (a, b, c, d) -> Node ()
toYAML (a
a,b
b,c
c,d
d) = forall a. ToYAML a => a -> Node ()
toYAML [forall a. ToYAML a => a -> Node ()
toYAML a
a, forall a. ToYAML a => a -> Node ()
toYAML b
b, forall a. ToYAML a => a -> Node ()
toYAML c
c, forall a. ToYAML a => a -> Node ()
toYAML d
d]
instance (ToYAML a, ToYAML b, ToYAML c, ToYAML d, ToYAML e) => ToYAML (a, b, c, d, e) where
toYAML :: (a, b, c, d, e) -> Node ()
toYAML (a
a,b
b,c
c,d
d,e
e) = forall a. ToYAML a => a -> Node ()
toYAML [forall a. ToYAML a => a -> Node ()
toYAML a
a, forall a. ToYAML a => a -> Node ()
toYAML b
b, forall a. ToYAML a => a -> Node ()
toYAML c
c, forall a. ToYAML a => a -> Node ()
toYAML d
d, forall a. ToYAML a => a -> Node ()
toYAML e
e]
instance (ToYAML a, ToYAML b, ToYAML c, ToYAML d, ToYAML e, ToYAML f) => ToYAML (a, b, c, d, e, f) where
toYAML :: (a, b, c, d, e, f) -> Node ()
toYAML (a
a,b
b,c
c,d
d,e
e,f
f) = forall a. ToYAML a => a -> Node ()
toYAML [forall a. ToYAML a => a -> Node ()
toYAML a
a, forall a. ToYAML a => a -> Node ()
toYAML b
b, forall a. ToYAML a => a -> Node ()
toYAML c
c, forall a. ToYAML a => a -> Node ()
toYAML d
d, forall a. ToYAML a => a -> Node ()
toYAML e
e, forall a. ToYAML a => a -> Node ()
toYAML f
f]
instance (ToYAML a, ToYAML b, ToYAML c, ToYAML d, ToYAML e, ToYAML f, ToYAML g) => ToYAML (a, b, c, d, e, f, g) where
toYAML :: (a, b, c, d, e, f, g) -> Node ()
toYAML (a
a,b
b,c
c,d
d,e
e,f
f,g
g) = forall a. ToYAML a => a -> Node ()
toYAML [forall a. ToYAML a => a -> Node ()
toYAML a
a, forall a. ToYAML a => a -> Node ()
toYAML b
b, forall a. ToYAML a => a -> Node ()
toYAML c
c, forall a. ToYAML a => a -> Node ()
toYAML d
d, forall a. ToYAML a => a -> Node ()
toYAML e
e, forall a. ToYAML a => a -> Node ()
toYAML f
f, forall a. ToYAML a => a -> Node ()
toYAML g
g]
encode :: ToYAML v => [v] -> BS.L.ByteString
encode :: forall v. ToYAML v => [v] -> ByteString
encode [v]
vList = [Doc (Node ())] -> ByteString
encodeNode forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall n. n -> Doc n
Doc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ToYAML a => a -> Node ()
toYAML) [v]
vList
encode1 :: ToYAML v => v -> BS.L.ByteString
encode1 :: forall v. ToYAML v => v -> ByteString
encode1 v
a = forall v. ToYAML v => [v] -> ByteString
encode [v
a]
encodeStrict :: ToYAML v => [v] -> BS.ByteString
encodeStrict :: forall v. ToYAML v => [v] -> ByteString
encodeStrict = ByteString -> ByteString
bsToStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall v. ToYAML v => [v] -> ByteString
encode
encode1Strict :: ToYAML v => v -> BS.ByteString
encode1Strict :: forall v. ToYAML v => v -> ByteString
encode1Strict = ByteString -> ByteString
bsToStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall v. ToYAML v => v -> ByteString
encode1
class Loc loc where
toUnit :: Functor f => f loc -> f ()
toUnit = (() forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$)
instance Loc Pos
instance Loc () where toUnit :: forall (f :: * -> *). Functor f => f () -> f ()
toUnit = forall a. a -> a
id
type Pair = (Node (), Node ())
(.=) :: ToYAML a => Text -> a -> Pair
Text
name .= :: forall a. ToYAML a => Text -> a -> (Node (), Node ())
.= a
node = (forall a. ToYAML a => a -> Node ()
toYAML Text
name, forall a. ToYAML a => a -> Node ()
toYAML a
node)
mapping :: [Pair] -> Node ()
mapping :: [(Node (), Node ())] -> Node ()
mapping = forall loc. loc -> Tag -> Mapping loc -> Node loc
Mapping () Tag
tagMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList