Skip to content

Commit

Permalink
Started group parsing mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
MicahGale committed Jan 14, 2024
1 parent 8a38f16 commit 94d0217
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions montepy/data_inputs/tally.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ def _number_validator(self, number):
class Tally(DataInputAbstract, Numbered_MCNP_Object):
""" """

# todo type enforcement
_parser = TallyParser()

__slots__ = {"_groups", "_type", "_number", "_old_number"}
__slots__ = {"_groups", "_type", "_number", "_old_number", "_include_total"}

def __init__(self, input=None):
self._cells = Cells()
Expand All @@ -41,6 +42,11 @@ def __init__(self, input=None):
tally_type = TallyType(self.number % _TALLY_TYPE_MODULUS)
except ValueError as e:
raise MalformedInputEror(input, f"Tally Type provided not allowed: {e}")
groups, has_total = TallyGroup.parse_tally_specification(
self._tree["tally"]
)
self._groups = group
self._include_total = has_total

@staticmethod
def _class_prefix():
Expand Down Expand Up @@ -76,7 +82,31 @@ def number(self):
class TallyGroup:
__slots__ = {"_cells"}

def __init__(
self,
):
def __init__(self, cells=None, nodes=None):
self._cells = montepy.cells.Cells()

@staticmethod
def parse_tally_specification(tally_spec):
# TODO type enforcement
ret = []
in_parens = False
buff = None
has_total = False
for node in tally_spec:
# TODO handle total
if in_parens:
if node.value == ")":
in_parens = False
buff.append(node)
ret.append(buff)
buff = None
else:
buff.apend(node)
else:
if node.value == "(":
in_parens = True
buff = TallyGroup()
buff.append(node)
else:
ret.append(TallyGroup(nodes=[node]))
return (ret, has_total)

0 comments on commit 94d0217

Please sign in to comment.