rule!() { /* proc-macro */ }Expand description
Define a rewrite rule with pattern/template syntax.
§Syntax
ⓘ
rule!(arena, "rule_name", LHS_PATTERN => RHS_TEMPLATE)
rule!(arena, "rule_name", LHS_PATTERN => RHS_TEMPLATE if condition_expr)arena— an expression of type&mut Arena."rule_name"— a string literal used for tracing.- Identifiers ending in
_are wilds (pattern variables): they match any sub-expression and bind it. - Known constants:
pi,E,I,oo,nan,zoo. - Integer literals:
0,1,2,-3, etc. - Functions:
sin,cos,tan,exp,ln,sqrt,abs. =>separates the pattern (LHS) from the template (RHS).- An optional
if <expr>after the RHS specifies a condition function:fn(&Arena, &Substitution) -> bool.
§Examples
ⓘ
use symplex::prelude::*;
use symplex::rule;
let rules = vec![
rule!(arena, "pythagorean", sin(w_)^2 + cos(w_)^2 => 1),
rule!(arena, "exp_ln", exp(ln(w_)) => w_),
rule!(arena, "ln_exp", ln(exp(w_)) => w_),
];§Limitations
- Only wilds (
w_), integers, known constants, and known functions are allowed. Bare identifiers that are not wilds or constants produce a compile error.