deep-transformations-0.4.0.1: Deep natural and unnatural tree transformations, including attribute grammars
Safe HaskellNone
LanguageHaskell2010

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

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

Instances details
type Atts (Inherited (Keep t)) g Source # 
Instance details

Defined in Transformation.AG

type Atts (Inherited (Keep t)) g = Atts (Inherited t) g
type Atts (Inherited (Auto t)) g Source # 
Instance details

Defined in Transformation.AG.Dimorphic

type Atts (Inherited (Auto t)) g = Inherited t
type Atts (Inherited (Auto t)) x Source # 
Instance details

Defined in Transformation.AG.Generics

type Atts (Inherited (Auto t)) x = Atts (Inherited t) x
type Atts (Synthesized (Keep t)) g Source # 
Instance details

Defined in Transformation.AG

type Atts (Synthesized (Keep t)) g = Kept t (g (Kept t) (Kept t))
type Atts (Synthesized (Auto t)) g Source # 
Instance details

Defined in Transformation.AG.Dimorphic

type Atts (Synthesized (Auto t)) g = Synthesized t
type Atts (Synthesized (Auto t)) x Source # 
Instance details

Defined in Transformation.AG.Generics

type Atts (Synthesized (Auto t)) x = Atts (Synthesized t) x

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

Instances details
Monoid (Atts (Inherited t) (NodeConstructor a)) => Monoid (Inherited t a) Source # 
Instance details

Defined in Transformation.AG

Methods

mempty :: Inherited t a #

mappend :: Inherited t a -> Inherited t a -> Inherited t a #

mconcat :: [Inherited t a] -> Inherited t a #

Semigroup (Atts (Inherited t) (NodeConstructor a)) => Semigroup (Inherited t a) Source # 
Instance details

Defined in Transformation.AG

Methods

(<>) :: Inherited t a -> Inherited t a -> Inherited t a #

sconcat :: NonEmpty (Inherited t a) -> Inherited t a #

stimes :: Integral b => b -> Inherited t a -> Inherited t a #

Show (Atts (Inherited t) (NodeConstructor a)) => Show (Inherited t a) Source # 
Instance details

Defined in Transformation.AG

Methods

showsPrec :: Int -> Inherited t a -> ShowS #

show :: Inherited t a -> String #

showList :: [Inherited t a] -> ShowS #

type Atts (Inherited (Keep t)) g Source # 
Instance details

Defined in Transformation.AG

type Atts (Inherited (Keep t)) g = Atts (Inherited t) g
type Atts (Inherited (Auto t)) g Source # 
Instance details

Defined in Transformation.AG.Dimorphic

type Atts (Inherited (Auto t)) g = Inherited t
type Atts (Inherited (Auto t)) x Source # 
Instance details

Defined in Transformation.AG.Generics

type Atts (Inherited (Auto t)) x = Atts (Inherited t) x

newtype Synthesized t a Source #

Type constructor wrapping the synthesized attributes for the given transformation.

Constructors

Synthesized 

Fields

Instances

Instances details
Monoid (Atts (Synthesized t) (NodeConstructor a)) => Monoid (Synthesized t a) Source # 
Instance details

Defined in Transformation.AG

Methods

mempty :: Synthesized t a #

mappend :: Synthesized t a -> Synthesized t a -> Synthesized t a #

mconcat :: [Synthesized t a] -> Synthesized t a #

Semigroup (Atts (Synthesized t) (NodeConstructor a)) => Semigroup (Synthesized t a) Source # 
Instance details

Defined in Transformation.AG

Methods

(<>) :: Synthesized t a -> Synthesized t a -> Synthesized t a #

sconcat :: NonEmpty (Synthesized t a) -> Synthesized t a #

stimes :: Integral b => b -> Synthesized t a -> Synthesized t a #

Show (Atts (Synthesized t) (NodeConstructor a)) => Show (Synthesized t a) Source # 
Instance details

Defined in Transformation.AG

Methods

showsPrec :: Int -> Synthesized t a -> ShowS #

show :: Synthesized t a -> String #

showList :: [Synthesized t a] -> ShowS #

type Atts (Synthesized (Keep t)) g Source # 
Instance details

Defined in Transformation.AG

type Atts (Synthesized (Keep t)) g = Kept t (g (Kept t) (Kept t))
type Atts (Synthesized (Auto t)) g Source # 
Instance details

Defined in Transformation.AG.Dimorphic

type Atts (Synthesized (Auto t)) g = Synthesized t
type Atts (Synthesized (Auto t)) x Source # 
Instance details

Defined in Transformation.AG.Generics

type Atts (Synthesized (Auto t)) x = Atts (Synthesized t) x

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.

Associated Types

type Origin t :: Type -> Type Source #

Methods

unwrap :: t -> Origin t x -> x Source #

Unwrap the value from the original attribution domain

Instances

Instances details
Attribution t => Attribution (Keep t) Source # 
Instance details

Defined in Transformation.AG

Associated Types

type Origin (Keep t) 
Instance details

Defined in Transformation.AG

type Origin (Keep t) = Origin t

Methods

unwrap :: Keep t -> Origin (Keep t) x -> x Source #

(Attribution t, Foldable (Origin t)) => Attribution (Auto t) Source # 
Instance details

Defined in Transformation.AG.Dimorphic

Associated Types

type Origin (Auto t) 
Instance details

Defined in Transformation.AG.Dimorphic

type Origin (Auto t) = Origin t

Methods

unwrap :: Auto t -> Origin (Auto t) x -> x Source #

Attribution t => Attribution (Auto t) Source # 
Instance details

Defined in Transformation.AG.Generics

Associated Types

type Origin (Auto t) 
Instance details

Defined in Transformation.AG.Generics

type Origin (Auto t) = Origin t

Methods

unwrap :: Auto t -> Origin (Auto t) x -> x 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

Instances details
(Functor (g (Semantics (Keep t))), Functor (Origin t), At t g) => At (Keep t) g Source # 
Instance details

Defined in Transformation.AG

Methods

attribution :: forall (sem :: Type -> Type). Traversable (g sem) => Keep t -> Origin (Keep t) (g sem sem) -> (Inherited (Keep t) (g sem sem), g sem (Synthesized (Keep t))) -> (Synthesized (Keep t) (g sem sem), g sem (Inherited (Keep t))) Source #

(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 # 
Instance details

Defined in Transformation.AG.Dimorphic

Methods

attribution :: forall (sem :: Type -> Type). Traversable (g sem) => Auto t -> Origin (Auto t) (g sem sem) -> (Inherited (Auto t) (g sem sem), g sem (Synthesized (Auto t))) -> (Synthesized (Auto t) (g sem sem), g sem (Inherited (Auto t))) Source #

(Attribution t, Bequether (Auto t) g, Synthesizer (Auto t) g) => At (Auto t) g Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

attribution :: forall (sem :: Type -> Type). Traversable (g sem) => Auto t -> Origin (Auto t) (g sem sem) -> (Inherited (Auto t) (g sem sem), g sem (Synthesized (Auto t))) -> (Synthesized (Auto t) (g sem sem), g sem (Inherited (Auto t))) Source #

newtype Knit t Source #

Constructors

Knit t 

Instances

Instances details
Attribution t => Transformation (Knit t) Source # 
Instance details

Defined in Transformation.AG

Associated Types

type Domain (Knit t) 
Instance details

Defined in Transformation.AG

type Domain (Knit t) = Origin t
type Codomain (Knit t) 
Instance details

Defined in Transformation.AG

type Codomain (Knit t) = Semantics t
(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 # 
Instance details

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 # 
Instance details

Defined in Transformation.AG

Methods

($) :: Knit t -> Domain (Knit t) (g sem sem) -> Codomain (Knit t) (g sem sem) Source #

type Codomain (Knit t) Source # 
Instance details

Defined in Transformation.AG

type Codomain (Knit t) = Semantics t
type Domain (Knit t) Source # 
Instance details

Defined in Transformation.AG

type Domain (Knit t) = Origin t

newtype Keep t Source #

Transformation wrapper that keeps all the original tree nodes alongside their attributes

Constructors

Keep t 

Instances

Instances details
Attribution t => Attribution (Keep t) Source # 
Instance details

Defined in Transformation.AG

Associated Types

type Origin (Keep t) 
Instance details

Defined in Transformation.AG

type Origin (Keep t) = Origin t

Methods

unwrap :: Keep t -> Origin (Keep t) x -> x Source #

(Functor (g (Semantics (Keep t))), Functor (Origin t), At t g) => At (Keep t) g Source # 
Instance details

Defined in Transformation.AG

Methods

attribution :: forall (sem :: Type -> Type). Traversable (g sem) => Keep t -> Origin (Keep t) (g sem sem) -> (Inherited (Keep t) (g sem sem), g sem (Synthesized (Keep t))) -> (Synthesized (Keep t) (g sem sem), g sem (Inherited (Keep t))) Source #

type Origin (Keep t) Source # 
Instance details

Defined in Transformation.AG

type Origin (Keep t) = Origin t
type Atts (Inherited (Keep t)) g Source # 
Instance details

Defined in Transformation.AG

type Atts (Inherited (Keep t)) g = Atts (Inherited t) g
type Atts (Synthesized (Keep t)) g Source # 
Instance details

Defined in Transformation.AG

type Atts (Synthesized (Keep t)) g = Kept t (g (Kept t) (Kept t))

data Kept t a Source #

Instances

Instances details
(Show (Atts (Inherited t) (NodeConstructor a)), Show (Atts (Synthesized t) (NodeConstructor a)), Show (Origin t a)) => Show (Kept t a) Source # 
Instance details

Defined in Transformation.AG

Methods

showsPrec :: Int -> Kept t a -> ShowS #

show :: Kept t a -> String #

showList :: [Kept t a] -> ShowS #

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.

knit :: (Apply (g sem), sem ~ Semantics t) => Rule t g -> g sem sem -> sem (g sem sem) Source #

The core function to tie the recursive knot, turning a Rule for a node into its Semantics.