Node - a base class for syntax tree nodes


All PAST and POST nodes subclass from this base type.

Accessor Methods ^

These methods define the external interface of node objects.

source ^

Sets or gets the source code string that a particular node was parsed from. (Useful for debugging output.)

    $S2 = node.'source'()

pos ^

Sets or gets the position offset in the original source code file that a particular node was parsed from. (Useful for debugging output.)

    $S2 = node.'pos'()

children ^

Returns a simple array of the children of a particular node.

    $P1 = node.'children'()

child_iter ^

Returns an iterator for the children of a node.

    iter = node.'child_iter'()

add_child ^

Adds one child to the node's list of children. If the list doesn't exist yet, it creates it.


elements ^

Check how many elements a node has by calling the elements opcode on it:

    $I1 = elements node

Array interface ^

The children of a node can be directly accessed using array indexes on the node object.

    $P2 = node[5]
    node[0] = $P1

clone ^

This method captures a few key elements from an existing node to populate a new node.


dump ^

Recursively prints a formatted display of the contents of a node.


Utility Methods ^

These methods provide functionality for the Node class and its subclasses, but aren't part of the external interface for the class.


This method returns a list of attributes that should be displayed in a 'dump' operation. Subclasses can override it to return a different list.

accessor ^

Provides a generic accessor method that can be used by any subclass. It takes three arguments: the name of the attribute to access, a value for the attribute, and a binary flag that says whether to set the attribute.

    self.'accessor'('attrname', value, setflag)