Module transform
source code
A transformation is a function that modifies the result of calling a matcher
once.
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
receives:
null_transform = lambda stream, matcher: matcher()
|
|
|
|
|
Assert(matcher)
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
|
|
|
|
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".
|
|
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.
- Decorators:
@trampoline_matcher_factory()
|