| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Transformation.AG
Description
An attribute grammar is a particular kind of Transformation that assigns attributes to nodes in a
tree. Different node types may have different types of attributes, so the transformation is not natural. All
attributes are divided into Inherited and Synthesized attributes.
Synopsis
- type family Atts (f :: Type -> Type) (g :: (Type -> Type) -> (Type -> Type) -> Type)
- type family NodeConstructor a :: (Type -> Type) -> (Type -> Type) -> Type where ...
- newtype Inherited t a = Inherited {
- inh :: Atts (Inherited t) (NodeConstructor a)
- newtype Synthesized t a = Synthesized {
- syn :: Atts (Synthesized t) (NodeConstructor a)
- mapInherited :: (Atts (Inherited t) (NodeConstructor a) -> Atts (Inherited t) (NodeConstructor b)) -> Inherited t a -> Inherited t b
- mapSynthesized :: (Atts (Synthesized t) (NodeConstructor a) -> Atts (Synthesized t) (NodeConstructor b)) -> Synthesized t a -> Synthesized t b
- type Semantics t = Inherited t ~> Synthesized t
- class Attribution t where
- class Attribution t => At t (g :: (Type -> Type) -> (Type -> Type) -> Type) where
- attribution :: forall (sem :: Type -> Type). Traversable (g sem) => t -> Origin t (g sem sem) -> (Inherited t (g sem sem), g sem (Synthesized t)) -> (Synthesized t (g sem sem), g sem (Inherited t))
- newtype Knit t = Knit t
- newtype Keep t = Keep t
- data Kept t a = Kept {
- inherited :: Atts (Inherited t) (NodeConstructor a)
- synthesized :: Atts (Synthesized t) (NodeConstructor a)
- original :: Origin t a
- type Rule t (g :: (Type -> Type) -> (Type -> Type) -> Type) = forall (sem :: Type -> Type). sem ~ Semantics t => (Inherited t (g sem (Semantics t)), g sem (Synthesized t)) -> (Synthesized t (g sem (Semantics t)), g sem (Inherited t))
- knit :: (Apply (g sem), sem ~ Semantics t) => Rule t g -> g sem sem -> sem (g sem sem)
Documentation
type family Atts (f :: Type -> Type) (g :: (Type -> Type) -> (Type -> Type) -> Type) Source #
Type family that maps a node type to the type of its attributes, indexed per type constructor.
Instances
| type Atts (Inherited (Keep t)) g Source # | |
| type Atts (Inherited (Auto t)) g Source # | |
Defined in Transformation.AG.Dimorphic | |
| type Atts (Inherited (Auto t)) x Source # | |
| type Atts (Synthesized (Keep t)) g Source # | |
Defined in Transformation.AG | |
| type Atts (Synthesized (Auto t)) g Source # | |
Defined in Transformation.AG.Dimorphic | |
| type Atts (Synthesized (Auto t)) x Source # | |
Defined in Transformation.AG.Generics | |
type family NodeConstructor a :: (Type -> Type) -> (Type -> Type) -> Type where ... Source #
Type family that lops off the two type parameters
Equations
| NodeConstructor (g p q) = g | |
| NodeConstructor t = Const2 t |
newtype Inherited t a Source #
Type constructor wrapping the inherited attributes for the given transformation.
Constructors
| Inherited | |
Fields
| |
Instances
| Monoid (Atts (Inherited t) (NodeConstructor a)) => Monoid (Inherited t a) Source # | |
| Semigroup (Atts (Inherited t) (NodeConstructor a)) => Semigroup (Inherited t a) Source # | |
| Show (Atts (Inherited t) (NodeConstructor a)) => Show (Inherited t a) Source # | |
| type Atts (Inherited (Keep t)) g Source # | |
| type Atts (Inherited (Auto t)) g Source # | |
Defined in Transformation.AG.Dimorphic | |
| type Atts (Inherited (Auto t)) x Source # | |
newtype Synthesized t a Source #
Type constructor wrapping the synthesized attributes for the given transformation.
Constructors
| Synthesized | |
Fields
| |
Instances
mapInherited :: (Atts (Inherited t) (NodeConstructor a) -> Atts (Inherited t) (NodeConstructor b)) -> Inherited t a -> Inherited t b Source #
mapSynthesized :: (Atts (Synthesized t) (NodeConstructor a) -> Atts (Synthesized t) (NodeConstructor b)) -> Synthesized t a -> Synthesized t b Source #
type Semantics t = Inherited t ~> Synthesized t Source #
A node's Semantics is a natural tranformation from the node's inherited attributes to its synthesized
attributes.
class Attribution t where Source #
The core type class for defining the attribute grammar. The instances of this class typically have a form like
instance Attribution MyAttGrammar MyNode Identity where
attribution MyAttGrammar{} (Identity MyNode{})
(Inherited fromParent,
Synthesized MyNode{firstChild= fromFirstChild, ...})
= (Synthesized _forMyself,
Inherited MyNode{firstChild= _forFirstChild, ...})If you prefer to separate the calculation of different attributes, you can split the above instance into two
instances of the Bequether and Synthesizer classes
instead. If you derive Generic instances for your attributes, you can even define each synthesized
attribute individually with a SynthesizedField instance.
Instances
| Attribution t => Attribution (Keep t) Source # | |
| (Attribution t, Foldable (Origin t)) => Attribution (Auto t) Source # | |
| Attribution t => Attribution (Auto t) Source # | |
class Attribution t => At t (g :: (Type -> Type) -> (Type -> Type) -> Type) where Source #
Methods
attribution :: forall (sem :: Type -> Type). Traversable (g sem) => t -> Origin t (g sem sem) -> (Inherited t (g sem sem), g sem (Synthesized t)) -> (Synthesized t (g sem sem), g sem (Inherited t)) Source #
The attribution rule for a given transformation and node.
Instances
| (Functor (g (Semantics (Keep t))), Functor (Origin t), At t g) => At (Keep t) g Source # | |
Defined in Transformation.AG | |
| (Attribution t, f ~ Origin t, Foldable f, At t g, Foldable (g (Semantics (Auto t))), Functor (g (Semantics (Auto t))), Monoid (Synthesized t)) => At (Auto t) g Source # | |
Defined in Transformation.AG.Dimorphic | |
| (Attribution t, Bequether (Auto t) g, Synthesizer (Auto t) g) => At (Auto t) g Source # | |
Defined in Transformation.AG.Generics | |
Constructors
| Knit t |
Instances
| Attribution t => Transformation (Knit t) Source # | |
Defined in Transformation.AG | |
| (At t g, Apply (g (Semantics t)), Traversable (g (Semantics t)), Functor (Origin t), Functor (g (Origin t)), Functor (Knit t) g) => Functor (Knit t) g Source # | |
Defined in Transformation.AG Methods (<$>) :: Knit t -> Domain (Knit t) (g (Domain (Knit t)) (Domain (Knit t))) -> Codomain (Knit t) (g (Codomain (Knit t)) (Codomain (Knit t))) Source # coerce :: (Knit t ~ Coercion p q, forall (h :: (Type -> Type) -> (Type -> Type) -> Type). Coercible (p (h p p)) (q (h q q))) => p (g p p) -> q (g q q) Source # | |
| (At t g, Apply (g sem), Traversable (g sem), sem ~ Semantics t) => At (Knit t) (g sem sem) Source # | |
| type Codomain (Knit t) Source # | |
Defined in Transformation.AG | |
| type Domain (Knit t) Source # | |
Defined in Transformation.AG | |
Transformation wrapper that keeps all the original tree nodes alongside their attributes
Constructors
| Keep t |
Instances
| Attribution t => Attribution (Keep t) Source # | |
| (Functor (g (Semantics (Keep t))), Functor (Origin t), At t g) => At (Keep t) g Source # | |
Defined in Transformation.AG | |
| type Origin (Keep t) Source # | |
Defined in Transformation.AG | |
| type Atts (Inherited (Keep t)) g Source # | |
| type Atts (Synthesized (Keep t)) g Source # | |
Defined in Transformation.AG | |
Constructors
| Kept | |
Fields
| |
type Rule t (g :: (Type -> Type) -> (Type -> Type) -> Type) = forall (sem :: Type -> Type). sem ~ Semantics t => (Inherited t (g sem (Semantics t)), g sem (Synthesized t)) -> (Synthesized t (g sem (Semantics t)), g sem (Inherited t)) Source #
An attribution rule maps a node's inherited attributes and its child nodes' synthesized attributes to the node's synthesized attributes and the children nodes' inherited attributes.