Package lepl :: Package regexp :: Module core :: Class NfaPattern
[hide private]
[frames] | no frames]

Class NfaPattern

source code


Given a graph this constructs a transition table and an associated matcher. The matcher attempts to find longest matches but does not guarantee termination (if a possible empty match is repeated).

Note that the matcher returns a triple, including label. This is not the same interface as the matchers used in recursive descent parsing.

Evaluation order for transition: - Transition with character, if defined - Empty transition to largest numbered node these ensure we do deepest match first.

Instance Methods [hide private]
 
__init__(self, graph, alphabet)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
__build_table(self)
Rewrite the graph as a transition table, with appropriate ordering.
source code
 
match(self, stream)
Use the table to match a stream.
source code
 
__repr__(self)
repr(x)
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, graph, alphabet)
(Constructor)

source code 
x.__init__(...) initializes x; see help(type(x)) for signature
Overrides: object.__init__
(inherited documentation)

match(self, stream)

source code 

Use the table to match a stream.

The stack holds the current state, which is consumed from left to
right.  An entry on the stack contains:

  - map_ - a map from character to [(dest state, terminals)]

  - matched - the [(dest state, terminals)] generated by the map for
    a given character

  - empties - empty transitions for this state

  - match - the current match, as a list of tokens consumed from the 
  stream

  - stream - the current stream

__repr__(self)
(Representation operator)

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