Add function to convert the rename property to a python dict

Probably less error prone, and I can remove code duplication.
master
Salvo 'LtWorf' Tomaselli 2020-06-09 12:05:36 +07:00
parent 6622ba947e
commit 72c4746578
No known key found for this signature in database
GPG Key ID: B3A7CF0C801886CF
1 changed files with 14 additions and 3 deletions

@ -24,7 +24,7 @@
#
# Language definition here:
# http://ltworf.github.io/relational/grammar.html
from typing import Optional, Union, List, Any
from typing import Optional, Union, List, Any, Dict
from dataclasses import dataclass
from relational import rtypes
@ -233,13 +233,24 @@ class Unary(Node):
if self.name == PROJECTION:
prop = '\"%s\"' % prop.replace(' ', '').replace(',', '\",\"')
elif self.name == RENAME:
prop = '{\"%s\"}' % prop.replace(
',', '\",\"').replace(ARROW, '\":\"').replace(' ', '')
prop = repr(self.rename_dict())
else: # Selection
prop = repr(prop)
return '%s.%s(%s)' % (self.child._toPython(), op_functions[self.name], prop)
def rename_dict(self) -> Dict[str, str]:
'''
Returns the dictionary that the rename operation wants
'''
if self.name != RENAME:
raise ValueError('This is only supported on rename nodes')
r = {}
for i in self.prop.split(','):
q = i.split(ARROW)
r[q[0].strip()] = q[1].strip()
return r
def parse_tokens(expression: List[Union[list, str]]) -> Node: