in o2a/o2a_libs/src/o2a_lib/el_parser.py [0:0]
def translate(expression: str, functions_module: str = "functions", quote: bool = False) -> str:
"""
Translate Expression Language sentence to Jinja.
During translation the following transformations are applied:
- ${, #{ -> {{
- name:function -> name_function
- CamelCase -> camel_case
:param expression: the expression to be translated
:type expression: str
:param functions_module: module with python equivalents of el functions
:type functions_module: str
:param quote: if True then translated expression is quoted
:type quote: bool
:return: translated expression
:rtype: str
"""
if functions_module:
functions_module = functions_module + "."
ast_tree = _parser(expression)
translation = _translate_el(ast_tree, functions_module)
translation = _purify(translation)
# Here we handle missing or necessary spaces before {{
if " ${" not in expression and " #{" not in expression:
translation = translation.replace(" {{", "{{")
elif " {{" not in translation:
translation = translation.replace("{{", " {{")
if quote:
return "'" + translation + "'"
return translation