1
use std::error::Error;
2

            
3
use ahash::AHashSet;
4
use mcrl2::aterm::TermPool;
5

            
6
use crate::utilities::to_untyped_data_expression;
7
use crate::Rule;
8

            
9
/// Create a rewrite rule lhs -> rhs with the given names being variables.
10
3
pub(crate) fn create_rewrite_rule(
11
3
    tp: &mut TermPool,
12
3
    lhs: &str,
13
3
    rhs: &str,
14
3
    variables: &[&str],
15
3
) -> Result<Rule, Box<dyn Error>> {
16
3
    let lhs = tp.from_string(lhs)?;
17
3
    let rhs = tp.from_string(rhs)?;
18
3
    let mut vars = AHashSet::new();
19
6
    for var in variables {
20
3
        vars.insert(var.to_string());
21
3
    }
22

            
23
3
    Ok(Rule {
24
3
        conditions: vec![],
25
3
        lhs: to_untyped_data_expression(tp, &lhs, &vars).into(),
26
3
        rhs: to_untyped_data_expression(tp, &rhs, &vars).into(),
27
3
    })
28
3
}