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
6
pub fn create_rewrite_rule(lhs: &str, rhs: &str, variables: &[&str]) -> Result<Rule, MercError> {
12
6
    let lhs = ATerm::from_string(lhs)?;
13
6
    let rhs = ATerm::from_string(rhs)?;
14
6
    let mut vars = AHashSet::new();
15
6
    for var in variables {
16
6
        vars.insert(var.to_string());
17
6
    }
18

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