kure-2.12.0: Combinators for Strategic Programming

Portabilityghc
Stabilitybeta
MaintainerNeil Sculthorpe <neil@ittc.ku.edu>
Safe HaskellSafe-Inferred

Language.KURE.Walker

Contents

Description

This module provides combinators that traverse a tree.

Note that all traversals take place on the node, its children, or its descendents. Deliberately, there is no mechanism for "ascending" the tree.

Synopsis

Shallow Traversals

Tree Walkers

class Walker c g whereSource

Walker captures the ability to walk over a tree containing nodes of type g, using a specific context c.

Minimal complete definition: allR.

Default definitions are provided for anyR, oneR, allT, oneT, and childL, but they may be overridden for efficiency.

Methods

allR :: MonadCatch m => Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite to all immediate children, succeeding if they all succeed.

allT :: (MonadCatch m, Monoid b) => Translate c m g b -> Translate c m g bSource

Apply a Translate to all immediate children, succeeding if they all succeed. The results are combined in a Monoid.

oneT :: MonadCatch m => Translate c m g b -> Translate c m g bSource

Apply a Translate to the first immediate child for which it can succeed.

anyR :: MonadCatch m => Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite to all immediate children, suceeding if any succeed.

oneR :: MonadCatch m => Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite to the first immediate child for which it can succeed.

childL :: (ReadPath c crumb, Eq crumb, MonadCatch m) => crumb -> Lens c m g gSource

Construct a Lens to the n-th child node.

Child Transformations

childR :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => crumb -> Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite to a specified child.

childT :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => crumb -> Translate c m g b -> Translate c m g bSource

Apply a Translate to a specified child.

Deep Traversals

Rewrite Traversals

alltdR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite in a top-down manner, succeeding if they all succeed.

allbuR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite in a bottom-up manner, succeeding if they all succeed.

allduR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite twice, in a top-down and bottom-up way, using one single tree traversal, succeeding if they all succeed.

anytdR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite in a top-down manner, succeeding if any succeed.

anybuR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite in a bottom-up manner, succeeding if any succeed.

anyduR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite twice, in a top-down and bottom-up way, using one single tree traversal, succeeding if any succeed.

onetdR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite to the first node for which it can succeed, in a top-down traversal.

onebuR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite to the first node for which it can succeed, in a bottom-up traversal.

prunetdR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m gSource

Attempt to apply a Rewrite in a top-down manner, pruning at successful rewrites.

innermostR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m gSource

A fixed-point traveral, starting with the innermost term.

allLargestR :: (Walker c g, MonadCatch m) => Translate c m g Bool -> Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite to the largest node(s) that satisfy the predicate, requiring all to succeed.

anyLargestR :: (Walker c g, MonadCatch m) => Translate c m g Bool -> Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite to the largest node(s) that satisfy the predicate, succeeding if any succeed.

oneLargestR :: (Walker c g, MonadCatch m) => Translate c m g Bool -> Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite to the first node for which it can succeed among the largest node(s) that satisfy the predicate.

Translate Traversals

foldtdT :: (Walker c g, MonadCatch m, Monoid b) => Translate c m g b -> Translate c m g bSource

Fold a tree in a top-down manner, using a single Translate for each node.

foldbuT :: (Walker c g, MonadCatch m, Monoid b) => Translate c m g b -> Translate c m g bSource

Fold a tree in a bottom-up manner, using a single Translate for each node.

onetdT :: (Walker c g, MonadCatch m) => Translate c m g b -> Translate c m g bSource

Apply a Translate to the first node for which it can succeed, in a top-down traversal.

onebuT :: (Walker c g, MonadCatch m) => Translate c m g b -> Translate c m g bSource

Apply a Translate to the first node for which it can succeed, in a bottom-up traversal.

prunetdT :: (Walker c g, MonadCatch m, Monoid b) => Translate c m g b -> Translate c m g bSource

Attempt to apply a Translate in a top-down manner, pruning at successes.

crushtdT :: (Walker c g, MonadCatch m, Monoid b) => Translate c m g b -> Translate c m g bSource

An always successful top-down fold, replacing failures with mempty.

crushbuT :: (Walker c g, MonadCatch m, Monoid b) => Translate c m g b -> Translate c m g bSource

An always successful bottom-up fold, replacing failures with mempty.

collectT :: (Walker c g, MonadCatch m) => Translate c m g b -> Translate c m g [b]Source

An always successful traversal that collects the results of all successful applications of a Translate in a list.

collectPruneT :: (Walker c g, MonadCatch m) => Translate c m g b -> Translate c m g [b]Source

Like collectT, but does not traverse below successes.

allLargestT :: (Walker c g, MonadCatch m, Monoid b) => Translate c m g Bool -> Translate c m g b -> Translate c m g bSource

Apply a Translate to the largest node(s) that satisfy the predicate, combining the results in a monoid.

oneLargestT :: (Walker c g, MonadCatch m) => Translate c m g Bool -> Translate c m g b -> Translate c m g bSource

Apply a Translate to the first node for which it can succeed among the largest node(s) that satisfy the predicate.

Utilitity Translations

childrenT :: (ReadPath c crumb, Walker c g, MonadCatch m) => Translate c m g [crumb]Source

List the children of the current node.

summandIsTypeT :: forall c m a g. (MonadCatch m, Injection a g) => a -> Translate c m g BoolSource

Test if the type of the current node summand matches the type of the argument. Note that the argument value is never inspected, it is merely a proxy for a type argument.

Paths

Building Lenses from Paths

pathL :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => Path crumb -> Lens c m g gSource

Construct a Lens by following a Path.

localPathL :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => LocalPath crumb -> Lens c m g gSource

Build a Lens from the root to a point specified by a LocalPath.

exhaustPathL :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => Path crumb -> Lens c m g gSource

Construct a Lens that points to the last node at which the Path can be followed.

repeatPathL :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => Path crumb -> Lens c m g gSource

Repeat as many iterations of the Path as possible.

Applying transformations at the end of Paths

pathR :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => Path crumb -> Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite at a point specified by a Path.

pathT :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => Path crumb -> Translate c m g b -> Translate c m g bSource

Apply a Translate at a point specified by a Path.

localPathR :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => LocalPath crumb -> Rewrite c m g -> Rewrite c m gSource

Apply a Rewrite at a point specified by a LocalPath.

localPathT :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => LocalPath crumb -> Translate c m g b -> Translate c m g bSource

Apply a Translate at a point specified by a LocalPath.

Testing Paths

testPathT :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => Path crumb -> Translate c m g BoolSource

Check if it is possible to construct a Lens along this path from the current node.