class documentation

Abstract base class for Node and Leaf. This provides some default functionality and boilerplate using the template pattern. A node may be a subnode of at most one parent. Each subclass of Base must provide a __str__ implementation that returns exactly the input that was used to create the item in the tree. Each subclass of Base must provide a value attribute, and the ranges of values must be distinct for each subclass. This isn't a strict requirement, but it's convenient so that instead of writing if isinstance(node, Leaf) and node.type == TOKEN.name: you can just write if node.type == TOKEN.name:

Method __eq__ Compare two nodes for equality.
Method __ne__ Compare two nodes for inequality.
Method __new__ Constructor that prevents Base from being instantiated.
Method __str__ Undocumented
Method changed Undocumented
Method clone Return a cloned (deep) copy of self.
Method depth Undocumented
Method descend_to Takes a sequence of integers and descends via children.
Method get_lineno Return the line number which generated the invocant node.
Method get_prefix Return the prefix for the node (see Leaf class).
Method get_suffix Return the string immediately following the invocant node. This is effectively equivalent to node.next_sibling.prefix
Method label_nodes Create 'label' attritbute for each Node/Leaf.
Method leaves Undocumented
Method post_order Post-order iterator for the tree.
Method pre_order Pre-order iterator for the tree.
Method remove Remove the node from the tree. Returns the position of the node in its parent's children before it was removed.
Method replace Replace this node with a new one in the parent.
Method set_prefix Set the prefix for the node (see Leaf class).
Class Variable __hash__ Undocumented
Class Variable children Undocumented
Class Variable type Undocumented
Class Variable was_checked Undocumented
Instance Variable label Undocumented
Instance Variable parent Undocumented
Instance Variable prefix Undocumented
Instance Variable was_changed Undocumented
Property next_sibling The node immediately following the invocant in their parent's children list. If the invocant does not have a next sibling, it is None
Property prev_sibling The node immediately preceding the invocant in their parent's children list. If the invocant does not have a previous sibling, it is None.
Property type_repr Get the type as a human-readable string.
Method _eq Compare two nodes for equality.
def __eq__(self, other): (source)

Compare two nodes for equality. This calls the method _eq().

def __ne__(self, other): (source)

Compare two nodes for inequality. This calls the method _eq().

def __new__(cls, *args, **kwds): (source)

Constructor that prevents Base from being instantiated.

def __str__(self): (source)

Undocumented

def changed(self): (source)

Undocumented

def clone(self): (source)

Return a cloned (deep) copy of self. This must be implemented by the concrete subclass.

def depth(self): (source)

Undocumented

def descend_to(self, indexes): (source)

Takes a sequence of integers and descends via children. For example, descend_to([]) returns self; descend_to([0]) returns self.children[0]; descend_to([2,5,3]) returns self.children[2].children[5],children[3]. In effect, this gives each node a unique number, which is the list of child # that is needed to get to it.

def get_lineno(self): (source)

Return the line number which generated the invocant node.

def get_prefix(self): (source)

Return the prefix for the node (see Leaf class). DEPRECATED; use the prefix property directly.

def get_suffix(self): (source)

Return the string immediately following the invocant node. This is effectively equivalent to node.next_sibling.prefix

def label_nodes(self, indexes=None): (source)

Create 'label' attritbute for each Node/Leaf. Args: indexes is used internally to keep track of the path to here.

def leaves(self): (source)

Undocumented

def post_order(self): (source)

Post-order iterator for the tree. This must be implemented by the concrete subclass.

def pre_order(self): (source)

Pre-order iterator for the tree. This must be implemented by the concrete subclass.

def remove(self): (source)

Remove the node from the tree. Returns the position of the node in its parent's children before it was removed.

def replace(self, new): (source)

Replace this node with a new one in the parent.

def set_prefix(self, prefix): (source)

Set the prefix for the node (see Leaf class). DEPRECATED; use the prefix property directly.

__hash__ = (source)

Undocumented

Undocumented

was_checked: bool = (source)

Undocumented

Undocumented

Undocumented

was_changed: bool = (source)

Undocumented

@property
next_sibling = (source)

The node immediately following the invocant in their parent's children list. If the invocant does not have a next sibling, it is None

@property
prev_sibling = (source)

The node immediately preceding the invocant in their parent's children list. If the invocant does not have a previous sibling, it is None.

Get the type as a human-readable string.

def _eq(self, other): (source)

Compare two nodes for equality. This is called by __eq__ and __ne__. It is only called if the two nodes have the same type. This must be implemented by the concrete subclass. Nodes should be considered equal if they have the same structure, ignoring the prefix string and other context information.