hoppy-generator-0.6.0: C++ FFI generator - Code generator

Safe HaskellSafe
LanguageHaskell2010

Foreign.Hoppy.Generator.Override

Description

Support for specifying overrides of values based on parameters.

For example, an entity may have a name that you want to override on a per-language basis. A single value like this may be represented as a WithOverrides Language Name value. Such a value will have a default name, as well as zero or more overrides, keyed by Language.

A MapWithOverrides type is also provided for ease of overriding values inside of a map.

Synopsis

Documentation

data WithOverrides p v Source #

Represents a default value of type v with optional overrides keyed by parameter type p. The type p must have an Ord instance.

plain :: v -> WithOverrides p v Source #

Creates a WithOverrides with the given default value v, and no overridden values.

overridden :: v -> Map p v -> WithOverrides p v Source #

Creates a WithOverrides with the given default value v, and overridden values in the map.

unoverriddenValue :: WithOverrides p v -> v Source #

The default, unoverriden value for the WithOverrides. Lookups on the override will return this value a given parameter doesn't have an override.

overriddenValues :: WithOverrides p v -> Map p v Source #

Any overridden values that have been added to the WithOverrides.

data MapWithOverrides p k v Source #

Represents a map from k values to v values, where each entry can be overridden based on parameter p. A key is either present with a default value and possibly some overridden values, or it is completely absent -- it is not possible for a key to have overridden values but no default value.

plainMap :: Map k v -> MapWithOverrides p k v Source #

Converts a plain map to a MapWithOverrides without any overrides.

mapWithOverrides :: Map k (WithOverrides p v) -> MapWithOverrides p k v Source #

Direct constructor for MapWithOverrides.

addOverrideMap :: (Ord p, Ord k, Show p, Show k) => p -> Map k v -> MapWithOverrides p k v -> MapWithOverrides p k v Source #

Adds a collection of overrides v for multiple keys k, all under a single parameter p, to a MapWithOverrides.

It is an error for a parameter to override a key that is not present in the defaults map.

addOverrideMaps :: (Ord p, Ord k, Show p, Show k) => Map p (Map k v) -> MapWithOverrides p k v -> MapWithOverrides p k v Source #

Adds overrides v for multiple keys k under multiple parameters p to a MapWithOverrides.

It is an error for a parameter to override a key that is not present in the defaults map.

applyOverrideMaps :: (Ord p, Ord k, Show p, Show k) => Map p (Map k v) -> Map k v -> MapWithOverrides p k v Source #

Constructs a MapWithOverrides from a map of default values and a bunch of parameter-specific maps overlaid on top of it.

It is an error for a parameter to override a key that is not present in the defaults map.

insertMapOverride :: (Ord p, Ord k, Show p, Show k) => p -> k -> v -> MapWithOverrides p k v -> MapWithOverrides p k v Source #

Adds an override v for key k under parameter p to a MapWithOverrides.

It is an error for a parameter to override a key that is not present in the defaults map.

overriddenMapLookup :: (Ord p, Ord k) => p -> k -> MapWithOverrides p k v -> Maybe v Source #

Looks up a value for k in the given MapWithOverrides, with the possibility that the value is overridden by the parameter p.