Package lepl :: Package regexp :: Module rewriters
[hide private]
[frames] | no frames]

Module rewriters

source code

Rewrite the tree of matchers from the bottom up (as far as possible) using regular expressions. This is complicated by a number of things.

First, intermediate parts of regular expressions are not matchers, so we need to keep them inside a special container type that we can detect and convert to a regular expression when needed (since at some point we cannot continue with regular expressions).

Second, we sometimes do not know if our regular expression can be used until we have moved higher up the matcher tree. For example, And() might convert all sub-expressions to a sequence if it's parent is an Apply(add). So we may need to store several alternatives, along with a way of selecting the correct alternative.

So cloning a node may give either a matcher or a container. The container will provide both a matcher and an intermediate regular expression. The logic for handling odd dependencies is more difficult to implement in a general way, because it is not clear what all cases may be. For now, therefore, we use a simple state machine approach using a tag (which is almost always None).

Classes [hide private]
  RegexpContainer
The container referred to above, which carries a regular expression and an alternative matcher "up the tree" during rewriting.
  Unsuitable
Exception thrown when a sub-node does not contain a suitable matcher.
  CompileRegexp
A rewriter that uses the given alphabet and matcher to compile simple matchers.
Functions [hide private]
 
single(alphabet, node, regexp, regexp_type, wrapper=None)
Create a matcher for the given regular expression.
source code
 
empty_adapter(_stream, matcher)
There is a fundamental mismatch between regular expressions and the recursive descent parser on how empty matchers are handled.
source code
 
make_clone(alphabet_, old_clone, regexp_type, use_from_start)
Factory that generates a clone suitable for rewriting recursive descent to regular expressions.
source code
Function Details [hide private]

empty_adapter(_stream, matcher)

source code 
There is a fundamental mismatch between regular expressions and the recursive descent parser on how empty matchers are handled. The main parser uses empty lists; regexp uses an empty string. This is a hack that converts from one to the other. I do not see a better solution.