Package transf :: Module transformation :: Class Transformation
[frames] | no frames]

Class Transformation




Abstract class for term transformations.

A transformation takes as input a term and returns the transformed term, or raises a failure exception if it is not applicable. It also receives a transformation context to which it can read/write.

A transformation should not maintain any state itself, i.e., different calls to the apply method with the same term and context must produce the same result.

Instance Methods
 
__init__(self)
Constructor.
 
__call__(self, trm, **kargs)
User-friendly wrapper for apply.
 
apply(self, trm, ctx)
Applies the transformation to the given term with the specified context.
 
__neg__(self)
Negation operator.
 
__pos__(self)
Positive operator.
 
__add__(self, other)
Addition operator.
 
__mul__(self, other)
Multiplication operator.
 
__pow__(self, other)
Exponentiation operater.
 
__repr__(self)
repr(x)

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Properties

Inherited from object: __class__

Method Details

__init__(self)
(Constructor)

 
Constructor.
Overrides: object.__init__

apply(self, trm, ctx)

 
Applies the transformation to the given term with the specified context.
Parameters:
  • trm - Term to be transformed.
  • ctx - Transformation context.
Returns:
The transformed term on success.
Raises:

__neg__(self)

 
Negation operator. Shorthand for lib.combine.Not

__pos__(self)

 
Positive operator. Shorthand for lib.combine.Try

__add__(self, other)
(Addition operator)

 
Addition operator. Shorthand for lib.combine.Choice

__mul__(self, other)

 
Multiplication operator. Shorthand for lib.combine.Composition

__pow__(self, other)

 

Exponentiation operater. Shorthand for lib.combine.GuardedChoice.

For example, t1 **t2** t3 is equivalent, to lib.combine.GuardedChoice(t1, t2, t3). The exponentiation operator is right associative, so t1 **t2** t3 **t4** t5 is the same as t1 **t2** (t3 **t4** t5). However note that its precedence is higher than other operators, therefore parenthesis must be used around them.

See Also: http://docs.python.org/ref/summary.html for a summary of Python's operators precedence.

__repr__(self)
(Representation operator)

 
repr(x)
Overrides: object.__repr__
(inherited documentation)