openpectus.lang.model.ast

Attributes

TNode

Classes

Position

Range

NodeIdGenerator

NodeState

dict() -> new empty dictionary

SupportCancelForce

Defines data for cancel and force operations that control interpretation behavior.

SupportsInterrupt

Marker interface that indicates that the node type uses the interrupt mechanism.

Node

Defines data for cancel and force operations that control interpretation behavior.

NodeWithChildren

Defines data for cancel and force operations that control interpretation behavior.

ProgramNode

Defines data for cancel and force operations that control interpretation behavior.

MarkNode

Defines data for cancel and force operations that control interpretation behavior.

BlockNode

Defines data for cancel and force operations that control interpretation behavior.

EndBlockNode

Defines data for cancel and force operations that control interpretation behavior.

EndBlocksNode

Defines data for cancel and force operations that control interpretation behavior.

BatchNode

Defines data for cancel and force operations that control interpretation behavior.

NodeWithTagOperatorValue

Defines data for cancel and force operations that control interpretation behavior.

NodeWithCondition

Defines data for cancel and force operations that control interpretation behavior.

NodeWithAssignment

Defines data for cancel and force operations that control interpretation behavior.

WatchNode

Defines data for cancel and force operations that control interpretation behavior.

AlarmNode

Defines data for cancel and force operations that control interpretation behavior.

TagOperatorValue

WhitespaceNode

Represents a node that counts as whitespace in regards to

CommentNode

Represents a line with only a comment.

InjectedNode

Defines data for cancel and force operations that control interpretation behavior.

MacroNode

Defines data for cancel and force operations that control interpretation behavior.

CallMacroNode

Defines data for cancel and force operations that control interpretation behavior.

NotifyNode

Defines data for cancel and force operations that control interpretation behavior.

CommandBaseNode

Defines data for cancel and force operations that control interpretation behavior.

InterpreterCommandNode

Represents commands that are directly executable by the interpreter.

EngineCommandNode

Represents internal engine commands that have a command class subclassing InternalEngineCommand.

SimulateNode

Defines data for cancel and force operations that control interpretation behavior.

SimulateOffNode

Defines data for cancel and force operations that control interpretation behavior.

UodCommandNode

Represents a uod command, subclassing UodCommand.

Comment

Error

BlankNode

Represents a line that contains only whitespace.

ErrorInstructionNode

Represents non-parsable instruction line.

Module Contents

class openpectus.lang.model.ast.Position(line, character)
Parameters:
  • line (int)

  • character (int)

line: int

Line number, zero based

character: int

Character number on line, zero-based. Corresponds to the indentation of the line

is_empty()
Return type:

bool

static empty()
Return type:

Position

__eq__(value)
__lt__(other)
__gt__(other)
with_character(character)
Parameters:

character (int)

Return type:

Position

__str__()
__hash__()
Return type:

int

class openpectus.lang.model.ast.Range(start, end)
Parameters:
start
end
is_empty()
Return type:

bool

with_end(position)
Parameters:

position (Position)

Return type:

Range

static empty()
Return type:

Range

__str__()
__contains__(index)

Check if position or character index is within range

Parameters:

index (Position)

__eq__(other)
Return type:

bool

__hash__()
Return type:

int

class openpectus.lang.model.ast.NodeIdGenerator
create_id(node)
Parameters:

node (Node)

Return type:

str

class openpectus.lang.model.ast.NodeState

Bases: TypedDict

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

id: str
class_name: str
name: str
started: bool
completed: bool
cancelled: bool
forced: bool
action_history: list[str]
openpectus.lang.model.ast.TNode
class openpectus.lang.model.ast.SupportCancelForce

Defines data for cancel and force operations that control interpretation behavior.

_cancellable: bool = False
_cancelled: bool = False
_forcible: bool = True
_forced: bool = False
property cancellable: bool

Whether the node is cancellable in its current state. Virtual property.

Return type:

bool

property cancelled: bool

Whether the node has been cancelled. Virtual property.

Return type:

bool

cancel()
property forcible: bool

Whether the node is forcible in its current state. Virtual property.

Return type:

bool

property forced: bool

Whether the node has been forced. Virtual property.

Return type:

bool

force()
class openpectus.lang.model.ast.SupportsInterrupt

Marker interface that indicates that the node type uses the interrupt mechanism.

Requirements: - it must provide a interrupt_registered property, currently NodeWithChildren does this - interpreter._create_interrupt_handler() must be able to create a handler for the node type

class openpectus.lang.model.ast.Node(position=Position.empty, id='')

Bases: SupportCancelForce

Defines data for cancel and force operations that control interpretation behavior.

instruction_names: list[str] = []

Specifies which node the parser should instantiate for a given instruction name(s)

parent: NodeWithChildren | None = None
id: str = ''
position: Position
instruction_part: str = ''
instruction_range: Range
stripped_instruction_range: Range
threshold_part: str = ''
arguments_part: str = ''
arguments: str = ''
arguments_range: Range
stripped_arguments_range: Range
comment_part: str = ''
has_comment: bool = False
has_argument: bool = False
threshold: float | None = None
indent_error: bool = False
errors: list[Error] = []
started: bool = False
completed: bool = False
action_history: list[str] = []
_empty_node_class_names
property name: str

Get node name. Parser guarantees it to not be None and be stripped. May be the empty string

Return type:

str

property instruction_name: str
Return type:

str

property runlog_name: str | None
Return type:

str | None

property display_name: str
Return type:

str

has_children()
Return type:

bool

get_child_by_id(id, include_self=False)
Parameters:

id (str)

Return type:

Node | None

can_load_state(state)

Determine whether state is valid for this kind of node

Parameters:

state (NodeState)

Return type:

bool

apply_state(state)
Parameters:

state (NodeState)

extract_state()
Return type:

NodeState

get_child_by_instruction(instruction_name, arguments=None)

Find node by instruction name and optionally arguments.

Parameters:
  • instruction_name (str)

  • arguments (str | None)

Return type:

Node | None

with_id(gen)
Parameters:

gen (NodeIdGenerator)

Return type:

Self

has_error()
Return type:

bool

append_error(error)
Parameters:

error (Error)

__str__()
__repr__()
as_tree()
Return type:

str

property parents: list[NodeWithChildren]
Return type:

list[NodeWithChildren]

property root: ProgramNode
Return type:

ProgramNode

reset_runtime_state(recursive)
Parameters:

recursive (bool)

matches_source(other, logger)

Returns True if the two nodes correspond to the same pcode source lines, else False.

Some white space and comments are not considered changes

Parameters:
  • other (Node)

  • logger (logging.Logger)

Return type:

bool

class openpectus.lang.model.ast.NodeWithChildren(position=Position.empty, id='')

Bases: Node

Defines data for cancel and force operations that control interpretation behavior.

_children: list[Node] = []
interrupt_registered: bool = False

Whether an interrupt was registered to execute the node.

children_complete: bool = False

Specifies that execution of child nodes should stop or is completed.

_last_non_ws_line: int = 0

Populated by WhitespaceAnalyzer

property children: list[Node]
Return type:

list[Node]

append_child(child)
Parameters:

child (Node)

has_children()
get_child_nodes(recursive=False, exclude_blocks=False)
Parameters:
  • recursive (bool)

  • exclude_blocks (bool)

Return type:

list[Node]

get_first_child(node_type)

Return the first child node of the specified type, recursively, depth first

Parameters:

node_type (Type[TNode])

Return type:

TNode | None

as_tree()

Return the node and its subtree as a string mimicing the source pcode

Return type:

str

extract_state()
Return type:

NodeState

apply_state(state)
reset_runtime_state(recursive)
class openpectus.lang.model.ast.ProgramNode(position=Position.empty, id='')

Bases: NodeWithChildren

Defines data for cancel and force operations that control interpretation behavior.

active_node: Node | None = None

The node currently executing. Is never ProgramNode. Is None untli first instruction is visited. Is not cleared at the end but keeps pointing to the last instruction.

The value is maintained by the interpreters program iterator.

revision: int = 0

The program revision. Starts as 0 and increments every time an edit is performed while running.

macros: dict[str, MacroNode]
get_instructions(include_blanks=False)

Return list of all program instructions, recursively, depth first.

Parameters:

include_blanks (bool)

Return type:

list[Node]

get_all_nodes()

Return all nodes, depth first, as a flat list

Return type:

list[Node]

extract_tree_state()

Return map of all nodes’ state keyed by their node id.

This includes non-started nodes that should not be imported. apply_tree_state() handles the filtering on import.

Return type:

dict[str, NodeState]

apply_tree_state(state)
Parameters:

state (dict[str, NodeState])

reset_runtime_state(recursive)
extract_state()
Return type:

NodeState

apply_state(state)
Parameters:

state (NodeState)

__str__()
static empty()
Return type:

ProgramNode

class openpectus.lang.model.ast.MarkNode(position=Position.empty, id='')

Bases: Node

Defines data for cancel and force operations that control interpretation behavior.

instruction_names = ['Mark']

Specifies which node the parser should instantiate for a given instruction name(s)

_forcible = False
class openpectus.lang.model.ast.BlockNode(position=Position.empty, id='')

Bases: NodeWithChildren

Defines data for cancel and force operations that control interpretation behavior.

instruction_names = ['Block']

Specifies which node the parser should instantiate for a given instruction name(s)

lock_aquired = False
reset_runtime_state(recursive)
extract_state()
Return type:

NodeState

apply_state(state)
Parameters:

state (NodeState)

class openpectus.lang.model.ast.EndBlockNode(position=Position.empty, id='')

Bases: Node

Defines data for cancel and force operations that control interpretation behavior.

instruction_names = ['End block']

Specifies which node the parser should instantiate for a given instruction name(s)

class openpectus.lang.model.ast.EndBlocksNode(position=Position.empty, id='')

Bases: Node

Defines data for cancel and force operations that control interpretation behavior.

instruction_names = ['End blocks']

Specifies which node the parser should instantiate for a given instruction name(s)

class openpectus.lang.model.ast.BatchNode(position=Position.empty, id='')

Bases: Node

Defines data for cancel and force operations that control interpretation behavior.

instruction_names = ['Batch']

Specifies which node the parser should instantiate for a given instruction name(s)

class openpectus.lang.model.ast.NodeWithTagOperatorValue(position=Position.empty, id='')

Bases: Node

Defines data for cancel and force operations that control interpretation behavior.

operators: list[str]
tag_operator_value_part: str
tag_operator_value: TagOperatorValue | None
class openpectus.lang.model.ast.NodeWithCondition(position=Position.empty, id='')

Bases: NodeWithTagOperatorValue

Defines data for cancel and force operations that control interpretation behavior.

operators = ['<=', '>=', '==', '!=', '<', '>', '=']
interrupt_registered: bool = False
activated: bool = False

Node condition was evaluated true

apply_state(state)
Parameters:

state (NodeState)

extract_state()
Return type:

NodeState

reset_runtime_state(recursive)
property cancellable: bool

Whether the node is cancellable in its current state. Virtual property.

Return type:

bool

property forcible: bool

Whether the node is forcible in its current state. Virtual property.

Return type:

bool

class openpectus.lang.model.ast.NodeWithAssignment(position=Position.empty, id='')

Bases: NodeWithTagOperatorValue

Defines data for cancel and force operations that control interpretation behavior.

operators = ['=']
class openpectus.lang.model.ast.WatchNode(position=Position.empty, id='')

Bases: NodeWithChildren, NodeWithCondition, SupportsInterrupt

Defines data for cancel and force operations that control interpretation behavior.

instruction_names = ['Watch']

Specifies which node the parser should instantiate for a given instruction name(s)

class openpectus.lang.model.ast.AlarmNode(position=Position.empty, id='')

Bases: NodeWithChildren, NodeWithCondition, SupportsInterrupt

Defines data for cancel and force operations that control interpretation behavior.

instruction_names = ['Alarm']

Specifies which node the parser should instantiate for a given instruction name(s)

run_count: int = 0

The number of times the alarm has completed

extract_state()
apply_state(state)
reset_runtime_state(recursive)
class openpectus.lang.model.ast.TagOperatorValue
error = True
lhs = ''
op = ''
rhs = ''
range: Range
stripped_range: Range
tag_name: str | None = None
tag_value: str | None = None
tag_unit: str | None = None
tag_value_numeric: int | float | None = None
lhs_range
stripped_lhs_range
op_range
rhs_range
stripped_rhs_range
tag_unit_range
__str__()
class openpectus.lang.model.ast.WhitespaceNode(position=Position.empty, id='')

Bases: Node

Represents a node that counts as whitespace in regards to interpretation, e.g. blank lines and comment lines.

Populated by WhitespaceAnalyzer

has_only_trailing_whitespace: bool = False

Specifies that only whitespace instructions follow this whitespace instruction in the current scope as well as outer scopes.

class openpectus.lang.model.ast.CommentNode(position=Position.empty, id='')

Bases: WhitespaceNode

Represents a line with only a comment.

has_comment = True
line: str = ''
with_line(line)
Parameters:

line (str)

class openpectus.lang.model.ast.InjectedNode(position=Position.empty, id='')

Bases: NodeWithChildren, SupportsInterrupt

Defines data for cancel and force operations that control interpretation behavior.

class openpectus.lang.model.ast.MacroNode(position=Position.empty, id='')

Bases: NodeWithChildren

Defines data for cancel and force operations that control interpretation behavior.

instruction_names = ['Macro']

Specifies which node the parser should instantiate for a given instruction name(s)

activated: bool = False
_cancellable = False
_forcible = False
is_registered: bool = False

Whether the macro has been registered in the revision. Lifetime is revision.

run_started_count: int = 0

The number of times the macro has started. Life time is the whole run

extract_state()
apply_state(state)
prepare_for_call()

Clears state left over by any previous calls of the macro so it can be called again

reset_runtime_state(recursive)
macro_calling_macro(macros, name=None)

Recurse through macro to produce a path of calls it makes to other macros.

This is used to identify if a macro will at some point call itself.

Parameters:
  • macros (dict[str, MacroNode])

  • name (str | None)

Return type:

list[str]

class openpectus.lang.model.ast.CallMacroNode(position=Position.empty, id='')

Bases: Node

Defines data for cancel and force operations that control interpretation behavior.

instruction_names = ['Call macro']

Specifies which node the parser should instantiate for a given instruction name(s)

_cancellable = False
_forcible = False
activated = False
extract_state()
apply_state(state)
reset_runtime_state(recursive)
class openpectus.lang.model.ast.NotifyNode(position=Position.empty, id='')

Bases: Node

Defines data for cancel and force operations that control interpretation behavior.

instruction_names = ['Notify']

Specifies which node the parser should instantiate for a given instruction name(s)

_cancellable = False
_forcible = False
class openpectus.lang.model.ast.CommandBaseNode(position=Position.empty, id='')

Bases: Node

Defines data for cancel and force operations that control interpretation behavior.

class openpectus.lang.model.ast.InterpreterCommandNode(position=Position.empty, id='')

Bases: CommandBaseNode

Represents commands that are directly executable by the interpreter.

instruction_names = ['Base', 'Increment run counter', 'Run counter', 'Wait']

Specifies which node the parser should instantiate for a given instruction name(s)

wait_start_time: float | None = None
extract_state()
apply_state(state)
reset_runtime_state(recursive)
class openpectus.lang.model.ast.EngineCommandNode(position=Position.empty, id='')

Bases: CommandBaseNode

Represents internal engine commands that have a command class subclassing InternalEngineCommand.

instruction_names = ['Stop', 'Pause', 'Unpause', 'Hold', 'Unhold', 'Restart', 'Info', 'Warning', 'Error']

Specifies which node the parser should instantiate for a given instruction name(s)

class openpectus.lang.model.ast.SimulateNode(position=Position.empty, id='')

Bases: NodeWithAssignment

Defines data for cancel and force operations that control interpretation behavior.

instruction_names = ['Simulate']

Specifies which node the parser should instantiate for a given instruction name(s)

class openpectus.lang.model.ast.SimulateOffNode(position=Position.empty, id='')

Bases: Node

Defines data for cancel and force operations that control interpretation behavior.

instruction_names = ['Simulate off']

Specifies which node the parser should instantiate for a given instruction name(s)

class openpectus.lang.model.ast.UodCommandNode(position=Position.empty, id='')

Bases: CommandBaseNode

Represents a uod command, subclassing UodCommand.

class openpectus.lang.model.ast.Comment(comment, position)
Parameters:
comment
position
class openpectus.lang.model.ast.Error(message=None)
Parameters:

message (str | None)

message: str | None = None
class openpectus.lang.model.ast.BlankNode(position=Position.empty, id='')

Bases: WhitespaceNode

Represents a line that contains only whitespace.

class openpectus.lang.model.ast.ErrorInstructionNode(position=Position.empty, id='')

Bases: Node

Represents non-parsable instruction line.

line: str = ''
with_line(line)
Parameters:

line (str)