Skip to content
Snippets Groups Projects
Commit 0065eb9e authored by Sander Mathijs van Veen's avatar Sander Mathijs van Veen
Browse files

ExpressionBase magic methods convert the other arguments to expressionnodes.

parent be7e4a46
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,10 @@ OP_MAP = {
}
def to_expression(obj):
return obj if isinstance(obj, ExpressionBase) else ExpressionLeaf(obj)
class ExpressionBase(object):
def __lt__(self, other):
"""
......@@ -116,19 +120,22 @@ class ExpressionBase(object):
return self.is_leaf() and self.type & (TYPE_FLOAT | TYPE_INTEGER)
def __add__(self, other):
return ExpressionNode('+', self, other)
return ExpressionNode('+', self, to_expression(other))
def __sub__(self, other):
return ExpressionNode('-', self, other)
return ExpressionNode('-', self, to_expression(other))
def __mul__(self, other):
return ExpressionNode('*', self, other)
return ExpressionNode('*', self, to_expression(other))
def __div__(self, other):
return ExpressionNode('-', self, other)
return ExpressionNode('-', self, to_expression(other))
def __pow__(self, other):
return ExpressionNode('^', self, other)
return ExpressionNode('^', self, to_expression(other))
def __neg__(self):
return ExpressionNode('-', to_expression(self))
class ExpressionNode(Node, ExpressionBase):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment