MCPcopy Create free account
hub / github.com/PRQL/prql / collect_frames

Function collect_frames

prqlc/prqlc/src/semantic/reporting.rs:139–168  ·  view source on GitHub ↗

Traverses AST and collects all node.frame

(expr: pl::Expr)

Source from the content-addressed store, hash-verified

137
138/// Traverses AST and collects all node.frame
139pub 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)]
171pub struct ExprGraphNode {

Callers 2

pl_to_lineageFunction · 0.85
executeMethod · 0.85

Calls 6

iterMethod · 0.80
pushMethod · 0.80
get_mutMethod · 0.80
fold_exprMethod · 0.45
insertMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected