Moved magic methods from ExpressionNode to Node.

parent e377e758
...@@ -2,8 +2,12 @@ ...@@ -2,8 +2,12 @@
class Node(object): class Node(object):
def __init__(self, label, *nodes): def __init__(self, value, *nodes):
self.label, self.nodes = label, list(nodes) self.value, self.nodes = value, list(nodes)
self.parent = None
for a in self.nodes:
a.parent = self
def __getitem__(self, n): def __getitem__(self, n):
return self.nodes[n] return self.nodes[n]
...@@ -18,12 +22,19 @@ class Node(object): ...@@ -18,12 +22,19 @@ class Node(object):
return len(self.nodes) return len(self.nodes)
def title(self): def title(self):
return str(self.label) return str(self.value)
class Leaf(object): class Leaf(object):
def __init__(self, label): def __init__(self, value):
self.label = label self.value = value
self.parent = None
def __repr__(self):
return repr(self.value)
def __str__(self):
return str(self.value)
def title(self): def title(self):
return str(self.label) return str(self.value)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment