Trait/Object

sigmastate.kiama.rewriting

Rewriter

Related Docs: object Rewriter | package rewriting

Permalink

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.

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Rewriter
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. object Duplicator

    Permalink

    General product duplication functionality.

    General product duplication functionality. This object is a function that returns a product that applies the same constructor as the product t, but with the given children instead of t's children. The function fails if a constructor cannot be found, there are the wrong number of new children, or if one of the new children is not of the appropriate type.

  5. object Term

    Permalink

    Generic term deconstruction.

  6. def all(s: ⇒ Strategy): Strategy

    Permalink

    Traversal to all children.

    Traversal to all children. Construct a strategy that applies s to all term children of the subject term. 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. If there are no children, succeed. If s succeeds on all children producing the same terms (by eq for references and by == for other values), then the overall strategy returns the subject term. This operation works on finite Rewritable, Product, Map and Iterable values, checked for in that order. Children of a Rewritable (resp. Product, collection) value are processed in the order returned by the value's deconstruct (resp. productElement, foreach) method. s is evaluated at most once.

  7. def allIterable[CC[U] <: Iterable[U]](s: Strategy, t: CC[Any])(implicit cbf: CanBuildFrom[CC[Any], Any, CC[Any]]): Option[CC[Any]]

    Permalink

    Implementation of all for Iterable values.

  8. def allMap[CC[V, W] <: Map[V, W]](s: Strategy, t: CC[Any, Any])(implicit cbf: CanBuildFrom[CC[Any, Any], (Any, Any), CC[Any, Any]]): Option[CC[Any, Any]]

    Permalink

    Implementation of all for Map values.

  9. def allProduct(s: Strategy, p: Product): Option[Any]

    Permalink

    Implementation of all for Product values.

  10. def and(s1: Strategy, s2: Strategy): Strategy

    Permalink

    and(s1, s2) applies s1 and s2 to the subject term and succeeds if both succeed.

    and(s1, s2) applies s1 and s2 to the subject term and succeeds if both succeed. s2 will always be applied, i.e., and is not a short-circuit operator.

  11. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  12. def attempt(s: Strategy): Strategy

    Permalink

    Construct a strategy that applies s, yielding the result of s if it succeeds, otherwise leave the original subject term unchanged.

    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.

  13. def bottomup(s: Strategy): Strategy

    Permalink

    Construct a strategy that applies s in a bottom-up, postfix fashion to the subject term.

  14. def build(t: Any): Strategy

    Permalink

    Construct a strategy that always succeeds, changing the subject term to the given term t.

    Construct a strategy that always succeeds, changing the subject term to the given term t. The term t is evaluated at most once.

  15. def child(i: Int, s: ⇒ Strategy): Strategy

    Permalink

    Traversal to a single child.

    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. If s succeeds on the ith child producing the same term (by eq for references and by == for other values), then the overall strategy returns the subject term. This operation works for instances of Product or finite Seq values. s is evaluated at most once.

  16. def childProduct(s: Strategy, i: Int, p: Product): Option[Any]

    Permalink

    Implementation of child for Product values.

  17. def childSeq[CC[U] <: Seq[U]](s: Strategy, i: Int, t: CC[Any])(implicit cbf: CanBuildFrom[CC[Any], Any, CC[Any]]): Option[CC[Any]]

    Permalink

    Implementation of child for Seq values.

  18. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. def collect[CC[X] <: Iterable[X], U](f: ==>[Any, U])(implicit cbf: Factory[U, CC[U]]): (Any) ⇒ CC[U]

    Permalink

    Collect query results in a Iterable collection.

    Collect query results in a Iterable collection. Run the function f as a top-down left-to-right query on the subject term. Each application of f returns a single value. All of these values are accumulated in the collection.

  20. def copy[T <: Product](t: T): T

    Permalink

    Copy a product node by creating a new node of the same class type using the same children.

  21. def count(f: ==>[Any, Int]): (Any) ⇒ Int

    Permalink

    Count function results.

    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.

  22. def dup[T <: Product](t: T, children: Array[AnyRef]): T

    Permalink

    The duplicator used by the generic traversals.

    The duplicator used by the generic traversals. Needs to be defined as a method so we can override it in other rewriting modules.

  23. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  24. val eq: Strategy

    Permalink

    A strategy that tests whether the two sub-terms of a pair of terms are equal.

  25. val equal: Strategy

    Permalink

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

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

  26. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  27. def everything[T](v: T)(f: (T, T) ⇒ T)(g: ==>[Any, T])(t: Any): T

    Permalink

    Apply the function at every term in t in a top-down, left-to-right order.

    Apply the function at every term in t in a top-down, left-to-right order. Collect the resulting T values by accumulating them using f with initial left value v. Return the final value of the accumulation.

  28. def everywhere(s: Strategy): Strategy

    Permalink

    Same as everywheretd.

  29. def everywherebu(s: Strategy): Strategy

    Permalink

    Construct a strategy that applies s at all terms in a bottom-up fashion regardless of failure.

    Construct a strategy that applies s at all terms in a bottom-up fashion regardless of failure. Terms for which the strategy fails are left unchanged.

  30. def everywheretd(s: Strategy): Strategy

    Permalink

    Construct a strategy that applies s at all terms in a top-down fashion regardless of failure.

    Construct a strategy that applies s at all terms in a top-down fashion regardless of failure. Terms for which the strategy fails are left unchanged.

  31. val fail: Strategy

    Permalink

    A strategy that always fails.

  32. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  33. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  34. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  35. val id: Strategy

    Permalink

    A strategy that always succeeds.

  36. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  37. def loop(c: Strategy, s: Strategy): Strategy

    Permalink

    Construct a strategy that while r succeeds applies s.

    Construct a strategy that while r succeeds applies s. This operator is called while in the Stratego library.

  38. def loopiter(s: (Int) ⇒ Strategy, low: Int, high: Int): Strategy

    Permalink

    Construct a strategy that applies s(i) for each integer i from low to high (inclusive).

    Construct a strategy that applies s(i) for each integer i from low to high (inclusive). This operator is called for in the Stratego library.

  39. def makechild(c: Any): AnyRef

    Permalink

    Make an arbitrary value c into a term child, checking that it worked properly.

    Make an arbitrary value c into a term child, checking that it worked properly. Object references will be returned unchanged; other values will be boxed.

    Attributes
    protected
  40. def map(s: Strategy): Strategy

    Permalink

    Construct a strategy that applies s to each element of a finite sequence (type Seq) returning a new sequence of the results if all of the applications succeed, otherwise fail.

    Construct a strategy that applies s to each element of a finite sequence (type Seq) returning a new sequence of the results if all of the applications succeed, otherwise fail. If all of the applications succeed without change, return the input sequence.

  41. def mkStrategy(f: (Any) ⇒ Option[Any]): Strategy

    Permalink

    Make a strategy with the body f.

    Make a strategy with the body f. By default, make a basic strategy.

  42. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  43. def not(s: Strategy): Strategy

    Permalink

    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.

  44. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  45. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  46. def one(s: ⇒ Strategy): Strategy

    Permalink

    Traversal to one child.

    Traversal to one child. Construct a strategy that applies s to the term children of the subject term. 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. If there are no children, fail. If s succeeds on the one child producing the same term (by eq for references and by == for other values), then the overall strategy returns the subject term. This operation works on instances of finite Rewritable, Product, Map and Iterable values, checked for in that order. Children of a Rewritable (resp. Product, collection) value are processed in the order returned by the value's deconstruct (resp. productElement, foreach) method. s is evaluated at most once.

  47. def oneIterable[CC[U] <: Iterable[U]](s: Strategy, t: CC[Any])(implicit cbf: CanBuildFrom[CC[Any], Any, CC[Any]]): Option[CC[Any]]

    Permalink

    Implementation of one for Iterable values.

  48. def oneMap[CC[V, W] <: Map[V, W]](s: Strategy, t: CC[Any, Any])(implicit cbf: CanBuildFrom[CC[Any, Any], (Any, Any), CC[Any, Any]]): Option[CC[Any, Any]]

    Permalink

    Implementation of one for Map values.

  49. def oneProduct(s: Strategy, p: Product): Option[Any]

    Permalink

    Implementation of one for Product values.

  50. def or(s1: Strategy, s2: Strategy): Strategy

    Permalink

    or(s1, s2) is similar to ior(s1, s2), but the application of the strategies is only tested.

  51. def para[T](f: (Any, Seq[T]) ⇒ T): (Any) ⇒ T

    Permalink

    Perform a paramorphism over a value.

    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 values that are supported by the Term generic term deconstruction. This operation is similar to that used in the Uniplate library.

  52. def query[T](f: ==>[T, Unit]): Strategy

    Permalink

    Define a term query by a partial function f.

    Define a term query by a partial function f. The query always succeeds with no effect on the subject term but applies the given partial function f to the subject term. In other words, the strategy runs f for its side-effects. If the subject term is not a T or the function is not defined at the subject term, the strategy fails.

    Due to the type erasure performed on Scala programs the type test will be imprecise for some types. E.g., it is not possible to tell the difference between List[Int] and List[String].

  53. def reduce(s: Strategy): Strategy

    Permalink

    Construct a strategy that applies s repeatedly to subterms until it fails on all of them.

  54. def repeat(s: Strategy, n: Int): Strategy

    Permalink

    Construct a strategy that applies s repeatedly exactly n times.

    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.

  55. def repeat(s: Strategy): Strategy

    Permalink

    Construct a strategy that applies s repeatedly until it fails.

  56. def rewrite[T](s: Strategy)(t: T): T

    Permalink

    Rewrite a term.

    Rewrite a term. Apply the strategy s to a term returning the result term if s succeeds, otherwise return the original term.

  57. def rule[T](f: ===>[T]): Strategy

    Permalink

    Define a rewrite rule using a partial function f defined on the type T.

    Define a rewrite rule using a partial function f defined on the type T. If the subject term is a T and the function is defined at the subject term, then the strategy succeeds with the return value of the function applied to the subject term. Otherwise, the strategy fails.

    Due to the type erasure performed on Scala programs the type test will be imprecise for some types. E.g., it is not possible to tell the difference between List[Int] and List[String].

  58. def rulef(f: (Any) ⇒ Any): Strategy

    Permalink

    Define a rewrite rule using a function f that returns a term.

    Define a rewrite rule using a function f that returns a term. The rule always succeeds with the return value of the function.

  59. def rulefs[T](f: ==>[T, Strategy]): Strategy

    Permalink

    Define a rewrite rule using a function f defined on type T that returns a strategy.

    Define a rewrite rule using a function f defined on type T that returns a strategy. If the subject term is a T and the function is defined at the subject term, the rule applies the function to the subject term to get a strategy which is then applied again to the subject term. In other words, the function is only used for effects such as pattern matching. The whole thing also fails if f is not defined at the term in the first place.

  60. def some(s: ⇒ Strategy): Strategy

    Permalink

    Traversal to as many children as possible, but at least one.

    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. 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 s fails on all children, then fail. If there are no children, fail. If s succeeds on children producing the same terms (by eq for references and by == for other values), then the overall strategy returns the subject term. This operation works on instances of finite Rewritable, Product, Map and Iterable values, checked for in that order. Children of a Rewritable (resp. Product, collection) value are processed in the order returned by the value's deconstruct (resp. productElement, foreach) method. s is evaluated at most once.

  61. def someIterable[CC[U] <: Iterable[U]](s: Strategy, t: CC[Any])(implicit cbf: CanBuildFrom[CC[Any], Any, CC[Any]]): Option[CC[Any]]

    Permalink

    Implementation of some for Iterable values.

  62. def someMap[CC[V, W] <: Map[V, W]](s: Strategy, t: CC[Any, Any])(implicit cbf: CanBuildFrom[CC[Any, Any], (Any, Any), CC[Any, Any]]): Option[CC[Any, Any]]

    Permalink

    Implementation of some for Map values.

  63. def someProduct(s: Strategy, p: Product): Option[Any]

    Permalink

    Implementation of some for Product values.

  64. def strategy[T](f: ==>[T, Option[T]]): Strategy

    Permalink

    Make a strategy from a partial function f defined on the type T.

    Make a strategy from a partial function f defined on the type T. If the subject term is a T and the function is defined at the subject term, then the function return value when applied to the subject term determines whether the strategy succeeds or fails. If the subject term is not a T or the function is not defined at the subject term, the strategy fails.

    Due to the type erasure performed on Scala programs the type test will be imprecise for some types. E.g., it is not possible to tell the difference between List[Int] and List[String].

  65. def strategyf(f: (Any) ⇒ Option[Any]): Strategy

    Permalink

    Make a strategy from a function f.

    Make a strategy from a function f. The function return value determines whether the strategy succeeds or fails.

  66. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  67. def term[T](t: T): Strategy

    Permalink

    Construct a strategy that succeeds only if the subject term matches the given term t.

  68. def test(s: Strategy): Strategy

    Permalink

    Construct a strategy that tests whether strategy s succeeds, restoring the original term on success.

    Construct a strategy that tests whether strategy s succeeds, restoring the original term on success. A synonym for where.

  69. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  70. def topdown(s: Strategy): Strategy

    Permalink

    Construct a strategy that applies s in a top-down, prefix fashion to the subject term.

  71. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  72. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  73. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  74. def where(s: Strategy): Strategy

    Permalink

    Construct a strategy that tests whether strategy s succeeds, restoring the original term on success.

    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.

Inherited from AnyRef

Inherited from Any

Ungrouped