now using isinstance instead of that ugly thing

git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@133 014f5005-505e-4b48-8d0a-63407b615a7c
master
LtWorf 2009-04-28 20:39:10 +07:00
parent e528a4babf
commit 256cd3e4ca
1 changed files with 7 additions and 2 deletions

@ -33,10 +33,10 @@ class node (object):
def __init__(self,expression):
'''Generates the tree from the tokenized expression'''
while len(expression)==1 and expression[0].__class__==[].__class__: #We have a list, removing
while len(expression)==1 and isinstance(expression[0],list): #We have a list, removing
expression=expression[0]
if len(expression)==1 and expression[0].__class__=="".__class__: #We have a string!
if len(expression)==1 and isinstance(expression[0],str): #We have a string (relation name)
print "Relation: ",expression[0]
self.kind=RELATION
self.name=expression[0]
@ -168,6 +168,11 @@ def tree(expression):
#isinstance(k,list)
return node(tokenize(expression))
def optimize(expression):
n=tree(expression) #Gets the tree
return n.__str__()
if __name__=="__main__":
#n=node(u"((a b) - c d) - b")
#n=node(u"((((((((((((2)))))))))))) - (3 * 5) - 2")