Fix crash on empty text

master
Salvo 'LtWorf' Tomaselli 2020-08-27 15:03:57 +07:00
parent 8270e6517c
commit 1a5e78d6d4
No known key found for this signature in database
GPG Key ID: B3A7CF0C801886CF
1 changed files with 5 additions and 1 deletions

@ -39,7 +39,8 @@ def optimize_program(code: str, rels: Dict[str, Relation]) -> str:
lines = code.split('\n') lines = code.split('\n')
context: Dict[str, Node] = {} context: Dict[str, Node] = {}
for line in lines: last_res = None
for line in lines:
# skip comments or empty lines # skip comments or empty lines
line = line.strip() line = line.strip()
if line.startswith(';') or not line: if line.startswith(';') or not line:
@ -51,6 +52,9 @@ def optimize_program(code: str, rels: Dict[str, Relation]) -> str:
parsed = tree(query) parsed = tree(query)
_replace_leaves(parsed, context) _replace_leaves(parsed, context)
context[res] = parsed context[res] = parsed
if last_res is None:
return ''
node = optimize_all(context[last_res], rels, tostr=False) node = optimize_all(context[last_res], rels, tostr=False)
return querysplit.split(node, rels) return querysplit.split(node, rels)