Step init from a Renderable. Step in Expression

This commit is contained in:
Benjamin Bertrand 2016-03-10 16:40:52 +03:00
parent 9a11549cc1
commit c314b55376
2 changed files with 17 additions and 9 deletions

View File

@ -98,7 +98,7 @@ class Expression(Explicable):
else:
self.simplified = self.child.simplify()
self.simplified.steps = self.child.steps + self.simplified.steps
self.simplified.this_append_before(self.child.steps)
return self.simplified
def compute_exp(self):
@ -106,7 +106,7 @@ class Expression(Explicable):
if len(self.postfix_tokens) == 1:
raise ComputeError("Nothing to compute in {}".format(self.postfix_tokens))
else:
ini_step = Expression(self.postfix_tokens)
ini_step = Step(self.postfix_tokens)
tokenList = self.postfix_tokens.copy()
tmpTokenList = []

View File

@ -41,7 +41,7 @@ class Step(Renderable):
"""
return super(Step, cls).tmp_render(Step)
def __init__(self, pstf_tokens):
def __init__(self, exp):
"""Initiate the renderable objet
:param pstf_tokens: the postfix list of tokens
@ -54,12 +54,20 @@ class Step(Renderable):
< Step [2, 3, '+', 5, '*']>
"""
self.postfix_tokens = []
for t in pstf_tokens:
try:
self.postfix_tokens += t.postfix_tokens
except AttributeError:
self.postfix_tokens.append(t)
if isinstance(exp, Renderable):
self.postfix_tokens = exp.postfix_tokens
elif isinstance(exp, list):
self.postfix_tokens = []
for t in exp:
try:
self.postfix_tokens += t.postfix_tokens
except AttributeError:
self.postfix_tokens.append(t)
else:
raise ValueError(
"Can't initiate Step with {}".format(
exp
))
# -----------------------------