montepy.input_parser.syntax_node module#
Classes:
A node to represent the classifier for a |
|
|
Object to represent a comment in an MCNP problem. |
|
A syntax tree that is a binary tree for representing CSG geometry logic. |
|
A node to represent a list of values. |
|
A node for representing isotopes and their concentration, and the material parameters. |
|
A syntax tree node to represent a collection of sequential padding elements. |
A node to hold the parameters, key-value pairs, for this input. |
|
|
A node to hold particles information in a |
|
A node that pretends to be a |
|
A general syntax node for handling inner tree nodes. |
|
A base class for all syntax nodes. |
|
A syntax node to represent the leaf node. |
- class montepy.input_parser.syntax_node.ClassifierNode#
Bases:
SyntaxNodeBase
A node to represent the classifier for a
montepy.data_input.DataInput
e.g., represents
M4
,F104:n,p
,IMP:n,e
.Methods:
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.Attributes:
A generator of all comments contained in this tree.
The modifier for this classifier if any.
The name for the node.
The children nodes of this node.
The number if any for the classifier.
The padding for this classifier.
The particles if any tied to this classifier.
The prefix for the classifier.
- 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
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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.
- Parameters:
input (Token) – the token from the lexer
Methods:
append
(token)Append the comment token 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.Attributes:
A generator of all comments contained in this tree.
The contents of the comments without delimiters (i.e., $/C).
Whether or not this CommentNode is a dollar sign ($) comment.
The name for the node.
The children nodes of this node.
- 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
- 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 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
- 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.
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:
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.
- 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:
- class montepy.input_parser.syntax_node.ListNode(name)#
Bases:
SyntaxNodeBase
A node to represent a list of values.
- Parameters:
name (str) – the name of this node.
Methods:
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.
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.remove
(obj)Removes the given object from this list.
update_with_new_values
(new_vals)Update this list node with new values.
Attributes:
A generator of all comments contained in this tree.
The name for the node.
The children nodes 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
- 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
- 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 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.MaterialsNode(name)#
Bases:
SyntaxNodeBase
A node for representing isotopes and their concentration, and the material parameters.
This stores a list of tuples of ZAIDs and concentrations, or a tuple of a parameter.
Added in version 1.0.0: This was added as a more general version of
IsotopesNodes
.- Parameters:
name (str) – a name for labeling this node.
Methods:
append
()Append the node to this node.
append_nuclide
(isotope_fraction)Append the isotope fraction to this node.
append_param
(param)Append the parameter 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.Attributes:
A generator of all comments contained in this tree.
The name for the node.
The children nodes of this node.
- append()#
Append the node to this node.
- Parameters:
node (SyntaxNodeBase, str, None) – node
- append_nuclide(isotope_fraction)#
Append the isotope fraction to this node.
Added in version 1.0.0: Added to replace
append
- 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.
- append_param(param)#
Append the parameter to this node.
Added in version 1.0.0: Added to replace
append
- Parameters:
param (ParametersNode) – the parameter to add to this 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
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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.PaddingNode(token=None, is_comment=False)#
Bases:
SyntaxNodeBase
A syntax tree node to represent a collection of sequential padding elements.
- Parameters:
token (str) – The first padding token for this node.
is_comment (bool) – If the token provided is a comment.
Methods:
append
(val[, is_comment])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.Checks if there is a graveyard comment that is preventing information from being part of the tree.
Determines if there is syntactically significant space anywhere in this node.
is_space
(i)Determine if the value at i is a space or not.
Attributes:
A generator of all comments contained in this tree.
The name for the node.
The children nodes of this node.
A string representation of the contents of this node.
- 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
- 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.
Notes
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
.- Return type:
unknown
- Raises:
IndexError – if the index i is not in
self.nodes
.
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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*
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"]
Methods:
append
(val[, is_default])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.Attributes:
A generator of all comments contained in this tree.
The name for the node.
The children nodes of this node.
- 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
- 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 comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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
.- Parameters:
name (str) – the name for the node.
token (str) – the original token from parsing
Methods:
add
(value)Add a particle to 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.remove
(value)Remove a particle from this node.
Attributes:
A generator of all comments contained in this tree.
The name for the node.
The children nodes of this node.
The particles included in this node.
The original text (token) for this ParticleNode.
- 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
- remove(value)#
Remove a particle from this node.
- Parameters:
value (Particle) – the particle to remove.
- property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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
- 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.
- Parameters:
p (sly.yacc.YaccProduction) – the parsing object to parse.
short_type (Shortcuts) – the type of the shortcut.
Methods:
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 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:
A generator of all comments contained in this tree.
The padding at the end of this shortcut.
The name for the node.
The children nodes of this node.
The Type of shortcut this ShortcutNode represents.
- 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:
- 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.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
- Parameters:
name (str) – a name for labeling this node.
parse_dict (dict) – the dictionary of the syntax tree nodes.
Methods:
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.get_value
(key)Get a value from the syntax tree.
Attributes:
A generator of all comments contained in this tree.
The name for the node.
The children nodes of 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
- 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 comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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.
- Parameters:
name (str) – a name for labeling this node.
Methods:
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.Attributes:
A generator of all comments contained in this tree.
The name for the node.
The children nodes of 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
- 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
- abstractmethod 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
- abstract property comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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.
- 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.
Methods:
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.
convert_to_enum
(enum_class[, allow_none, ...])Converts the ValueNode to an Enum for allowed values.
Converts a float ValueNode to an int ValueNode.
Converts this ValueNode to being a string type.
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.Attributes:
A generator of all comments contained in this tree.
Whether or not this value is a negatable float.
Whether or not this value is a negatable identifier.
Whether or not this value is negative.
The name for the node.
Whether or not this value node will not have extra spaces added.
The children nodes of this node.
The padding if any for this ValueNode.
The original text (token) for this ValueNode.
The data type for this ValueNode.
The current semantic value of this 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
- 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.
- convert_to_str()#
Converts this ValueNode to being a string type.
Added in version 1.0.0.
- 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 comments#
A generator of all comments contained in this tree.
- Returns:
the comments in the tree.
- Return type:
Generator
- 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