raesl.compile.ast.nodes#

Node classes representing elementary and combined flows.

Module Contents#

Classes#

Node

Abstract class for nodes.

VarNode

Abstract base class of a variable or parameter node that can be shared with

ElementaryVarNode

Elementary variable/parameter node.

CompoundVarNode

Grouped variable/parameter node.

GroupNode

Class describing content of a variable group. Unlike the VarNode above,

class raesl.compile.ast.nodes.Node(name_tok: raesl.compile.scanner.Token)#

Abstract class for nodes.

Note that a Node only has a name. The typed sub-tree starts with VarNode.

Parameters:

name_tok – Name of the node.

class raesl.compile.ast.nodes.VarNode(name_tok: raesl.compile.scanner.Token, the_type: raesl.compile.ast.types.BaseType)#

Bases: Node

Abstract base class of a variable or parameter node that can be shared with variable groups and other users such as transformations and goals.

Parameters:
  • name_tok – Token with the name/location of the variable or parameter.

  • the_type – Type of the variable or parameter.

abstract resolve_node(name: str) VarNode | None#

Find the varparam (sub)node that matches the provided dotted ‘name’.

Parameters:

name – Possibly dotted name that should point at an existing sub-node. The empty string denotes ‘self’.

Returns:

The node that matches the name, or None if no such node exists. In the

latter case, use ‘self.get_error_position(name)’ to get an indication where the match fails in the name.

abstract get_error_position(name: str) int#

Return the index in the given string where an error occurs in resolving the node.

Parameters:

name – Name of the element to find.

Returns:

Approximated index in the string where matching the element fails.

Returned value has no meaning if resolving a node succeeds.

abstract add_comment(comment_tok: raesl.compile.scanner.Token)#

Add found documentation comment.

Parameters:

comment_tok – The raw documentation token to add.

class raesl.compile.ast.nodes.ElementaryVarNode(name_tok: raesl.compile.scanner.Token, the_type: raesl.compile.ast.types.BaseType, counter: raesl.compile.typechecking.compdef_builder.Counter)#

Bases: VarNode, raesl.compile.ast.comment_storage.DocElement

Elementary variable/parameter node.

Parameters:
  • name_tok – Token with the name/position of the variable or parameter.

  • the_type – Type of the variable or parameter.

  • counter – Object to give out unique identification numbers, yet be resistant against re-use of imported modules.

id#

Unique number of the node, mostly useful for dumps and debugging.

comments#

Stored comments of the node.

resolve_node(name: str) VarNode | None#

Find the varparam (sub)node that matches the provided dotted ‘name’.

Parameters:

name – Possibly dotted name that should point at an existing sub-node. The empty string denotes ‘self’.

Returns:

The node that matches the name, or None if no such node exists. In the

latter case, use ‘self.get_error_position(name)’ to get an indication where the match fails in the name.

get_error_position(name: str) int#

Return the index in the given string where an error occurs in resolving the node.

Parameters:

name – Name of the element to find.

Returns:

Approximated index in the string where matching the element fails.

Returned value has no meaning if resolving a node succeeds.

add_comment(comment_tok: raesl.compile.scanner.Token)#

Add found documentation comment.

Parameters:

comment_tok – The raw documentation token to add.

get_comment()#

Retrieve the stored comments.

__repr__()#

Return repr(self).

class raesl.compile.ast.nodes.CompoundVarNode(name_tok: raesl.compile.scanner.Token, the_type: raesl.compile.ast.types.BaseType, child_nodes: List[VarNode])#

Bases: VarNode, raesl.compile.ast.comment_storage.DocAddElement

Grouped variable/parameter node.

Parameters:
  • name_tok – Token with the name/position of the variable or parameter.

  • the_type – Type of the variable or parameter.

  • child_nodes – Child nodes of the group.

name_index#

Mapping of name to the associated VarNode instance.

resolve_node(name: str) VarNode | None#

Find the varparam (sub)node that matches the provided dotted ‘name’.

Parameters:

name – Possibly dotted name that should point at an existing sub-node. The empty string denotes ‘self’.

Returns:

The node that matches the name, or None if no such node exists. In the

latter case, use ‘self.get_error_position(name)’ to get an indication where the match fails in the name.

get_error_position(name: str) int#

Return the index in the given string where an error occurs in resolving the node.

Parameters:

name – Name of the element to find.

Returns:

Approximated index in the string where matching the element fails.

Returned value has no meaning if resolving a node succeeds.

add_comment(comment_tok: raesl.compile.scanner.Token)#

Compound node doesn’t own a store, push comment down to all children.

class raesl.compile.ast.nodes.GroupNode(name_tok: raesl.compile.scanner.Token, child_nodes: List[Node])#

Bases: Node

Class describing content of a variable group. Unlike the VarNode above, a group node has no type of its own.

Parameters:
  • name_tok – Name of the group node.

  • child_nodes – Elements of the group.