montepy.input_parser.syntax_node.ValueNode#

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:

_avoid_rounding_truncation()

Detects when not enough digits are in original input to preserve precision.

_delete_trailing_comment()

Deletes the trailing comment if any.

_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.

convert_to_enum(enum_class[, allow_none, ...])

Converts the ValueNode to an Enum for allowed values.

convert_to_int()

Converts a float ValueNode to an int ValueNode.

convert_to_str()

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_trailing_comment()

Get the trailing c style comments if any.

Attributes:

_print_value

The print version of the value.

_value_changed

Checks if the value has changed at all from first parsing.

comments

A generator of all comments contained in this tree.

is_negatable_float

Whether or not this value is a negatable float.

is_negatable_identifier

Whether or not this value is a negatable identifier.

is_negative

Whether or not this value is negative.

name

The name for the node.

never_pad

Whether or not this value node will not have extra spaces added.

nodes

The children nodes of this node.

padding

The padding if any for this ValueNode.

token

The original text (token) for this ValueNode.

type

The data type for this ValueNode.

value

The current semantic value of this ValueNode.

_avoid_rounding_truncation()#

Detects when not enough digits are in original input to preserve precision.

This will update the precision in the formatter to the necessary value to preserve the precision.

_delete_trailing_comment()#

Deletes the trailing comment if any.

_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

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 _print_value#

The print version of the value.

This takes a float/int that is negatable, and negates it based on the is_negative value.

Return type:

int, float

property _value_changed#

Checks if the value has changed at all from first parsing.

Used to shortcut formatting and reverse engineering.

Return type:

bool

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:
  1. the ValueNode is an int.

  2. The value will always be positive.

  3. 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:
  1. the ValueNode is an int.

  2. The value will always be positive.

  3. 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() or is_negatable_identifier() is true then this will return None.

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:

PaddingNode

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