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