finesse.script.graph module

Graph represening a parsed kat script file.

class finesse.script.graph.KatEdgeType(*values)[source]

Bases: Flag

ARGUMENT = 1
DEPENDENCY = 2
class finesse.script.graph.KatGraph(*args, backend=None, **kwargs)[source]

Bases: DiGraph

Kat script graph.

argument(argument_node, adapter)[source]

Get argument corresponding to node argument_node.

This returns the argument object for a syntax graph node. It is useful for retrieving the names for positional arguments during parsing, but works for keyword arguments too.

Returns

BoundArgument

The argument specified in the script corresponding to argument_node.

Raises

TypeError

When argument_node corresponds to a positional argument that doesn’t exist in the setter signature defined in adapter.

argument_node_order(node)[source]

Get the order attribute of the edge linking argument node to its parent.

classmethod branch_base(path, reference)[source]

The branch base node name for path, relative to reference.

dependent_argument_nodes(node, **kwargs)[source]
dependent_arguments_edge_data(parent, data)[source]

Get mapping of dependent argument nodes to the value of the data attribute on the edge connecting them to parent.

directive_graph(node)[source]
filter_argument_nodes(node, key)[source]
filter_dependent_nodes(node, key)[source]
in_edge_source_nodes_by_edge_type(node, edge_types, **kwargs)[source]
in_edges_by_edge_type(node, edge_types, **kwargs)[source]
is_independent(node)[source]

Check if the node has no external dependencies.

A node is independent if it is a terminal type or if its arguments have no non- argument incoming edges.

classmethod is_subpath(path, reference)[source]

Check if path is a subpath of reference.

is_tree()[source]
classmethod item_node_name(name, parent_path)[source]
merge(other)[source]

Merge other graph into this graph, rewriting paths in other if there are name collisions.

Merging two identical graphs kat –> kat.0 –> kat.0.1, the result would be:

kat --> kat.0 --> kat.0.1
    --> kat.1 --> kat.1.1

Notes

self and other must be trees (is_tree() returns True).

nodes_by_node_type(node_type, **kwargs)[source]

Get nodes by type, with optional data.

out_edge_target_nodes_by_edge_type(node, edge_types, **kwargs)[source]
out_edges_by_edge_type(node, edge_types, **kwargs)[source]
param_target_element_path(target, root_node)[source]

The owning element path for target.

Target should be in the form “element_name{.param_name{.param_name {…}}}.

classmethod path_parent(path)[source]
plot(*args, **kwargs)[source]
sorted_dependent_argument_nodes(node, **kwargs)[source]
class finesse.script.graph.KatNodeType(*values)[source]

Bases: Flag

ARRAY = 32
COMPILER_TERMINAL_NODES = 1152
CONSTANT = 512
DEPENDENT_NODES = 256
DIRECTIVE_NODES = 6
ELEMENT = 2
EXPRESSION = 8
FUNCTION = 4
GENERATOR_TERMINAL_NODES = 1920
GROUPED_EXPRESSION = 16
KEYWORD = 1024
NUMERICAL_ARRAY = 64
REFERENCE = 256
ROOT = 1
VALUE = 128