Traverses AST and collects all node.frame
(expr: pl::Expr)
| 137 | |
| 138 | /// Traverses AST and collects all node.frame |
| 139 | pub fn collect_frames(expr: pl::Expr) -> FrameCollector { |
| 140 | let mut collector = FrameCollector { |
| 141 | frames: vec![], |
| 142 | nodes: vec![], |
| 143 | ast: None, |
| 144 | }; |
| 145 | |
| 146 | collector.fold_expr(expr).unwrap(); |
| 147 | |
| 148 | collector.frames.reverse(); |
| 149 | |
| 150 | let mut parent_updates = Vec::new(); |
| 151 | let mut node_pos = HashMap::new(); |
| 152 | for (i, node) in collector.nodes.iter().enumerate() { |
| 153 | node_pos.insert(node.id, i); |
| 154 | for &child in &node.children { |
| 155 | parent_updates.push((child, node.id)); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | for (child, parent) in parent_updates { |
| 160 | if let Some(child_pos) = node_pos.get(&child) { |
| 161 | if let Some(child_node) = collector.nodes.get_mut(*child_pos) { |
| 162 | child_node.parent = Some(parent); |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | collector |
| 168 | } |
| 169 | |
| 170 | #[derive(Debug, Clone, PartialEq, Serialize, JsonSchema)] |
| 171 | pub struct ExprGraphNode { |