simplified and working perfect
This commit is contained in:
parent
333cd329a1
commit
d135f603c0
1 changed files with 7 additions and 17 deletions
|
|
@ -45,40 +45,30 @@ class SyntaxTree(VariableDependency):
|
||||||
return String("".join([str(res) for res in resolved]))
|
return String("".join([str(res) for res in resolved]))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_custom_function_dependencies(
|
def _traverse_custom_function_dependencies(
|
||||||
cls,
|
cls,
|
||||||
custom_function_name: str,
|
custom_function_name: str,
|
||||||
custom_function_dependency: "SyntaxTree",
|
custom_function_dependency: "SyntaxTree",
|
||||||
custom_functions: Dict[str, "SyntaxTree"],
|
custom_functions: Dict[str, "SyntaxTree"],
|
||||||
deps: List[str],
|
deps: List[str],
|
||||||
) -> List[str]:
|
) -> None:
|
||||||
deps = copy.deepcopy(deps) # do not work with references
|
|
||||||
|
|
||||||
for dep in custom_function_dependency.custom_functions:
|
for dep in custom_function_dependency.custom_functions:
|
||||||
# Skip leaf functions since they will never cause a cycle
|
if custom_function_name in deps + [dep.name]:
|
||||||
if not custom_functions[dep.name].custom_functions:
|
cycle_deps = [custom_function_name] + deps + [dep.name]
|
||||||
continue
|
|
||||||
|
|
||||||
deps.append(dep.name)
|
|
||||||
|
|
||||||
if custom_function_name in deps:
|
|
||||||
cycle_deps = [custom_function_name] + deps[0 : deps.index(custom_function_name) + 1]
|
|
||||||
cycle_deps_str = " -> ".join([f"%{name}" for name in cycle_deps])
|
cycle_deps_str = " -> ".join([f"%{name}" for name in cycle_deps])
|
||||||
raise CycleDetected(f"Custom functions contain a cycle: {cycle_deps_str}")
|
raise CycleDetected(f"Custom functions contain a cycle: {cycle_deps_str}")
|
||||||
|
|
||||||
deps += cls._get_custom_function_dependencies(
|
cls._traverse_custom_function_dependencies(
|
||||||
custom_function_name=custom_function_name,
|
custom_function_name=custom_function_name,
|
||||||
custom_function_dependency=custom_functions[dep.name],
|
custom_function_dependency=custom_functions[dep.name],
|
||||||
custom_functions=custom_functions,
|
custom_functions=custom_functions,
|
||||||
deps=deps,
|
deps=deps + [dep.name],
|
||||||
)
|
)
|
||||||
|
|
||||||
return deps
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _ensure_no_custom_function_cycles(cls, custom_functions: Dict[str, "SyntaxTree"]):
|
def _ensure_no_custom_function_cycles(cls, custom_functions: Dict[str, "SyntaxTree"]):
|
||||||
for custom_function_name, custom_function in custom_functions.items():
|
for custom_function_name, custom_function in custom_functions.items():
|
||||||
_ = cls._get_custom_function_dependencies(
|
cls._traverse_custom_function_dependencies(
|
||||||
custom_function_name=custom_function_name,
|
custom_function_name=custom_function_name,
|
||||||
custom_function_dependency=custom_function,
|
custom_function_dependency=custom_function,
|
||||||
custom_functions=custom_functions,
|
custom_functions=custom_functions,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue