From 1a5e78d6d48489492b654b11b97c3d05e9a1dc1e Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Thu, 27 Aug 2020 15:03:57 +0200 Subject: [PATCH] Fix crash on empty text --- relational/optimizer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/relational/optimizer.py b/relational/optimizer.py index 9de4444..5637b96 100644 --- a/relational/optimizer.py +++ b/relational/optimizer.py @@ -39,7 +39,8 @@ def optimize_program(code: str, rels: Dict[str, Relation]) -> str: lines = code.split('\n') context: Dict[str, Node] = {} - for line in lines: + last_res = None + for line in lines: # skip comments or empty lines line = line.strip() if line.startswith(';') or not line: @@ -51,6 +52,9 @@ def optimize_program(code: str, rels: Dict[str, Relation]) -> str: parsed = tree(query) _replace_leaves(parsed, context) context[res] = parsed + + if last_res is None: + return '' node = optimize_all(context[last_res], rels, tostr=False) return querysplit.split(node, rels)