Fixed infinite recursion when parsing complex BNF node

This commit is contained in:
2020-06-23 15:22:27 +02:00
parent 912455c343
commit 7310bc5522
28 changed files with 1082 additions and 276 deletions
+26 -1
View File
@@ -187,6 +187,32 @@ def remove_list_from_list(lst, to_remove):
return lst
def make_unique(lst, get_id=None):
"""
All items in the list are now uniq and the order is kept
>>> assert make_unique(["a", "a", "b", "c", "c"]) == ["a", "b", "c"]
:param lst:
:param get_id: define your own way to recognize the items
:return:
"""
def _make_unique(seq, get_id=None):
seen = set()
if get_id is None:
for x in seq:
if x not in seen:
seen.add(x)
yield x
else:
for x in seq:
x = get_id(x)
if x not in seen:
seen.add(x)
yield x
return list(_make_unique(lst, get_id))
def product(a, b):
"""
Kind of cartesian product between lists a and b
@@ -241,7 +267,6 @@ def dict_product(a, b):
return res
def strip_quotes(text):
if not isinstance(text, str):
return text