use sqry_core::graph::{GraphBuilderError, GraphResult, Span};
use tree_sitter::{Language, Query};
#[derive(Debug)]
#[allow(dead_code)] pub struct CssQueries {
pub custom_properties: Query,
pub imports: Query,
pub url_calls: Query,
}
impl CssQueries {
#[allow(dead_code)] pub fn new(language: &Language) -> GraphResult<Self> {
let custom_properties = Query::new(language, CUSTOM_PROPERTY_QUERY).map_err(|e| {
GraphBuilderError::ParseError {
span: Span::default(),
reason: format!("Failed to compile custom_properties query: {e}"),
}
})?;
let imports =
Query::new(language, IMPORT_QUERY).map_err(|e| GraphBuilderError::ParseError {
span: Span::default(),
reason: format!("Failed to compile imports query: {e}"),
})?;
let url_calls =
Query::new(language, URL_CALL_QUERY).map_err(|e| GraphBuilderError::ParseError {
span: Span::default(),
reason: format!("Failed to compile url_calls query: {e}"),
})?;
Ok(Self {
custom_properties,
imports,
url_calls,
})
}
}
#[allow(dead_code)] const CUSTOM_PROPERTY_QUERY: &str = r#"
(declaration
(property_name) @name
(#match? @name "^--")) @property
"#;
#[allow(dead_code)] const IMPORT_QUERY: &str = r"
(import_statement) @import
";
#[allow(dead_code)] const URL_CALL_QUERY: &str = r#"
(call_expression
(function_name) @function_name
(arguments) @arguments
(#match? @function_name "^[uU][rR][lL]$")) @url_call
"#;