Package rxpy :: Package graph :: Module support :: Class BaseNode
[hide private]
[frames] | no frames]

Class BaseNode

source code


Subclasses describe ordered actions (typically, matches) to be made.

This base class provides support for constructing and connecting nodes, cloning them, and displaying them in GraphViz.

Nodes accessible from this instance are visible in .next.

For automatic cloning, subclasses should have a public attribute for each constructor karg (and no additional public attributes). Note that graph nodes are not exposed as part of the public API - they are purely internal to RXPY.

This class is designed to support both simple nodes (an instance is a graph node) and complex nodes (an instance describes some subset of the graph with a single entry node, and which will be given a single exit node). Complex nodes are used during construction of the graph (eg for sequences and alternatives), but final connection of nodes connects the individual sub-nodes.

Instance Methods [hide private]
 
__init__(self, consumer=True, size=None)
Subclasses should pay attention to the relationship between constructor kargs and attributes assumed in .clone.
source code
 
consumer(self)
Does this node consume data from the input string? This is used to detect errors (if False, repeating with * or + would not terminate).
source code
 
size(self, groups)
The number of characters matched by this and subsequence nodes, if known, otherwise None.
source code
 
start(self)
The node to connect to when connecting to "this" node.
source code
 
concatenate(self, next)
The given node is the next node in the sequence.
source code
 
__repr__(self)
Generate a description of this node and accessible children which can be used to plot the graph in GraphViz.
source code
 
__str__(self)
Subclasses must implement something useful here, which will be displayed in the graphviz node (see repr).
source code
 
clone(self, cache=None)
Duplicate this node (necessary when replacing a numbered repeat with explicit, repeated, instances, for example).
source code
 
__clone_next(self, cache)
Clone child nodes, using the cache where appropriate.
source code
 
_node_eq(self, other) source code
 
deep_eq(self, other)
Used only for testing.
source code
 
_kargs(self)
Generate a list of arguments used for cloning.
source code
 
visit(self, visitor, state=None)
The visitor pattern - used to evaluate the graph by an interpreter, for example.
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, consumer=True, size=None)
(Constructor)

source code 
Subclasses should pay attention to the relationship between constructor kargs and attributes assumed in .clone.
Overrides: object.__init__

consumer(self)

source code 
Does this node consume data from the input string? This is used to detect errors (if False, repeating with * or + would not terminate).
Decorators:
  • @property

size(self, groups)

source code 
The number of characters matched by this and subsequence nodes, if known, otherwise None. Nodes must give a single, fixed number or None, so any loops should return None.

start(self)

source code 

The node to connect to when connecting to "this" node. For a simple node, this is simply 'self', but for a complex node (one that contains sub-nodes) this method must return the "entry node".

This method is only called on complex nodes after "initial node assembly" is complete (complex nodes are assembled, then connected).

Decorators:
  • @property

concatenate(self, next)

source code 

The given node is the next node in the sequence.

This method is only called on complex nodes after "initial node assembly" is complete (complex nodes are assembled, then connected). It is also only called once.

__repr__(self)
(Representation operator)

source code 
Generate a description of this node and accessible children which can be used to plot the graph in GraphViz.
Overrides: object.__repr__

__str__(self)
(Informal representation operator)

source code 
Subclasses must implement something useful here, which will be displayed in the graphviz node (see repr).
Decorators:
  • @unimplemented
Overrides: object.__str__

clone(self, cache=None)

source code 

Duplicate this node (necessary when replacing a numbered repeat with explicit, repeated, instances, for example).

This copies all "public" attributes as constructor kargs.

_kargs(self)

source code 
Generate a list of arguments used for cloning. Subclasses can over-ride this if necessary, but probably shouldn't (instead, they should have attributes that correspond to kargs).

visit(self, visitor, state=None)

source code 
The visitor pattern - used to evaluate the graph by an interpreter, for example. Calls back to the visitor via the interface described in rxpy.parser.visitor.Visitor.
Decorators:
  • @unimplemented