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

Function insert_stmts_at_path

prqlc/prqlc/src/parser.rs:153–177  ·  view source on GitHub ↗
(module: &mut pr::ModuleDef, mut path: Vec<String>, stmts: Vec<pr::Stmt>)

Source from the content-addressed store, hash-verified

151}
152
153fn insert_stmts_at_path(module: &mut pr::ModuleDef, mut path: Vec<String>, stmts: Vec<pr::Stmt>) {
154 if path.is_empty() {
155 module.stmts.extend(stmts);
156 return;
157 }
158
159 let step = path.remove(0);
160
161 // find submodule def
162 let submodule = module.stmts.iter_mut().find(|x| is_mod_def_for(x, &step));
163 let submodule = if let Some(sm) = submodule {
164 sm
165 } else {
166 // insert new module def
167 let new_stmt = pr::Stmt::new(pr::StmtKind::ModuleDef(pr::ModuleDef {
168 name: step,
169 stmts: Vec::new(),
170 }));
171 module.stmts.push(new_stmt);
172 module.stmts.last_mut().unwrap()
173 };
174 let submodule = submodule.kind.as_module_def_mut().unwrap();
175
176 insert_stmts_at_path(submodule, path, stmts);
177}
178
179pub(crate) fn is_mod_def_for(stmt: &pr::Stmt, name: &str) -> bool {
180 stmt.kind.as_module_def().is_some_and(|x| x.name == name)

Callers 1

parseFunction · 0.85

Calls 4

is_mod_def_forFunction · 0.85
is_emptyMethod · 0.80
pushMethod · 0.80
ModuleDefClass · 0.50

Tested by

no test coverage detected