montepy.input_parser.syntax_node.ShortcutNode#

class montepy.input_parser.syntax_node.ShortcutNode(p=None, short_type=None, data_type=<class 'float'>)#

Bases: ListNode

A node that pretends to be a ListNode but is actually representing a shortcut.

This takes the shortcut tokens, and expands it into their “virtual” values.

Parameters:
  • p (sly.yacc.YaccProduction) – the parsing object to parse.

  • short_type (Shortcuts) – the type of the shortcut.

Methods:

_can_consume_node(node, direction[, ...])

If it's possible to consume this node.

_can_use_last_node(node[, start])

Determine if the previous node can be used as the start to this node (and therefore skip the start of this one).

_delete_trailing_comment()

Deletes the trailing comment if any.

_expand_shortcuts(new_vals, new_vals_cache)

Expands the existing shortcuts, and tries to "zip out" and consume their neighbors.

_grab_beginning_comment(extra_padding)

Consumes the provided comment, and moves it to the beginning of this node.

append(val[, from_parsing])

Append the node to this node.

check_for_graveyard_comments([...])

Checks if there is a graveyard comment that is preventing information from being part of the tree, and handles them.

consume_edge_node(node, direction[, ...])

Tries to consume the given edge.

flatten()

Flattens this tree structure into a list of leaves.

format([leading_node])

Generate a string representing the tree's current state.

get_trailing_comment()

Get the trailing c style comments if any.

load_nodes(nodes)

Loads the given nodes into this shortcut, and update needed information.

remove(obj)

Removes the given object from this list.

update_with_new_values(new_vals)

Update this list node with new values.

Attributes:

comments

A generator of all comments contained in this tree.

end_padding

The padding at the end of this shortcut.

name

The name for the node.

nodes

The children nodes of this node.

type

The Type of shortcut this ShortcutNode represents.

_can_consume_node(node, direction, last_edge_shortcut=False)#

If it’s possible to consume this node.

Parameters:
  • node (ValueNode) – the node to consume

  • direction (int) – the direct to go in. Must be in {-1, 1}

  • last_edge_shortcut (bool) – Whether the previous node in the list was part of a different shortcut

Returns:

true it can be consumed.

Return type:

bool

_can_use_last_node(node, start=None)#

Determine if the previous node can be used as the start to this node (and therefore skip the start of this one).

Last node can be used if - it’s a basic ValueNode that matches this repeat - it’s also a shortcut, with the same edge values.

Parameters:
  • node (ValueNode, ShortcutNode) – the previous node to test.

  • start (float) – the starting value for this node (specifically for interpolation)

Returns:

True if the node given can be used.

Return type:

bool

_delete_trailing_comment()#

Deletes the trailing comment if any.

_expand_shortcuts(new_vals, new_vals_cache)#

Expands the existing shortcuts, and tries to “zip out” and consume their neighbors.

Parameters:
  • new_vals (list) – the new values.

  • new_vals_cache (dict) – a dictionary mapping the id of the ValueNode to the ValueNode or ShortcutNode. This is ordered the same as new_vals.

_grab_beginning_comment(extra_padding)#

Consumes the provided comment, and moves it to the beginning of this node.

Parameters:

extra_padding (list) – the padding comment to add to the beginning of this padding.

append(val, from_parsing=False)#

Append the node to this node.

Parameters:
  • node (ValueNode, ShortcutNode) – node

  • from_parsing (bool) – If this is being append from the parsers, and not elsewhere.

check_for_graveyard_comments(has_following_input=False)#

Checks if there is a graveyard comment that is preventing information from being part of the tree, and handles them.

A graveyard comment is one that accidentally suppresses important information in the syntax tree.

For example:

imp:n=1 $ grave yard Vol=1

Should be:

imp:n=1 $ grave yard
Vol=1

These graveyards are handled by appending a new line, and the required number of continue spaces to the comment.

Added in version 0.4.0.

Parameters:

has_following_input (bool) – Whether there is another input (cell modifier) after this tree that should be continued.

Return type:

None

consume_edge_node(node, direction, last_edge_shortcut=False)#

Tries to consume the given edge.

If it can be consumed the node is appended to the internal nodes.

Parameters:
  • node (ValueNode) – the node to consume

  • direction (int) – the direct to go in. Must be in {-1, 1}

  • last_edge_shortcut (bool) – Whether or the previous node in the list was part of a different shortcut

Returns:

True if the node was consumed.

Return type:

bool

flatten()#

Flattens this tree structure into a list of leaves.

Added in version 0.4.0.

Returns:

a list of ValueNode and PaddingNode objects from this tree.

Return type:

list

format(leading_node=None)#

Generate a string representing the tree’s current state.

Returns:

the MCNP representation of the tree’s current state.

Return type:

str

get_trailing_comment()#

Get the trailing c style comments if any.

Returns:

The trailing comments of this tree.

Return type:

list

load_nodes(nodes)#

Loads the given nodes into this shortcut, and update needed information.

For interpolate nodes should start and end with the beginning/end of the interpolation.

Parameters:

nodes (list) – the nodes to be loaded.

remove(obj)#

Removes the given object from this list.

Parameters:

obj (ValueNode) – the object to remove.

update_with_new_values(new_vals)#

Update this list node with new values.

This will first try to find if any shortcuts in the original input match up with the new values. If so it will then “zip” out those shortcuts to consume as many neighbor nodes as possible. Finally, the internal shortcuts, and list will be updated to reflect the new state.

Parameters:

new_vals (list) – the new values (a list of ValueNodes)

property comments#

A generator of all comments contained in this tree.

Returns:

the comments in the tree.

Return type:

Generator

property end_padding#

The padding at the end of this shortcut.

Return type:

PaddingNode

property name#

The name for the node.

Returns:

the node’s name.

Return type:

str

property nodes#

The children nodes of this node.

Returns:

a list of the nodes.

Return type:

list

property type#

The Type of shortcut this ShortcutNode represents.

Return type:

Shortcuts