Skip to content
Snippets Groups Projects
Commit 90c20998 authored by Valentin Lorentz's avatar Valentin Lorentz
Browse files

Comments.

parent 6a136034
No related branches found
No related tags found
No related merge requests found
...@@ -6,19 +6,25 @@ from ppp_datamodel.nodes.list_operators import * ...@@ -6,19 +6,25 @@ from ppp_datamodel.nodes.list_operators import *
__all__ = ['simplify'] __all__ = ['simplify']
def simplify_union(tree): def simplify_union(tree):
# Trivial cases
if len(tree.list) == 0: if len(tree.list) == 0:
return List([]) return List([])
elif len(tree.list) == 1: elif len(tree.list) == 1:
return tree.list[0] return tree.list[0]
# Partition the items in lists / non-lists
list_ = [x for x in tree.list if x] list_ = [x for x in tree.list if x]
lists = (x.list for x in list_ if isinstance(x, List)) lists = (x.list for x in list_ if isinstance(x, List))
not_lists = [x for x in list_ if not isinstance(x, List)] not_lists = [x for x in list_ if not isinstance(x, List)]
# Make union of lists
lists = list(set(itertools.chain(*lists))) lists = list(set(itertools.chain(*lists)))
if not_lists:
if not_lists: # If there are non-lists (eg. triples)
all_ = not_lists all_ = not_lists
all_.append(List(lists)) all_.append(List(lists))
return Union(all_) return Union(all_)
else: else: # If there are only lists
return List(lists) return List(lists)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment