added support for parenthesis
git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@22 014f5005-505e-4b48-8d0a-63407b615a7c
This commit is contained in:
parent
f92749f7ee
commit
a99aef8c7b
13
parser.py
13
parser.py
@ -79,13 +79,15 @@ def parse(expr):
|
||||
internal=parse(expr[start:end])
|
||||
|
||||
endp=start-1
|
||||
start=-1
|
||||
symbol=""
|
||||
for i in range(endp,-1,-1):
|
||||
if expr[i:i+2] in symbols:
|
||||
symbol=expr[i:i+2]
|
||||
start=i+2
|
||||
break
|
||||
elif expr[i:i+1] ==")":
|
||||
break #No symbol before
|
||||
|
||||
parameters=expr[start:endp]
|
||||
|
||||
res="" #String for result
|
||||
@ -100,15 +102,22 @@ def parse(expr):
|
||||
params+="\"%s\"" % (i.strip())
|
||||
|
||||
res="%s.projection(%s)" % (internal,params)
|
||||
expr= ("%s%s%s") % (expr[0:start-2],res,expr[end+1:])
|
||||
elif symbol== "σ": #Selection
|
||||
res="%s.selection(\"%s\")" % (internal,parameters)
|
||||
expr= ("%s%s%s") % (expr[0:start-2],res,expr[end+1:])
|
||||
elif symbol=="ρ": #Rename
|
||||
params=parameters.replace(",","\",\"").replace("➡","\",\"").replace(" ","")
|
||||
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
|
||||
#Next cycle will do the same to the new last unparsed complex operator
|
||||
#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)
|
||||
|
||||
def parse_op(expr):
|
||||
|
Loading…
Reference in New Issue
Block a user