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

Module support

source code

Support classes for matchers.
Classes [hide private]
  BaseMatcher
A base class that provides support to all matchers.
  TreeStr
  OperatorMatcher
A base class that provides support to all matchers with operators.
  Transformable
All subclasses must expose and apply wrapper, and implement compose.
  BaseFactoryMatcher
This must be used as a mixin with something that inherits from ArgsAsAttribute (ie the usual matcher classes).
  TransformableWrapper
A common support class for various wrappers.
  TransformableTrampolineWrapper
A wrapper for source of generators that evaluate other matchers via the trampoline (ie for generators that evaluate matchers via yield).
  TrampolineWrapper
A wrapper for source of generators that evaluate other matchers via the trampoline (ie for generators that evaluate matchers via yield).
  NoTrampoline
A matcher that does not require the trampoline.
  NoTrampolineWrapper
A wrapper for source of generators that do not evaluate other matchers via the trampoline.
  SequenceWrapper
A wrapper for simple generator factories, where the final matcher is a function that yields a series of matches without evaluating other matchers via the trampoline.
  FunctionWrapper
A wrapper for simple function factories, where the final matcher is a function that returns a single match or None.
Functions [hide private]
 
check_matcher(matcher)
Check that the signature takes support + stream.
source code
 
check_args(func)
Check that the factory doesn't use any of those modern haifalutin extensions...
source code
 
check_modifiers(func, modifiers)
Check that any modifiers match the function declaration.
source code
 
apply_modifiers(func, args, kargs, modifiers, margs, mkargs)
Modify values in args and kargs.
source code
 
make_wrapper_factory(wrapper, factory, modifiers, margs=identity, mkargs=identity, memo=True)
A helper function that assembles a matcher from a wrapper class and a factory function that contains the logic.
source code
 
make_factory(maker, matcher)
A helper function that assembles a matcher from a wrapper class and a function that contains the logic.
source code
 
keep_gate(gatekeeper, name) source code
 
trampoline_matcher_factory(gatekeeper_=None, args_=identity, kargs_=identity, **kargs)
Decorator that allows matchers to be defined using a nested pair of functions.
source code
 
trampoline_matcher(matcher)
Decorator that allows matchers to be defined using a single function to implement the matcher logic.
source code
 
sequence_matcher_factory(gatekeeper_=None, args_=identity, kargs_=identity, **kargs)
Decorator that allows matchers to be defined using a nested pair of functions.
source code
 
sequence_matcher(matcher)
Decorator that allows matchers to be defined using a single function to implement the matcher logic.
source code
 
function_matcher_factory(gatekeeper_=None, args_=identity, kargs_=identity, **kargs)
Decorator that allows matchers to be defined using a nested pair of functions.
source code
 
function_matcher(matcher)
Decorator that allows matchers to be defined using a single function to implement the matcher logic.
source code
 
coerce_(arg, function=None)
Many arguments can take a string which is implicitly converted (via this function) to a literal (or similar).
source code
 
to(function)
Generate a coercion for later application.
source code
Variables [hide private]
  NoMemo = ABCMeta('NoMemo', (object,), {})
ABC used to indicate that memoisation should not be applied.
Function Details [hide private]

make_wrapper_factory(wrapper, factory, modifiers, margs=identity, mkargs=identity, memo=True)

source code 

A helper function that assembles a matcher from a wrapper class and a factory function that contains the logic.

wrapper is the class that will be constructed, and which will contain the functionality defined in factory.

modifiers is a map of functions applied to arguments of the given name. Similarly, margs and mkargs apply to varargs.

memo should be set to False for matchers that do not want memoisation.

make_factory(maker, matcher)

source code 

A helper function that assembles a matcher from a wrapper class and a function that contains the logic.

This works by generating a dummy factory and delegating to make_wrapper_factory.

trampoline_matcher_factory(gatekeeper_=None, args_=identity, kargs_=identity, **kargs)

source code 

Decorator that allows matchers to be defined using a nested pair of functions. The outer function acts like a constructor; the inner function implements the matcher logic.

The matcher code can evaluate sub-matchers by yielding the generator created by matcher._match() to the trampoline. Matches should also be yielded.

Other keyword arguments should match factory arguments and identify functions of one argument that are applied to the arguments when the matcher is created as part of a grammar (eg coercion). Similarly,

args_ and kargs_ are applied to varargs.

trampoline_matcher(matcher)

source code 

Decorator that allows matchers to be defined using a single function to implement the matcher logic.

The matcher code can evaluate sub-matchers by yielding the generator created by matcher._match() to the trampoline. Matches should also be yielded.

sequence_matcher_factory(gatekeeper_=None, args_=identity, kargs_=identity, **kargs)

source code 

Decorator that allows matchers to be defined using a nested pair of functions. The outer function acts like a constructor; the inner function implements the matcher logic.

The matcher must yield matches (multiple times if required). It cannot evaluate sub-matchers.

args_, kargs_ and named arguments define modifiers, which are applied to the corresponding arguments when the matcher is first used in a grammar (eg to coerce strings to Literal instances).

sequence_matcher(matcher)

source code 

Decorator that allows matchers to be defined using a single function to implement the matcher logic.

The matcher must yield matches (multiple times if required). It cannot evaluate sub-matchers.

function_matcher_factory(gatekeeper_=None, args_=identity, kargs_=identity, **kargs)

source code 

Decorator that allows matchers to be defined using a nested pair of functions. The outer function acts like a constructor; the inner function implements the matcher logic.

The matcher must return a single match. It cannot evaluate sub-matchers.

args_, kargs_ and named arguments define modifiers, which are applied to the corresponding arguments when the matcher is first used in a grammar (eg to coerce strings to Literal instances).

function_matcher(matcher)

source code 

Decorator that allows matchers to be defined using a single function to implement the matcher logic.

The matcher must return a single match. It cannot evaluate sub-matchers.