1use crate::{QError, QErrorKind, QSource};
6use camino::Utf8Path;
7use dibs_query_schema::{QueryFile, Span};
8use std::sync::Arc;
9
10pub fn parse_query_file(
15 source_path: &Utf8Path,
16 source: &str,
17) -> Result<(QueryFile, Arc<QSource>), QError> {
18 let qsource = Arc::new(QSource {
19 source: source.to_string(),
20 source_path: source_path.to_owned(),
21 });
22
23 let query_file: QueryFile = facet_styx::from_str(source).map_err(|e| {
24 let span = e.span.unwrap_or(Span { offset: 0, len: 0 });
25 QError {
26 source: qsource.clone(),
27 span,
28 kind: QErrorKind::Parse {
29 message: e.kind.to_string(),
30 },
31 }
32 })?;
33
34 Ok((query_file, qsource))
38}