Skip to content

Commit

Permalink
Flattened tally specification data structure for parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
MicahGale committed Jan 14, 2024
1 parent 7d26ebd commit 2bb0cce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
2 changes: 0 additions & 2 deletions montepy/data_inputs/tally.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def __init__(self, input=None):
num = self._input_number
self._old_number = copy.deepcopy(num)
self._number = num
print(self._tree["tally"])
assert False
try:
tally_type = TallyType(self.number % _TALLY_TYPE_MODULUS)
except ValueError as e:
Expand Down
38 changes: 18 additions & 20 deletions montepy/input_parser/tally_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def tally_specification(self, p):
"tally list", {"tally": p.tally_numbers, "end": text}
)

@_('"("', '"(" padding', '")"', '")" padding')
def paren_phrase(self, p):
""" """
return self._flush_phrase(p, str)

@_("PARTICLE", "PARTICLE padding")
def end_phrase(self, p):
"""
Expand All @@ -41,31 +46,24 @@ def end_phrase(self, p):
"tally_numbers tally_numbers",
"number_sequence",
"tally_group",
"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]})
ret = p.tally_numbers1
for node in p.tally_numbers2.nodes:
ret.append(node)
return ret
else:
left = syntax_node.PaddingNode(None)
right = syntax_node.PaddingNode(None)
return syntax_node.SyntaxNode(
"tally set", {"left": left, "tally": p[0], "right": right}
)
return p[0]

@_(
'"(" number_sequence ")"',
'"(" padding number_sequence ")"',
'paren_phrase number_sequence paren_phrase',
)
def tally_group(self, p):
left = syntax_node.PaddingNode(p[0])
if hasattr(p, "padding"):
left.append(p.padding)
right = syntax_node.PaddingNode(p[-1])
return syntax_node.SyntaxNode(
"tally set", {"left": left, "tally": p.number_sequence, "right": right}
)
ret = syntax_node.ListNode()
ret.append(p[0])
for node in p.number_sequence.nodes:
ret.append(node)
ret.append(p[2])
return ret

0 comments on commit 2bb0cce

Please sign in to comment.