montepy.input_parser.syntax_node.PaddingNode#
- 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:
Deletes the trailing comment if any.
Get the first index that is a
c
style comment._grab_beginning_comment
(extra_padding)Consumes the provided comment, and moves it to the beginning of this node.
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.
- _delete_trailing_comment()#
Deletes the trailing comment if any.
- _get_first_comment()#
Get the first index that is a
c
style comment.- Returns:
the index of the first comment, if there is no comment then None.
- Return type:
int, None
- _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, 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