kiama.rewriting

trait Rewriter

[source: kiama/rewriting/Rewriter.scala]

trait Rewriter
extends AnyRef
Strategy-based term rewriting in the style of Stratego (http://strategoxt.org/). The implementation here is partially based on the semantics given in "Program Transformation with Scoped Dynamic Rewrite Rules", by Bravenboer, van Dam, Olmos and Visser, Fundamenta Informaticae, 69, 2005. The library strategies are mostly based on the Stratego library, but also on combinators found in the Scrap Your Boilerplate and Uniplate libraries for Haskell.
Direct Known Subclasses:
RewritingEvaluator, TransformingMain, Evaluator

Type Summary
type Term
The type of terms that can be rewritten. Any type of object value is acceptable but generic traversals will only work on Products (e.g., instances of case classes). We use AnyRef here so that non-Product values can be present in rewritten structures.
Value Summary
val eq : Strategy
Construct a strategy that tests whether the two sub-terms of a pair of terms are equal.
val equal : Strategy
Construct a strategy that tests whether the two sub-terms of a pair of terms are equal. Synonym for eq.
val failure : Strategy
A strategy that always fails. Stratego's fail is avoided here to avoid a clash with JUnit's method of the same name.
val id : Strategy
A strategy that always succeeds with the subject term unchanged (i.e., this is the identity strategy).
val isinnernode : Strategy
Construct a strategy that succeeds if the current term has at least one direct subterm.
val isleaf : Strategy
Construct a strategy that succeeds if the current term has no direct subterms.
val ispropersubterm : Strategy
Construct a strategy that succeeds when applied to a pair (x,y) if x is a sub-term of y but is not equal to y.
val ispropersuperterm : Strategy
Construct a strategy that succeeds when applied to a pair (x,y) if x is a super-term of y but is not equal to y.
val issubterm : Strategy
Construct a strategy that succeeds when applied to a pair (x,y) if x is a sub-term of y.
val issuperterm : Strategy
Construct a strategy that succeeds when applied to a pair (x,y) if x is a superterm of y.
Method Summary
def all (s : => Strategy) : Strategy
Traversal to all children. Construct a strategy that applies s to all term children of the subject term in left-to-right order. If s succeeds on all of the children, then succeed, forming a new term from the constructor of the original term and the result of s for each child. If s fails on any child, fail.
def alldownup2 (s1 : => Strategy, s2 : => Strategy) : Strategy
Construct a strategy that applies s1 in a top-down, prefix fashion stopping at a frontier where s succeeds. s2 is applied in a bottom-up, postfix fashion to the result.
def alltd (s : => Strategy) : Strategy
Construct a strategy that applies s in a top-down fashion, stopping at a frontier where s succeeds.
def alltdfold (s1 : => Strategy, s2 : => Strategy) : Strategy
Construct a strategy that applies s1 in a top-down, prefix fashion stopping at a frontier where s succeeds. s2 is applied in a bottom-up, postfix fashion to the results of the recursive calls.
def and (s1 : => Strategy, s2 : => Strategy) : Strategy
and (s1, s2) applies s1 and s2 to the current term and succeeds if both succeed. s2 will always be applied, i.e., and is *not* a short-circuit operator
def attempt (s : => Strategy) : Strategy
Construct a strategy that applies s, yielding the result of s if it succeeds, otherwise leave the original subject term unchanged. In Stratego library this strategy is called "try".
def bottomup (s : => Strategy) : Strategy
Construct a strategy that applies s in a bottom-up, postfix fashion to the subject term.
def bottomupS (s : => Strategy, stop : (Strategy) => Strategy) : Strategy
Construct a strategy that applies s in a bottom-up, postfix fashion to the subject term but stops when stop succeeds.
def breadthfirst (s : => Strategy) : Strategy
Construct a strategy that applies s in breadth first order.
def child (i : Int, s : Strategy) : Strategy
Traversal to a single child. Construct a strategy that applies s to the ith child of the subject term (counting from one). If s succeeds on the ith child producing t, then succeed, forming a new term that is the same as the original term except that the ith child is now t. If s fails on the ith child or the subject term does not have an ith child, then fail. child (i, s) is equivalent to Stratego's i(s) operator.
def collectl [T](f : scala.PartialFunction[AnyRef, T]) : (AnyRef) => scala.List[T]
Collect query results in a list. Run the function f as a top-down query on the subject term. Accumulate the values produced by the function in a list and return the final value of the list.
def collects [T](f : scala.PartialFunction[AnyRef, T]) : (AnyRef) => scala.collection.immutable.Set[T]
Collect query results in a set. Run the function f as a top-down query on the subject term. Accumulate the values produced by the function in a set and return the final value of the set.
def count (f : scala.PartialFunction[AnyRef, Int]) : (AnyRef) => Int
Count function results. Run the function f as a top-down query on the subject term. Sum the integer values returned by f from all applications.
def doloop (s : => Strategy, c : => Strategy) : Strategy
Construct a strategy that applies s at least once and then repeats s while c succeeds. This operator is called "do-while" in the Stratego library.
def dontstop (s : => Strategy) : Strategy
A unit for topdownS, bottomupS and downupS. For example, topdown (s) is equivalent to topdownS (s, dontstop).
def downup (s1 : => Strategy, s2 : => Strategy) : Strategy
Construct a strategy that applies s1 in a top-down, prefix fashion and s2 in a bottom-up, postfix fashion to the subject term.
def downup (s : => Strategy) : Strategy
Construct a strategy that applies s in a combined top-down and bottom-up fashion (i.e., both prefix and postfix) to the subject term.
def downupS (s1 : => Strategy, s2 : => Strategy, stop : (Strategy) => Strategy) : Strategy
Construct a strategy that applies s1 in a top-down, prefix fashion and s2 in a bottom-up, postfix fashion to the subject term but stops when stop succeeds.
def downupS (s : => Strategy, stop : (Strategy) => Strategy) : Strategy
Construct a strategy that applies s in a combined top-down and bottom-up fashion (i.e., both prefix and postfix) to the subject term but stops when stop succeeds.
def everywherebu (s : => Strategy) : Strategy
Construct a strategy that applies s at every term in a bottom-up fashion regardless of failure. (Sub-)terms for which the strategy fails are left unchanged.
def everywheretd (s : => Strategy) : Strategy
Construct a strategy that applies s at every term in a top-down fashion regardless of failure. (Sub-)terms for which the strategy fails are left unchanged.
def innermost (s : => Strategy) : Strategy
Construct a strategy that applies s repeatedly to the innermost (i.e., lowest and left-most) (sub-)term to which it applies. Stop with the current term if s doesn't apply anywhere.
def innermost2 (s : => Strategy) : Strategy
An alternative version of innermost.
def ior (s1 : => Strategy, s2 : => Strategy) : Strategy
ior (s1, s2) implements 'inclusive or', that is, the inclusive choice of s1 and s2. It first tries s1, if that fails it applies s2 (just like s1 <+ s2). However, when s1 succeeds it also tries to apply s2. The results of the transformations are returned.
def lastly (s : => Strategy, f : => Strategy) : Strategy
Applies s followed by f whether s failed or not. This operator is called "finally" in the Stratego library.
def leaves (s : => Strategy, isleaf : => Strategy) : Strategy
Construct a strategy that applies to all of the leaves of the current term, using isleaf as the leaf predicate.
def leaves (s : => Strategy, isleaf : => Strategy, skip : (Strategy) => Strategy) : Strategy
Construct a strategy that applies to all of the leaves of the current term, using isleaf as the leaf predicate, skipping subterms for which skip succeeds.
def loop (c : => Strategy, s : => Strategy) : Strategy
Construct a strategy that while c succeeds applies s. This operator is called "while" in the Stratego library.
def loopiter (s : (Int) => Strategy, low : Int, up : Int) : Strategy
Construct a strategy that applies s (i) for each integer i from low to up (inclusive). This operator is called "for" in the Stratego library.
def loopiter (i : => Strategy, c : => Strategy, s : => Strategy) : Strategy
Construct a strategy that repeats application of s while c fails, after initialization with i. This operator is called "for" in the Stratego library.
def loopnot (c : => Strategy, s : => Strategy) : Strategy
Construct a strategy that while c does not succeed applies s. This operator is called "while-not" in the Stratego library.
def manybu (s : Strategy) : Strategy
Construct a strategy that applies s as many times as possible, but at least once, in bottom up order.
def manytd (s : Strategy) : Strategy
Construct a strategy that applies s as many times as possible, but at least once, in top down order.
def not (s : => Strategy) : Strategy
Construct a strategy that applies s, then fails if s succeeded or, if s failed, succeeds with the subject term unchanged, I.e., it tests if s applies, but has no effect on the subject term.
def oncebu (s : => Strategy) : Strategy
Construct a strategy that applies s in a bottom-up fashion to one subterm at each level, stopping as soon as it succeeds once (at any level).
def oncetd (s : => Strategy) : Strategy
Construct a strategy that applies s in a top-down fashion to one subterm at each level, stopping as soon as it succeeds once (at any level).
def one (s : => Strategy) : Strategy
Traversal to one child. Construct a strategy that applies s to the term children of the subject term in left-to-right order. Assume that c is the first child on which s succeeds. Then stop applying s to the children and succeed, forming a new term from the constructor of the original term and the original children, except that c is replaced by the result of applying s to c. In the event that the strategy fails on all children, then fail.
def or (s1 : => Strategy, s2 : => Strategy) : Strategy
or (s1, s2) is similar to ior (s1,s2), but the application of the strategies is only tested.
def outermost (s : => Strategy) : Strategy
Construct a strategy that applies s repeatedly in a top-down fashion stopping each time as soon as it succeeds once (at any level). The outermost fails when s fails to apply to any (sub-)term.
def para [T](f : (Any, scala.Seq[T]) => T) : (Any) => T
Perform a paramorphism over a value. This is a fold in which the recursive step may refer to the recursive component of the value and the results of folding over the children. When the function f is called, the first parameter is the value and the second is a sequence of the values that f has returned for the children. This will work on any value, but will only decompose Products. This operation is similar to that used in the Uniplate library.
def query [T](f : scala.PartialFunction[AnyRef, T]) : Strategy
Define a term query. Construct a strategy that always succeeds with no effect on the subject term but applies a given partial function f to the subject term. In other words, the strategy runs f for its side-effects.
def queryf [T](f : (AnyRef) => T) : Strategy
Define a term query. Construct a strategy that always succeeds with no effect on the subject term but applies a given (possibly partial) function f to the subject term. In other words, the strategy runs f for its side-effects.
def reduce (s : => Strategy) : Strategy
Construct a strategy that applies s repeatedly to subterms until it fails on all of them.
def repeat (s : => Strategy) : Strategy
Construct a strategy that applies s repeatedly until it fails.
def repeat (s : => Strategy, n : Int) : Strategy
Construct a strategy that applies s repeatedly exactly n times. If s fails at some point during the n applications, the entire strategy fails. The result of the strategy is that of the nth application of s.
def repeat (s : => Strategy, c : => Strategy) : Strategy
Construct a strategy that repeatedly applies s until it fails and then terminates with application of c.
def repeat1 (s : => Strategy, c : => Strategy) : Strategy
Construct a strategy that repeatedly applies s (at least once) and terminates with application of c.
def repeat1 (s : => Strategy) : Strategy
Construct a strategy that repeatedly applies s (at least once).
def repeatuntil (s : => Strategy, c : => Strategy) : Strategy
Construct a strategy that repeatedly applies s until c succeeds.
def restore (s : => Strategy, rest : => Strategy) : Strategy
Apply restoring action 'rest' if s fails, and then fail. Typically useful if s performs side effects that should be restored/undone in case s fails.
def restorealways (s : => Strategy, rest : => Strategy) : Strategy
Apply restoring action 'rest' after s terminates, and preserve success/failure behaviour of s. Typically useful if s performs side effects that should be restored always, e.g., when maintaining scope information.
def rewrite [T <: AnyRef](s : => Strategy)(t : T) : T
Rewrite a term. Apply the strategy s to a term returning the result term if s succeeds, otherwise return the original term.
def rule (f : scala.PartialFunction[AnyRef, AnyRef]) : Strategy
Define a rewrite rule using a partial function. If the function is defined at the current term, then the strategy succeeds with the return value of the function applied to the current term. Otherwise the strategy fails.
def rulef (f : (AnyRef) => AnyRef) : Strategy
Define a rewrite rule using a function. The rule always succeeds with the return value of the function.
def some (s : => Strategy) : Strategy
Traversal to as many children as possible, but at least one. Construct a strategy that applies s to the term children of the subject term in left-to-right order. If s succeeds on any of the children, then succeed, forming a new term from the constructor of the original term and the result of s for each succeeding child, with other children unchanged. In the event that the strategy fails on all children, then fail.
def somebu (s : => Strategy) : Strategy
Construct a strategy that applies s in a bottom-up fashion to some subterms at each level, stopping as soon as it succeeds once (at any level).
def somedownup (s : => Strategy) : Strategy
Construct a strategy that applies s1 in a top-down, prefix fashion stopping at a frontier where s succeeds on some children. s2 is applied in a bottom-up, postfix fashion to the subject term the result.
def sometd (s : => Strategy) : Strategy
Construct a strategy that applies s in a top-down fashion to some subterms at each level, stopping as soon as it succeeds once (at any level).
def strategy (f : scala.PartialFunction[AnyRef, scala.Option[AnyRef]]) : Strategy
Make a strategy from a partial function. If the function is defined at the current term, then the function return value when applied to the current term determines whether the strategy succeeds or fails. If the function is not defined at the current term, the strategy fails.
def strategyf (f : (AnyRef) => scala.Option[AnyRef]) : Strategy
Make a strategy from a function. The function return value determines whether the strategy succeeds or fails.
def term (t : AnyRef) : Strategy
Construct a strategy that succeeds only if the subject term matches a given term.
implicit def termToStrategy (t : AnyRef) : Strategy
(Implicitly) construct a strategy that always succeeds, changing the subject term to a given term.
def test (s : => Strategy) : Strategy
Construct a strategy that tests whether strategy s succeeds, restoring the original term on success. A synonym for where.
def topdown (s : => Strategy) : Strategy
Construct a strategy that applies s in a top-down, prefix fashion to the subject term.
def topdownS (s : => Strategy, stop : (Strategy) => Strategy) : Strategy
Construct a strategy that applies s in a top-down, prefix fashion to the subject term but stops when stop succeeds.
def where (s : => Strategy) : Strategy
Construct a strategy that tests whether strategy s succeeds, restoring the original term on success. This is similar to Stratego's "where", except that in this version any effects on bindings are not visible outside s.
Methods inherited from AnyRef
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Class Summary
class PlusStrategy (p : => Strategy, q : => Strategy) extends Strategy
Helper class to contain commonality of choice in non-deterministic choice operator and then-else part of a conditional choice. Only returned by the non-deterministic choice operator.
abstract class Strategy extends (AnyRef) => scala.Option[AnyRef]
Term-rewriting strategies.
Object Summary
object Term extends AnyRef
Generic term deconstruction.
Type Details
type Term
The type of terms that can be rewritten. Any type of object value is acceptable but generic traversals will only work on Products (e.g., instances of case classes). We use AnyRef here so that non-Product values can be present in rewritten structures.

Value Details
val failure : Strategy
A strategy that always fails. Stratego's fail is avoided here to avoid a clash with JUnit's method of the same name.

val id : Strategy
A strategy that always succeeds with the subject term unchanged (i.e., this is the identity strategy).

val eq : Strategy
Construct a strategy that tests whether the two sub-terms of a pair of terms are equal.

val equal : Strategy
Construct a strategy that tests whether the two sub-terms of a pair of terms are equal. Synonym for eq.

val issubterm : Strategy
Construct a strategy that succeeds when applied to a pair (x,y) if x is a sub-term of y.

val ispropersubterm : Strategy
Construct a strategy that succeeds when applied to a pair (x,y) if x is a sub-term of y but is not equal to y.

val issuperterm : Strategy
Construct a strategy that succeeds when applied to a pair (x,y) if x is a superterm of y.

val ispropersuperterm : Strategy
Construct a strategy that succeeds when applied to a pair (x,y) if x is a super-term of y but is not equal to y.

val isleaf : Strategy
Construct a strategy that succeeds if the current term has no direct subterms.

val isinnernode : Strategy
Construct a strategy that succeeds if the current term has at least one direct subterm.

Method Details
def strategyf(f : (AnyRef) => scala.Option[AnyRef]) : Strategy
Make a strategy from a function. The function return value determines whether the strategy succeeds or fails.

def strategy(f : scala.PartialFunction[AnyRef, scala.Option[AnyRef]]) : Strategy
Make a strategy from a partial function. If the function is defined at the current term, then the function return value when applied to the current term determines whether the strategy succeeds or fails. If the function is not defined at the current term, the strategy fails.

def rulef(f : (AnyRef) => AnyRef) : Strategy
Define a rewrite rule using a function. The rule always succeeds with the return value of the function.

def rule(f : scala.PartialFunction[AnyRef, AnyRef]) : Strategy
Define a rewrite rule using a partial function. If the function is defined at the current term, then the strategy succeeds with the return value of the function applied to the current term. Otherwise the strategy fails.

implicit def termToStrategy(t : AnyRef) : Strategy
(Implicitly) construct a strategy that always succeeds, changing the subject term to a given term.

def queryf[T](f : (AnyRef) => T) : Strategy
Define a term query. Construct a strategy that always succeeds with no effect on the subject term but applies a given (possibly partial) function f to the subject term. In other words, the strategy runs f for its side-effects.

def query[T](f : scala.PartialFunction[AnyRef, T]) : Strategy
Define a term query. Construct a strategy that always succeeds with no effect on the subject term but applies a given partial function f to the subject term. In other words, the strategy runs f for its side-effects.

def term(t : AnyRef) : Strategy
Construct a strategy that succeeds only if the subject term matches a given term.

def para[T](f : (Any, scala.Seq[T]) => T) : (Any) => T
Perform a paramorphism over a value. This is a fold in which the recursive step may refer to the recursive component of the value and the results of folding over the children. When the function f is called, the first parameter is the value and the second is a sequence of the values that f has returned for the children. This will work on any value, but will only decompose Products. This operation is similar to that used in the Uniplate library.

def child(i : Int, s : Strategy) : Strategy
Traversal to a single child. Construct a strategy that applies s to the ith child of the subject term (counting from one). If s succeeds on the ith child producing t, then succeed, forming a new term that is the same as the original term except that the ith child is now t. If s fails on the ith child or the subject term does not have an ith child, then fail. child (i, s) is equivalent to Stratego's i(s) operator.

def all(s : => Strategy) : Strategy
Traversal to all children. Construct a strategy that applies s to all term children of the subject term in left-to-right order. If s succeeds on all of the children, then succeed, forming a new term from the constructor of the original term and the result of s for each child. If s fails on any child, fail.

def one(s : => Strategy) : Strategy
Traversal to one child. Construct a strategy that applies s to the term children of the subject term in left-to-right order. Assume that c is the first child on which s succeeds. Then stop applying s to the children and succeed, forming a new term from the constructor of the original term and the original children, except that c is replaced by the result of applying s to c. In the event that the strategy fails on all children, then fail.

def some(s : => Strategy) : Strategy
Traversal to as many children as possible, but at least one. Construct a strategy that applies s to the term children of the subject term in left-to-right order. If s succeeds on any of the children, then succeed, forming a new term from the constructor of the original term and the result of s for each succeeding child, with other children unchanged. In the event that the strategy fails on all children, then fail.

def rewrite[T <: AnyRef](s : => Strategy)(t : T) : T
Rewrite a term. Apply the strategy s to a term returning the result term if s succeeds, otherwise return the original term.

def collects[T](f : scala.PartialFunction[AnyRef, T]) : (AnyRef) => scala.collection.immutable.Set[T]
Collect query results in a set. Run the function f as a top-down query on the subject term. Accumulate the values produced by the function in a set and return the final value of the set.

def collectl[T](f : scala.PartialFunction[AnyRef, T]) : (AnyRef) => scala.List[T]
Collect query results in a list. Run the function f as a top-down query on the subject term. Accumulate the values produced by the function in a list and return the final value of the list.

def count(f : scala.PartialFunction[AnyRef, Int]) : (AnyRef) => Int
Count function results. Run the function f as a top-down query on the subject term. Sum the integer values returned by f from all applications.

def attempt(s : => Strategy) : Strategy
Construct a strategy that applies s, yielding the result of s if it succeeds, otherwise leave the original subject term unchanged. In Stratego library this strategy is called "try".

def repeat(s : => Strategy) : Strategy
Construct a strategy that applies s repeatedly until it fails.

def repeat(s : => Strategy, c : => Strategy) : Strategy
Construct a strategy that repeatedly applies s until it fails and then terminates with application of c.

def repeat(s : => Strategy, n : Int) : Strategy
Construct a strategy that applies s repeatedly exactly n times. If s fails at some point during the n applications, the entire strategy fails. The result of the strategy is that of the nth application of s.

def repeat1(s : => Strategy, c : => Strategy) : Strategy
Construct a strategy that repeatedly applies s (at least once) and terminates with application of c.

def repeat1(s : => Strategy) : Strategy
Construct a strategy that repeatedly applies s (at least once).

def repeatuntil(s : => Strategy, c : => Strategy) : Strategy
Construct a strategy that repeatedly applies s until c succeeds.

def loop(c : => Strategy, s : => Strategy) : Strategy
Construct a strategy that while c succeeds applies s. This operator is called "while" in the Stratego library.

def loopnot(c : => Strategy, s : => Strategy) : Strategy
Construct a strategy that while c does not succeed applies s. This operator is called "while-not" in the Stratego library.

def doloop(s : => Strategy, c : => Strategy) : Strategy
Construct a strategy that applies s at least once and then repeats s while c succeeds. This operator is called "do-while" in the Stratego library.

def loopiter(i : => Strategy, c : => Strategy, s : => Strategy) : Strategy
Construct a strategy that repeats application of s while c fails, after initialization with i. This operator is called "for" in the Stratego library.

def loopiter(s : (Int) => Strategy, low : Int, up : Int) : Strategy
Construct a strategy that applies s (i) for each integer i from low to up (inclusive). This operator is called "for" in the Stratego library.

def not(s : => Strategy) : Strategy
Construct a strategy that applies s, then fails if s succeeded or, if s failed, succeeds with the subject term unchanged, I.e., it tests if s applies, but has no effect on the subject term.

def where(s : => Strategy) : Strategy
Construct a strategy that tests whether strategy s succeeds, restoring the original term on success. This is similar to Stratego's "where", except that in this version any effects on bindings are not visible outside s.

def test(s : => Strategy) : Strategy
Construct a strategy that tests whether strategy s succeeds, restoring the original term on success. A synonym for where.

def breadthfirst(s : => Strategy) : Strategy
Construct a strategy that applies s in breadth first order.

def topdown(s : => Strategy) : Strategy
Construct a strategy that applies s in a top-down, prefix fashion to the subject term.

def topdownS(s : => Strategy, stop : (Strategy) => Strategy) : Strategy
Construct a strategy that applies s in a top-down, prefix fashion to the subject term but stops when stop succeeds.

def bottomup(s : => Strategy) : Strategy
Construct a strategy that applies s in a bottom-up, postfix fashion to the subject term.

def bottomupS(s : => Strategy, stop : (Strategy) => Strategy) : Strategy
Construct a strategy that applies s in a bottom-up, postfix fashion to the subject term but stops when stop succeeds.

def downup(s : => Strategy) : Strategy
Construct a strategy that applies s in a combined top-down and bottom-up fashion (i.e., both prefix and postfix) to the subject term.

def downup(s1 : => Strategy, s2 : => Strategy) : Strategy
Construct a strategy that applies s1 in a top-down, prefix fashion and s2 in a bottom-up, postfix fashion to the subject term.

def downupS(s : => Strategy, stop : (Strategy) => Strategy) : Strategy
Construct a strategy that applies s in a combined top-down and bottom-up fashion (i.e., both prefix and postfix) to the subject term but stops when stop succeeds.

def downupS(s1 : => Strategy, s2 : => Strategy, stop : (Strategy) => Strategy) : Strategy
Construct a strategy that applies s1 in a top-down, prefix fashion and s2 in a bottom-up, postfix fashion to the subject term but stops when stop succeeds.

def dontstop(s : => Strategy) : Strategy
A unit for topdownS, bottomupS and downupS. For example, topdown (s) is equivalent to topdownS (s, dontstop).

def oncetd(s : => Strategy) : Strategy
Construct a strategy that applies s in a top-down fashion to one subterm at each level, stopping as soon as it succeeds once (at any level).

def oncebu(s : => Strategy) : Strategy
Construct a strategy that applies s in a bottom-up fashion to one subterm at each level, stopping as soon as it succeeds once (at any level).

def sometd(s : => Strategy) : Strategy
Construct a strategy that applies s in a top-down fashion to some subterms at each level, stopping as soon as it succeeds once (at any level).

def somebu(s : => Strategy) : Strategy
Construct a strategy that applies s in a bottom-up fashion to some subterms at each level, stopping as soon as it succeeds once (at any level).

def outermost(s : => Strategy) : Strategy
Construct a strategy that applies s repeatedly in a top-down fashion stopping each time as soon as it succeeds once (at any level). The outermost fails when s fails to apply to any (sub-)term.

def innermost(s : => Strategy) : Strategy
Construct a strategy that applies s repeatedly to the innermost (i.e., lowest and left-most) (sub-)term to which it applies. Stop with the current term if s doesn't apply anywhere.

def innermost2(s : => Strategy) : Strategy
An alternative version of innermost.

def reduce(s : => Strategy) : Strategy
Construct a strategy that applies s repeatedly to subterms until it fails on all of them.

def alltd(s : => Strategy) : Strategy
Construct a strategy that applies s in a top-down fashion, stopping at a frontier where s succeeds.

def alldownup2(s1 : => Strategy, s2 : => Strategy) : Strategy
Construct a strategy that applies s1 in a top-down, prefix fashion stopping at a frontier where s succeeds. s2 is applied in a bottom-up, postfix fashion to the result.

def alltdfold(s1 : => Strategy, s2 : => Strategy) : Strategy
Construct a strategy that applies s1 in a top-down, prefix fashion stopping at a frontier where s succeeds. s2 is applied in a bottom-up, postfix fashion to the results of the recursive calls.

def somedownup(s : => Strategy) : Strategy
Construct a strategy that applies s1 in a top-down, prefix fashion stopping at a frontier where s succeeds on some children. s2 is applied in a bottom-up, postfix fashion to the subject term the result.

def manybu(s : Strategy) : Strategy
Construct a strategy that applies s as many times as possible, but at least once, in bottom up order.

def manytd(s : Strategy) : Strategy
Construct a strategy that applies s as many times as possible, but at least once, in top down order.

def leaves(s : => Strategy, isleaf : => Strategy) : Strategy
Construct a strategy that applies to all of the leaves of the current term, using isleaf as the leaf predicate.

def leaves(s : => Strategy, isleaf : => Strategy, skip : (Strategy) => Strategy) : Strategy
Construct a strategy that applies to all of the leaves of the current term, using isleaf as the leaf predicate, skipping subterms for which skip succeeds.

def everywherebu(s : => Strategy) : Strategy
Construct a strategy that applies s at every term in a bottom-up fashion regardless of failure. (Sub-)terms for which the strategy fails are left unchanged.

def everywheretd(s : => Strategy) : Strategy
Construct a strategy that applies s at every term in a top-down fashion regardless of failure. (Sub-)terms for which the strategy fails are left unchanged.

def restore(s : => Strategy, rest : => Strategy) : Strategy
Apply restoring action 'rest' if s fails, and then fail. Typically useful if s performs side effects that should be restored/undone in case s fails.

def restorealways(s : => Strategy, rest : => Strategy) : Strategy
Apply restoring action 'rest' after s terminates, and preserve success/failure behaviour of s. Typically useful if s performs side effects that should be restored always, e.g., when maintaining scope information.

def lastly(s : => Strategy, f : => Strategy) : Strategy
Applies s followed by f whether s failed or not. This operator is called "finally" in the Stratego library.

def ior(s1 : => Strategy, s2 : => Strategy) : Strategy
ior (s1, s2) implements 'inclusive or', that is, the inclusive choice of s1 and s2. It first tries s1, if that fails it applies s2 (just like s1 <+ s2). However, when s1 succeeds it also tries to apply s2. The results of the transformations are returned.

def or(s1 : => Strategy, s2 : => Strategy) : Strategy
or (s1, s2) is similar to ior (s1,s2), but the application of the strategies is only tested.

def and(s1 : => Strategy, s2 : => Strategy) : Strategy
and (s1, s2) applies s1 and s2 to the current term and succeeds if both succeed. s2 will always be applied, i.e., and is *not* a short-circuit operator