swarm-0.5.0.0: 2D resource gathering game with programmable robots
LicenseBSD-3-Clause
Safe HaskellSafe-Inferred
LanguageHaskell2010

Swarm.Util.Yaml

Description

Various utilities related to parsing YAML files.

Synopsis

Documentation

newtype With e f 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 :: (e' -> e) -> With e f a -> With e' f a Source #

Locally modify an environment.

withE :: Semigroup e => e -> With e f a -> With e f a Source #

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

getE :: 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 Display Display Source # 
Instance details

Defined in Swarm.Game.Display

FromJSONE EntityMap Entity Source #

If we have access to an EntityMap, we can parse the name of an Entity as a string and look it up in the map.

Instance details

Defined in Swarm.Game.Entity

FromJSONE EntityMap TRobot Source #

We can parse a robot from a YAML file if we have access to an EntityMap in which we can look up the names of entities.

Instance details

Defined in Swarm.Game.Robot

FromJSONE e Int Source # 
Instance details

Defined in Swarm.Util.Yaml

FromJSONE EntityMap (Recipe Entity) Source # 
Instance details

Defined in Swarm.Game.Recipe

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 #

FromJSONE (EntityMap, RobotMap) Cell Source # 
Instance details

Defined in Swarm.Game.Scenario.Topography.Cell

FromJSONE (EntityMap, WorldMap) Scenario Source # 
Instance details

Defined in Swarm.Game.Scenario

FromJSONE (EntityMap, RobotMap) (AugmentedCell Entity) Source #

Parse a tuple such as [grass, rock, base] into a PCell. The entity and robot, if present, are immediately looked up and converted into Entity and TRobot values. If they are not found, a parse error results.

Instance details

Defined in Swarm.Game.Scenario.Topography.Cell

FromJSONE (EntityMap, RobotMap) (NamedStructure (Maybe (PCell Entity))) Source # 
Instance details

Defined in Swarm.Game.Scenario.Topography.Structure

FromJSONE (EntityMap, RobotMap) (PStructure (Maybe (PCell Entity))) Source # 
Instance details

Defined in Swarm.Game.Scenario.Topography.Structure

FromJSONE (EntityMap, RobotMap) (WorldPalette Entity) Source # 
Instance details

Defined in Swarm.Game.Scenario.Topography.WorldPalette

FromJSONE (WorldMap, InheritedStructureDefs, EntityMap, RobotMap) WorldDescription Source # 
Instance details

Defined in Swarm.Game.Scenario.Topography.WorldDescription

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 Value, 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 Value, 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 Value when value is an Value and fails otherwise.

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

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