pub(super) fn rpq_label_count(source: &str) -> usize {
match uqa_graph::parse_rpq(source) {
Ok(expr) => count_rpq_labels(&expr).max(1),
Err(_) => 1,
}
}
fn count_rpq_labels(expr: &uqa_graph::RegularPathExpr) -> usize {
use uqa_graph::RegularPathExpr;
match expr {
RegularPathExpr::Label(_) => 1,
RegularPathExpr::Concat(l, r) | RegularPathExpr::Alternation(l, r) => {
count_rpq_labels(l) + count_rpq_labels(r)
}
RegularPathExpr::KleeneStar(inner) => count_rpq_labels(inner).saturating_mul(2),
RegularPathExpr::Bounded { inner, max, .. } => {
count_rpq_labels(inner).saturating_mul(usize::try_from(*max).unwrap_or(usize::MAX))
}
}
}