def simplify(expr):
if isinstance(expr, ParseResults) and len(expr) == 1:
return simplify(expr[0])
if isinstance(expr, (list, ParseResults)):
return map(simplify, expr)
if not isinstance(expr, CompValue):
return expr
if expr.name.endswith('Expression'):
if expr.other is None:
return simplify(expr.expr)
for k in expr.keys():
expr[k] = simplify(expr[k])
# expr['expr']=simplify(expr.expr)
# expr['other']=simplify(expr.other)
return expr
评论列表
文章目录