swarm-0.7.0.0: 2D resource gathering game with programmable robots
LicenseBSD-3-Clause
Safe HaskellNone
LanguageHaskell2010

Swarm.Util.Yaml

Description

Various utilities related to parsing YAML files.

Synopsis

Documentation

newtype With e (f :: Type -> Type) a Source #

A generic wrapper for computations which also depend on knowing a value of type e.

Constructors

E 

Fields

Instances

Instances details
MonadFail f => MonadFail (With e f) Source # 
Instance details

Defined in Swarm.Util.Yaml

Methods

fail :: String -> With e f a #

Alternative f => Alternative (With e f) Source # 
Instance details

Defined in Swarm.Util.Yaml

Methods

empty :: With e f a #

(<|>) :: With e f a -> With e f a -> With e f a #

some :: With e f a -> With e f [a] #

many :: With e f a -> With e f [a] #

Applicative f => Applicative (With e f) Source # 
Instance details

Defined in Swarm.Util.Yaml

Methods

pure :: a -> With e f a #

(<*>) :: With e f (a -> b) -> With e f a -> With e f b #

liftA2 :: (a -> b -> c) -> With e f a -> With e f b -> With e f c #

(*>) :: With e f a -> With e f b -> With e f b #

(<*) :: With e f a -> With e f b -> With e f a #

Functor f => Functor (With e f) Source # 
Instance details

Defined in Swarm.Util.Yaml

Methods

fmap :: (a -> b) -> With e f a -> With e f b #

(<$) :: a -> With e f b -> With e f a #

Monad f => Monad (With e f) Source # 
Instance details

Defined in Swarm.Util.Yaml

Methods

(>>=) :: With e f a -> (a -> With e f b) -> With e f b #

(>>) :: With e f a -> With e f b -> With e f b #

return :: a -> With e f a #

type ParserE e = With e Parser Source #

A ParserE is a YAML Parser that can also depend on knowing an value of type e. The E used to stand for EntityMap, but now that it is generalized, it stands for Environment.

liftE :: Functor f => f a -> With e f a Source #

Lift a computation that does not care about the environment value.

localE :: forall e' e (f :: Type -> Type) a. (e' -> e) -> With e f a -> With e' f a Source #

Locally modify an environment.

withE :: forall e (f :: Type -> Type) a. Semigroup e => e -> With e f a -> With e f a Source #

Locally merge an environment with the current one for given action.

getE :: forall (f :: Type -> Type) e. Monad f => With e f e Source #

Get the current environment.

class FromJSONE e a where Source #

FromJSONE governs values that can be parsed from a YAML (or JSON) file, but which also have access to an extra, read-only environment value.

For things that don't care about the environment, the default implementation of parseJSONE simply calls parseJSON from a FromJSON instance.

Minimal complete definition

Nothing

Methods

parseJSONE :: Value -> ParserE e a Source #

default parseJSONE :: FromJSON a => Value -> ParserE e a Source #

parseJSONE' :: e -> Value -> Parser a Source #

Instances

Instances details
FromJSONE e Int Source # 
Instance details

Defined in Swarm.Util.Yaml

FromJSONE e a => FromJSONE e [a] Source # 
Instance details

Defined in Swarm.Util.Yaml

Methods

parseJSONE :: Value -> ParserE e [a] Source #

parseJSONE' :: e -> Value -> Parser [a] Source #

(FromJSONE e a, FromJSONE e b) => FromJSONE e (a, b) Source # 
Instance details

Defined in Swarm.Util.Yaml

Methods

parseJSONE :: Value -> ParserE e (a, b) Source #

parseJSONE' :: e -> Value -> Parser (a, b) Source #

decodeFileEitherE :: FromJSONE e a => e -> FilePath -> IO (Either ParseException a) Source #

Read a value from a YAML file, providing the needed extra environment.

(..:) :: FromJSONE e a => Object -> Text -> ParserE e a Source #

A variant of .: for ParserE: project out a field of an Object, passing along the extra environment.

(..:?) :: FromJSONE e a => Object -> Text -> ParserE e (Maybe a) Source #

A variant of .:? for ParserE: project out an optional field of an Object, passing along the extra environment.

(..!=) :: Functor f => f (Maybe a) -> a -> f a Source #

A variant of .!= for any functor.

withTextE :: String -> (Text -> ParserE e a) -> Value -> ParserE e a Source #

withTextE name f value applies f to the Text when value is a String and fails otherwise.

withObjectE :: String -> (Object -> ParserE e a) -> Value -> ParserE e a Source #

withObjectE name f value applies f to the Object when value is an Object and fails otherwise.

withArrayE :: String -> (Array -> ParserE e a) -> Value -> ParserE e a Source #

withArrayE name f value applies f to the Array when value is an Array and fails otherwise.