Fixed infinite recursion when parsing complex BNF node
This commit is contained in:
@@ -334,7 +334,10 @@ class ExecutionContext:
|
||||
for k, v in self._bag.items():
|
||||
bag[k] = v
|
||||
bag["bag." + k] = v
|
||||
for prop in ("id", "who", "desc", "obj", "inputs", "values", "concepts"):
|
||||
for prop in ("id", "who", "action", "desc", "obj", "inputs", "values", "concepts"):
|
||||
bag[prop] = getattr(self, prop)
|
||||
bag["action"] = self.action_context
|
||||
for prop in ("desc", "obj", "inputs", "values", "concepts"):
|
||||
bag[prop] = getattr(self, prop)
|
||||
bag["status"] = self.get_status()
|
||||
bag["elapsed"] = self.elapsed
|
||||
@@ -362,15 +365,23 @@ class ExecutionContext:
|
||||
:param predicate:
|
||||
:return:
|
||||
"""
|
||||
res = []
|
||||
current = self
|
||||
while True:
|
||||
parent = current._parent
|
||||
if parent:
|
||||
if predicate is None or predicate(parent):
|
||||
res.append(parent)
|
||||
current = parent
|
||||
else:
|
||||
return list(self.search(predicate, None, False))
|
||||
|
||||
def search(self, predicate=None, get_obj=None, start_with_self=False, stop=None):
|
||||
"""
|
||||
Iter thru execution context parent and return the list of obj
|
||||
:param predicate: what execution context to keep
|
||||
:param get_obj: lambda to compute what to return
|
||||
:param start_with_self: include the current execution context in the search
|
||||
:param stop: stop the search if matched
|
||||
:return:
|
||||
"""
|
||||
current = self if start_with_self else self._parent
|
||||
while current:
|
||||
if stop and stop(current):
|
||||
break
|
||||
|
||||
return res
|
||||
if predicate is None or predicate(current):
|
||||
yield current if get_obj is None else get_obj(current)
|
||||
|
||||
current = current._parent
|
||||
|
||||
Reference in New Issue
Block a user