|
1 | 1 | import collections |
2 | | -from typing import Deque, Dict, Iterator, List, Optional |
| 2 | +from typing import Deque, Dict, Iterator, List, Optional, Any |
3 | 3 |
|
4 | 4 | from reqif.helpers.debug import auto_described |
5 | 5 | from reqif.models.error_handling import ReqIFSchemaError |
@@ -75,6 +75,34 @@ def iterate_specification_hierarchy( |
75 | 75 | if current.children is not None: |
76 | 76 | task_list.extendleft(reversed(current.children)) |
77 | 77 |
|
| 78 | + def iterate_specification_hierarchy_for_conversion( |
| 79 | + self, |
| 80 | + specification: ReqIFSpecification, |
| 81 | + root_node: Any, |
| 82 | + get_level_lambda, |
| 83 | + node_lambda, |
| 84 | + ): |
| 85 | + section_stack: List[Any] = [root_node] |
| 86 | + |
| 87 | + for current_hierarchy in self.iterate_specification_hierarchy(specification): |
| 88 | + current_section = section_stack[-1] |
| 89 | + section_level = get_level_lambda(current_section) |
| 90 | + |
| 91 | + if current_hierarchy.level <= section_level: |
| 92 | + for _ in range( |
| 93 | + 0, |
| 94 | + (section_level - current_hierarchy.level) + 1, |
| 95 | + ): |
| 96 | + assert len(section_stack) > 0 |
| 97 | + section_stack.pop() |
| 98 | + |
| 99 | + current_section = section_stack[-1] |
| 100 | + converted_node, converted_node_is_section = node_lambda( |
| 101 | + current_hierarchy, current_section |
| 102 | + ) |
| 103 | + if converted_node_is_section: |
| 104 | + section_stack.append(converted_node) |
| 105 | + |
78 | 106 | def get_spec_object_by_ref(self, ref) -> ReqIFSpecObject: |
79 | 107 | return self.lookup.get_spec_object_by_ref(ref) |
80 | 108 |
|
|
0 commit comments