Step init from a Renderable. Step in Expression
This commit is contained in:
parent
9a11549cc1
commit
c314b55376
@ -98,7 +98,7 @@ class Expression(Explicable):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
self.simplified = self.child.simplify()
|
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
|
return self.simplified
|
||||||
|
|
||||||
def compute_exp(self):
|
def compute_exp(self):
|
||||||
@ -106,7 +106,7 @@ class Expression(Explicable):
|
|||||||
if len(self.postfix_tokens) == 1:
|
if len(self.postfix_tokens) == 1:
|
||||||
raise ComputeError("Nothing to compute in {}".format(self.postfix_tokens))
|
raise ComputeError("Nothing to compute in {}".format(self.postfix_tokens))
|
||||||
else:
|
else:
|
||||||
ini_step = Expression(self.postfix_tokens)
|
ini_step = Step(self.postfix_tokens)
|
||||||
|
|
||||||
tokenList = self.postfix_tokens.copy()
|
tokenList = self.postfix_tokens.copy()
|
||||||
tmpTokenList = []
|
tmpTokenList = []
|
||||||
|
@ -41,7 +41,7 @@ class Step(Renderable):
|
|||||||
"""
|
"""
|
||||||
return super(Step, cls).tmp_render(Step)
|
return super(Step, cls).tmp_render(Step)
|
||||||
|
|
||||||
def __init__(self, pstf_tokens):
|
def __init__(self, exp):
|
||||||
"""Initiate the renderable objet
|
"""Initiate the renderable objet
|
||||||
|
|
||||||
:param pstf_tokens: the postfix list of tokens
|
:param pstf_tokens: the postfix list of tokens
|
||||||
@ -54,12 +54,20 @@ class Step(Renderable):
|
|||||||
< Step [2, 3, '+', 5, '*']>
|
< Step [2, 3, '+', 5, '*']>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if isinstance(exp, Renderable):
|
||||||
|
self.postfix_tokens = exp.postfix_tokens
|
||||||
|
elif isinstance(exp, list):
|
||||||
self.postfix_tokens = []
|
self.postfix_tokens = []
|
||||||
for t in pstf_tokens:
|
for t in exp:
|
||||||
try:
|
try:
|
||||||
self.postfix_tokens += t.postfix_tokens
|
self.postfix_tokens += t.postfix_tokens
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
self.postfix_tokens.append(t)
|
self.postfix_tokens.append(t)
|
||||||
|
else:
|
||||||
|
raise ValueError(
|
||||||
|
"Can't initiate Step with {}".format(
|
||||||
|
exp
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user