Skip to content

Commit

Permalink
Made a simple tally segment parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
MicahGale committed Jul 1, 2024
1 parent 6c6e822 commit f9e0d3c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
4 changes: 2 additions & 2 deletions montepy/data_inputs/tally_segment.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copyright 2024, Battelle Energy Alliance, LLC All Rights Reserved.
import montepy
from montepy.data_inputs.data_input import DataInputAbstract
from montepy.input_parser.tally_parser import TallyParser
from montepy.input_parser.tally_seg_parser import TallySegmentParser


class TallySegment(DataInputAbstract):
""" """

_parser = TallyParser()
_parser = TallySegmentParser()

@staticmethod
def _class_prefix():
Expand Down
61 changes: 61 additions & 0 deletions montepy/input_parser/tally_seg_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2024, Battelle Energy Alliance, LLC All Rights Reserved.
from montepy.input_parser.data_parser import DataParser
from montepy.input_parser import syntax_node


class TallySegmentParser(DataParser):
""" """

debugfile = None

@_("introduction tally_specification")
def tally(self, p):
ret = {}
for key, node in p.introduction.nodes.items():
ret[key] = node
ret["tally"] = p.tally_specification
return syntax_node.SyntaxNode("data", ret)

@_(
"tally_numbers",
"tally_numbers end_phrase",
"tally_numbers end_phrase end_phrase",
)
def tally_specification(self, p):
if hasattr(p, "end_phrase"):
text = p.end_phrase
else:
text = syntax_node.ValueNode(None, str)

return syntax_node.SyntaxNode(
"tally list", {"tally": p.tally_numbers, "end": text}
)

@_("PARTICLE", "PARTICLE padding", "TEXT", "TEXT padding")
def end_phrase(self, p):
"""
A non-zero number with or without padding.
:returns: a float ValueNode
:rtype: ValueNode
"""
return self._flush_phrase(p, str)

@_(
"tally_numbers tally_numbers",
"number_sequence",
"tally_numbers padding",
)
def tally_numbers(self, p):
if hasattr(p, "tally_numbers"):
ret = p.tally_numbers
ret.nodes["right"] += p.padding
return ret
if hasattr(p, "tally_numbers1"):
return syntax_node.SyntaxNode("tally tree", {"left": p[0], "right": p[1]})
else:
left = syntax_node.PaddingNode(None)
right = syntax_node.PaddingNode(None)
return syntax_node.SyntaxNode(
"tally set", {"left": left, "tally": p[0], "right": right}
)

0 comments on commit f9e0d3c

Please sign in to comment.