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

Method execute

prqlc/prqlc/src/cli/mod.rs:363–493  ·  view source on GitHub ↗
(&self, sources: &'a mut SourceTree, main_path: &'a str)

Source from the content-addressed store, hash-verified

361 }
362
363 fn execute<'a>(&self, sources: &'a mut SourceTree, main_path: &'a str) -> Result<Vec<u8>> {
364 let main_path = main_path
365 .split('.')
366 .filter(|x| !x.is_empty())
367 .map(str::to_string)
368 .collect_vec();
369
370 Ok(match self {
371 Command::Parse { format, .. } => {
372 let ast = prql_to_pl_tree(sources)?;
373 match format {
374 Format::Json => serde_json::to_string_pretty(&ast)?.into_bytes(),
375 Format::Yaml => serde_yaml::to_string(&ast)?.into_bytes(),
376 }
377 }
378 Command::Lex { format, .. } => {
379 let s = sources.sources.values().exactly_one().or_else(|_| {
380 // TODO: allow multiple sources
381 bail!("Currently `lex` only works with a single source, but found multiple sources")
382 })?;
383 let tokens = prql_to_tokens(s)?;
384 match format {
385 Format::Json => serde_json::to_string_pretty(&tokens)?.into_bytes(),
386 Format::Yaml => serde_yaml::to_string(&tokens)?.into_bytes(),
387 }
388 }
389 Command::Collect(_) => {
390 let mut root_module_def = prql_to_pl_tree(sources)?;
391
392 drop_module_def(&mut root_module_def.stmts, "std");
393
394 pl_to_prql(&root_module_def)?.into_bytes()
395 }
396 Command::Debug(DebugCommand::Annotate(_)) => {
397 let (_, source) = sources.sources.clone().into_iter().exactly_one().or_else(
398 |_| bail!(
399 "Currently `annotate` only works with a single source, but found multiple sources: {:?}",
400 sources.sources.keys()
401 .map(|x| x.display().to_string())
402 .sorted()
403 .map(|x| format!("`{x}`"))
404 .join(", ")
405 )
406 )?;
407
408 // TODO: potentially if there is code performing a role beyond
409 // presentation, it should be a library function; and we could
410 // promote it to the `prqlc` crate.
411 let root_mod = prql_to_pl(&source)?;
412
413 // resolve
414 let ctx = semantic::resolve(root_mod)?;
415
416 let frames = if let Ok((main, _)) = ctx.find_main_rel(&[]) {
417 semantic::reporting::collect_frames(*main.clone().into_relation_var().unwrap())
418 .frames
419 } else {
420 vec![]

Callers 1

run_io_commandMethod · 0.45

Calls 15

prql_to_pl_treeFunction · 0.85
prql_to_tokensFunction · 0.85
drop_module_defFunction · 0.85
resolveFunction · 0.85
collect_framesFunction · 0.85
combine_prql_and_framesFunction · 0.85
generate_html_docsFunction · 0.85
generate_markdown_docsFunction · 0.85
maybe_strip_colorsFunction · 0.85
highlightFunction · 0.85
log_startFunction · 0.85
pl_to_rq_treeFunction · 0.85

Tested by

no test coverage detected