use crate::compound_expression::Op;
use crate::expression::{Dependency, Expr, Node};
use crate::value::Value;
#[must_use]
pub fn feature_property_keys(expression: &Expr) -> Option<Vec<String>> {
let mut keys = Vec::new();
if !collect_feature_property_keys(expression, &mut keys) {
return None;
}
keys.sort_unstable();
keys.dedup();
Some(keys)
}
fn collect_feature_property_keys(expression: &Expr, keys: &mut Vec<String>) -> bool {
match expression.node() {
Node::Within(_) | Node::Distance(_) | Node::FormatSectionOverride(_) => return false,
Node::Compound(e) => {
let signature = e.signature();
if signature.dependencies.intersects(Dependency::FEATURE) {
let reads_key = match signature.op {
Op::Get | Op::Has => true,
Op::GeometryType => false,
_ => return false,
};
if reads_key {
match e.args().first().and_then(Expr::literal_value) {
Some(Value::String(key)) => keys.push(key.clone()),
_ => return false,
}
}
}
}
_ => {}
}
let mut groupable = true;
expression.each_child(&mut |e| {
groupable = groupable && collect_feature_property_keys(e, keys);
});
groupable
}