conjure_core/rules/
expand_comprehension.rs

1use conjure_core::ast::{Expression as Expr, SymbolTable};
2use conjure_core::rule_engine::{
3    register_rule, ApplicationError::RuleNotApplicable, ApplicationResult, Reduction,
4};
5
6use crate::into_matrix_expr;
7
8#[register_rule(("Base", 1000))]
9fn expand_comprehension(expr: &Expr, _: &SymbolTable) -> ApplicationResult {
10    let Expr::Comprehension(_, comprehension) = expr else {
11        return Err(RuleNotApplicable);
12    };
13
14    // TODO: check what kind of error this throws and maybe panic
15
16    let results = comprehension
17        .as_ref()
18        .clone()
19        .solve_with_minion()
20        .or(Err(RuleNotApplicable))?;
21
22    Ok(Reduction::pure(into_matrix_expr!(results)))
23}