solve bug with - and ()

This commit is contained in:
Lafrite 2015-03-08 23:56:59 +01:00
parent c391c8e084
commit 097ad25fe2
1 changed files with 18 additions and 0 deletions

View File

@ -313,6 +313,23 @@ class op(object):
""" """
def l_parenthesis(self, op, str_join=False): def l_parenthesis(self, op, str_join=False):
return op return op
def r_parenthesis(self, op, str_join=False):
try:
if op.mainOp.priority <= self.priority:
op = flatten_list(["(", op, ")"])
except AttributeError:
# op has not the attribute priority
try:
if int(op) < 0:
op = ['(', op, ')']
except ValueError:
pass
ans = flatten_list([op])
if str_join:
ans = ' '.join([str(i) for i in ans])
return ans
caract = { caract = {
"operator" : "-", \ "operator" : "-", \
"name" : "sub",\ "name" : "sub",\
@ -322,6 +339,7 @@ class op(object):
"txt" : "{op1} - {op2}",\ "txt" : "{op1} - {op2}",\
"tex" : "{op1} - {op2}",\ "tex" : "{op1} - {op2}",\
"l_parenthesis": l_parenthesis,\ "l_parenthesis": l_parenthesis,\
"r_parenthesis": r_parenthesis,\
} }
return caract return caract