added support for parenthesis

git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@22 014f5005-505e-4b48-8d0a-63407b615a7c
master
LtWorf 2008-07-22 14:59:31 +07:00
parent f92749f7ee
commit a99aef8c7b
1 changed files with 11 additions and 2 deletions

@ -79,13 +79,15 @@ def parse(expr):
internal=parse(expr[start:end]) internal=parse(expr[start:end])
endp=start-1 endp=start-1
start=-1
symbol="" symbol=""
for i in range(endp,-1,-1): for i in range(endp,-1,-1):
if expr[i:i+2] in symbols: if expr[i:i+2] in symbols:
symbol=expr[i:i+2] symbol=expr[i:i+2]
start=i+2 start=i+2
break break
elif expr[i:i+1] ==")":
break #No symbol before
parameters=expr[start:endp] parameters=expr[start:endp]
res="" #String for result res="" #String for result
@ -100,15 +102,22 @@ def parse(expr):
params+="\"%s\"" % (i.strip()) params+="\"%s\"" % (i.strip())
res="%s.projection(%s)" % (internal,params) res="%s.projection(%s)" % (internal,params)
expr= ("%s%s%s") % (expr[0:start-2],res,expr[end+1:])
elif symbol== "σ": #Selection elif symbol== "σ": #Selection
res="%s.selection(\"%s\")" % (internal,parameters) res="%s.selection(\"%s\")" % (internal,parameters)
expr= ("%s%s%s") % (expr[0:start-2],res,expr[end+1:])
elif symbol=="ρ": #Rename elif symbol=="ρ": #Rename
params=parameters.replace(",","\",\"").replace("","\",\"").replace(" ","") params=parameters.replace(",","\",\"").replace("","\",\"").replace(" ","")
res="%s.rename(\"%s\")" % (internal,params) res="%s.rename(\"%s\")" % (internal,params)
expr= ("%s%s%s") % (expr[0:start-2],res,expr[end+1:])
else:
res="(%s)" % (internal)
expr= ("%s%s%s") % (expr[0:start-1],res,expr[end+1:])
#Last complex operator is replaced with it's python code #Last complex operator is replaced with it's python code
#Next cycle will do the same to the new last unparsed complex operator #Next cycle will do the same to the new last unparsed complex operator
#At the end, parse_op will convert operators without parameters #At the end, parse_op will convert operators without parameters
expr= ("%s%s%s") % (expr[0:start-2],res,expr[end+1:])
return parse_op(expr) return parse_op(expr)
def parse_op(expr): def parse_op(expr):