montepy.input_parser.syntax_node.GeometryTree#
- class montepy.input_parser.syntax_node.GeometryTree(name, tokens, op, left, right=None, left_short_type=None, right_short_type=None)#
Bases:
SyntaxNodeBase
A syntax tree that is a binary tree for representing CSG geometry logic.
Changed in version 0.4.1: Added left/right_short_type
- Parameters:
name (str) – a name for labeling this node.
tokens (dict) – The nodes that are in the tree.
op (str) – The string representation of the Operator to use.
left (GeometryTree, ValueNode) – the node of the left side of the binary tree.
right (GeometryTree, ValueNode) – the node of the right side of the binary tree.
left_short_type (Shortcuts) – The type of Shortcut that right left leaf is involved in.
right_short_type (Shortcuts) – The type of Shortcut that the right leaf is involved in.
Methods:
Deletes the trailing comment if any.
Flattens this tree into a ListNode.
_grab_beginning_comment
(extra_padding)Consumes the provided comment, and moves it to the beginning of this node.
append
(node)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.
flatten
()Flattens this tree structure into a list of leaves.
format
()Generate a string representing the tree's current state.
Get the trailing
c
style comments if any.mark_last_leaf_shortcut
(short_type)Mark the final (rightmost) leaf node in this tree as being a shortcut.
Attributes:
A generator of all comments contained in this tree.
The left side of the binary tree.
The name for the node.
The children nodes of this node.
The operator used for the binary tree.
The right side of the binary tree.
- _delete_trailing_comment()#
Deletes the trailing comment if any.
- _flatten_shortcut()#
Flattens this tree into a ListNode.
This will add ShortcutNodes as well.
- Return type:
- _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(node)#
Append the node to this node.
- Parameters:
node (SyntaxNodeBase, str, None) – node
- 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
- 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()#
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
- mark_last_leaf_shortcut(short_type)#
Mark the final (rightmost) leaf node in this tree as being a shortcut.
- Parameters:
short_type (Shortcuts) – the type of shortcut that this leaf is.
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- property left#
The left side of the binary tree.
- Returns:
the left node of the syntax tree.
- Return type:
- 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 operator#
The operator used for the binary tree.
- Returns:
the operator used.
- Return type:
- property right#
The right side of the binary tree.
- Returns:
the right node of the syntax tree.
- Return type: