Package lepl :: Package matchers :: Module transform
[hide private]
[frames] | no frames]

Module transform

source code

A transformation is a function that modifies the result of calling a matcher

From the point of view of a transformation, a matcher is a function that 
takes no arguments and either returns (results, stream_out) or raises a 
StopIteration (note - this is an interface - the way you typically define 
matchers doesn't conform to that interface, but decorators like 
@function_matcher etc do the necessary work to adapt things as necessary).

A transformation takes two arguments - the initial stream and a matcher 
(as described above).  The transformation, when called, should return 
either return a (result, stream_out) pair, or raise a StopIteration.  
A null transformation, therefore, would simply evaluate the matcher it 
    null_transform = lambda stream, matcher: matcher()

Classes [hide private]
Helper object that composes transformations and also keeps a list of the separate transformations for introspection.
Apply a function to (stream_in, matcher)
Functions [hide private]
Let raise be used as a function.
source code
Raise StopIteration if the matcher returns an empty result.
source code
PostCondition(matcher, predicate)
Apply the predicate to each result in turn and return the result only if it is always True.
source code
Variables [hide private]
  ApplyRaw = ABCMeta('ApplyRaw', (object,), {})
ABC used to control Apply, so that the result is not wrapped in a list.
  ApplyArgs = ABCMeta('ApplyArgs', (object,), {})
ABC used to control Apply, so that the results list is supplied as "*args".
Function Details [hide private]


source code 

Raise StopIteration if the matcher returns an empty result.

This can be useful when using a transform that raise a StopIteration because that only "vetoes" the answer, which might leave an empty list.

  • @trampoline_matcher_factory()