1
#![forbid(unsafe_code)]
2

            
3
use ahash::AHashSet;
4
use merc_aterm::ATerm;
5
use merc_data::to_untyped_data_expression;
6
use merc_utilities::MercError;
7

            
8
use crate::Rule;
9

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

            
19
3
    Ok(Rule {
20
3
        conditions: vec![],
21
3
        lhs: to_untyped_data_expression(lhs, Some(&vars)),
22
3
        rhs: to_untyped_data_expression(rhs, Some(&vars)),
23
3
    })
24
3
}