Skip to main content

dibs_qgen/parse/
mod.rs

1//! Parse styx into query schema types.
2//!
3//! Uses facet-styx for parsing.
4
5use crate::{QError, QErrorKind, QSource};
6use camino::Utf8Path;
7use dibs_query_schema::{QueryFile, Span};
8use std::sync::Arc;
9
10/// Parse a styx source string into a QueryFile.
11///
12/// Returns both the parsed QueryFile and the QSource for error reporting.
13/// Validation is deferred to SQL generation phase for proper context.
14pub 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    // Note: Filter validation is now done during SQL generation
35    // where we have proper context for rich error messages
36
37    Ok((query_file, qsource))
38}