montepy.input_parser.syntax_node module#
- class montepy.input_parser.syntax_node.ClassifierNode#
Bases:
SyntaxNodeBase
A node to represent the classifier for a
montepy.data_input.DataInput
Added in version 0.2.0: This was added with the major parser rework.
e.g., represents
M4
,F104:n,p
,IMP:n,e
.- 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
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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
- property modifier#
The modifier for this classifier if any.
A modifier is a prefix character that changes the inputs behavior, e.g.:
*
or+
.- Returns:
the modifier
- 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 number#
The number if any for the classifier.
- Returns:
the number holder for this classifier.
- Return type:
- property padding#
The padding for this classifier.
Note
None of the ValueNodes in this object should have padding.
- Returns:
the padding after the classifier.
- Return type:
- property particles#
The particles if any tied to this classifier.
- Returns:
the particles used.
- Return type:
- class montepy.input_parser.syntax_node.CommentNode(input)#
Bases:
SyntaxNodeBase
Object to represent a comment in an MCNP problem.
Added in version 0.2.0: This was added with the major parser rework.
- Parameters:
input (Token) – the token from the lexer
- append(token)#
Append the comment token to this node.
- Parameters:
token (str) – the comment token
- 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
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- property contents#
The contents of the comments without delimiters (i.e., $/C).
- Returns:
String of the contents
- Return type:
str
- 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
- property is_dollar#
Whether or not this CommentNode is a dollar sign ($) comment.
- Returns:
True iff this is a dollar sign comment.
- Return type:
bool
- 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
- 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.
Added in version 0.2.0: This was added with the major parser rework.
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.
- 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
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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
- property left#
The left side of the binary tree.
- Returns:
the left node of the syntax tree.
- Return type:
- 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 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:
- class montepy.input_parser.syntax_node.IsotopesNode(name)#
Bases:
SyntaxNodeBase
A node for representing isotopes and their concentration.
This stores a list of tuples of ZAIDs and concentrations.
Added in version 0.2.0: This was added with the major parser rework.
- Parameters:
name (str) – a name for labeling this node.
- append(isotope_fraction)#
Append the node to this node.
- Parameters:
isotope_fraction (tuple) – the isotope_fraction to add. This must be a tuple from A Yacc production. This will consist of: the string identifying the Yacc production, a ValueNode that is the ZAID, and a ValueNode of the concentration.
- 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
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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
- 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
- class montepy.input_parser.syntax_node.ListNode(name)#
Bases:
SyntaxNodeBase
A node to represent a list of values.
Added in version 0.2.0: This was added with the major parser rework.
- Parameters:
name (str) – the name of this node.
- 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
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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
- 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
- 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)
- class montepy.input_parser.syntax_node.PaddingNode(token=None, is_comment=False)#
Bases:
SyntaxNodeBase
A syntax tree node to represent a collection of sequential padding elements.
Added in version 0.2.0: This was added with the major parser rework.
- Parameters:
token (str) – The first padding token for this node.
is_comment (bool) – If the token provided is a comment.
- append(val, is_comment=False)#
Append the node to this node.
- Parameters:
node (str, CommentNode) – node
is_comment (bool) – whether or not the node is a comment.
- 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
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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
- has_graveyard_comment()#
Checks if there is a graveyard comment that is preventing information from being part of the tree.
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
Added in version 0.4.0.
- Returns:
True if this PaddingNode contains a graveyard comment.
- Return type:
bool
- has_space()#
Determines if there is syntactically significant space anywhere in this node.
- Returns:
True if there is syntactically significant (not in a comment) space.
- Return type:
bool
- is_space(i)#
Determine if the value at i is a space or not.
Note
the newline,
\n
, by itself is not considered a space.- Parameters:
i (int) – the index of the element to check.
- Returns:
true iff the padding at that node is only spaces that are not
\n
.- Raises:
IndexError – if the index i is not in
self.nodes
.
- 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 value#
A string representation of the contents of this node.
All of the padding will be combined into a single string.
- Returns:
a string sequence of the padding.
- Return type:
str
- class montepy.input_parser.syntax_node.ParametersNode#
Bases:
SyntaxNodeBase
A node to hold the parameters, key-value pairs, for this input.
This behaves like a dictionary and is accessible by their key*
Added in version 0.2.0: This was added with the major parser rework.
Note
How to access values.
The internal dictionary doesn’t use the full classifier directly, because some parameters should not be both allowed: e.g.,
fill
and*fill
. The key is a string that is all lower case, and only uses the classifiers prefix, and particles.So to access a cell’s fill information you would run:
parameters["fill"]
And to access the n,p importance:
parameters["imp:n,p"]
- append(val, is_default=False)#
Append the node to this node.
- This takes a syntax node, which requires the keys:
["classifier", "seperator", "data"]
- Parameters:
val (SyntaxNode) – the parameter to append.
is_default (bool) – whether this parameter was added as a default tree not from the user.
- 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
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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
- 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
- class montepy.input_parser.syntax_node.ParticleNode(name, token)#
Bases:
SyntaxNodeBase
A node to hold particles information in a
ClassifierNode
.Added in version 0.2.0: This was added with the major parser rework.
- Parameters:
name (str) – the name for the node.
token (str) – the original token from parsing
- 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
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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
- 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 particles#
The particles included in this node.
- Returns:
a set of the particles being used.
- Return type:
set
- remove(value)#
Remove a particle from this node.
- Parameters:
value (Particle) – the particle to remove.
- property token#
The original text (token) for this ParticleNode.
- Returns:
the original input.
- Return type:
str
- 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.
Added in version 0.2.0: This was added with the major parser rework.
- Parameters:
p (sly.yacc.YaccProduction) – the parsing object to parse.
short_type (Shortcuts) – the type of the shortcut.
- 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
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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
- property end_padding#
The padding at the end of this shortcut.
- Return type:
- 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.
- 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
- 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)
- class montepy.input_parser.syntax_node.SyntaxNode(name, parse_dict)#
Bases:
SyntaxNodeBase
A general syntax node for handling inner tree nodes.
This is a generalized wrapper for a dictionary. The order of the dictionary is significant.
This does behave like a dict for collecting items. e.g.,
value = syntax_node["start_pad"] if key in syntax_node: pass
Added in version 0.2.0: This was added with the major parser rework.
- Parameters:
name (str) – a name for labeling this node.
parse_dict (dict) – the dictionary of the syntax tree nodes.
- 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
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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
- get_value(key)#
Get a value from the syntax tree.
- Parameters:
key (str) – the key for the item to get.
- Returns:
the node in the syntax tree.
- Return type:
- Raises:
KeyError – if key is not in SyntaxNode
- 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
- class montepy.input_parser.syntax_node.SyntaxNodeBase(name)#
Bases:
ABC
A base class for all syntax nodes.
A syntax node is any component of the syntax tree for a parsed input.
Added in version 0.2.0: This was added with the major parser rework.
- Parameters:
name (str) – a name for labeling this node.
- 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
- abstract property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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
- abstract 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
- 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
- class montepy.input_parser.syntax_node.ValueNode(token, token_type, padding=None, never_pad=False)#
Bases:
SyntaxNodeBase
A syntax node to represent the leaf node.
This stores the original input token, the current value, and the possible associated padding.
Added in version 0.2.0: This was added with the major parser rework.
- Parameters:
token (str) – the original token for the ValueNode.
token_type (class) – the type for the ValueNode.
padding (PaddingNode) – the padding for this node.
never_pad (bool) – If true an ending space will never be added to this.
- _convert_to_enum(enum_class, allow_none=False, format_type=<class 'str'>, switch_to_upper=False)#
Converts the ValueNode to an Enum for allowed values.
- Parameters:
enum_class (Class) – the class for the enum to use.
allow_none (bool) – Whether or not to allow None as a value.
format_type (Class) – the base data type to format this ValueNode as.
switch_to_upper (bool) – Whether or not to convert a string to upper case before convert to enum.
- _convert_to_int()#
Converts a float ValueNode to an int ValueNode.
- 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
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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
- property is_negatable_float#
Whether or not this value is a negatable float.
Example use: cell density.
- This means:
the ValueNode is an int.
The
value
will always be positive.The
is_negative
property will be available.
- Returns:
the state of this marker.
- Return type:
bool
- property is_negatable_identifier#
Whether or not this value is a negatable identifier.
Example use: the surface transform or periodic surface is switched based on positive or negative.
- This means:
the ValueNode is an int.
The
value
will always be positive.The
is_negative
property will be available.
- Returns:
the state of this marker.
- Return type:
bool
- property is_negative#
Whether or not this value is negative.
If neither
is_negatable_float()
oris_negatable_identifier()
is true then this will returnNone
.- Returns:
true if this value is negative (either in input or through state).
- Return type:
bool, None
- property name#
The name for the node.
- Returns:
the node’s name.
- Return type:
str
- property never_pad#
Whether or not this value node will not have extra spaces added.
- Returns:
true if extra padding is not adding at the end if missing.
- Return type:
bool
- property nodes#
The children nodes of this node.
- Returns:
a list of the nodes.
- Return type:
list
- property padding#
The padding if any for this ValueNode.
- Returns:
the padding if any.
- Return type:
- property token#
The original text (token) for this ValueNode.
- Returns:
the original input.
- Return type:
str
- property type#
The data type for this ValueNode.
Examples: float, int, str, Lattice
- Returns:
the class for the value of this node.
- Return type:
Class
- property value#
The current semantic value of this ValueNode.
This is the parsed meaning in the type of
self.type
, that can be updated. When this value is updated, next time format() is ran this value will be used.- Returns:
the node’s value in type
type
.- Return type:
float, int, str, enum