expr!() { /* proc-macro */ }Expand description
The expr! procedural macro for boolean expressions
Provides clean syntax for building boolean expressions from existing BoolExpr values
with proper operator precedence.
§Supported Syntax
a- Variable or anyBoolExpridentifier in scope"a"- String literal (createsBoolExpr::variable("a")automatically)0- False constant (createsBoolExpr::constant(false))1- True constant (createsBoolExpr::constant(true))!aor~a- NOT operation (both syntaxes supported, like the parser)a * bora & b- AND operation (both*and&supported)a + bora | b- OR operation (both+and|supported)(a + b) * c- Parentheses for grouping
§Operator Precedence
From highest to lowest:
( )(Parentheses - force evaluation order)!/~(NOT)*/&(AND)+/|(OR)
§Examples
ⓘ
use espresso_logic::{BoolExpr, expr};
// Option 1: Use string literals (variables created automatically)
let xor = expr!("a" * !"b" + !"a" * "b");
let complex = expr!(("a" + "b") * "c");
// Option 2: Use existing BoolExpr variables
let a = BoolExpr::variable("a");
let b = BoolExpr::variable("b");
let c = BoolExpr::variable("c");
let and_expr = expr!(a * b);
let or_expr = expr!(a + b);
let not_expr = expr!(!a);
// Option 3: Use constants
let with_const = expr!("a" * 1 + "b" * 0); // a AND true OR b AND false
let always_true = expr!(1);
let always_false = expr!(0);
// Option 4: Mix all styles
let expr1 = expr!(a * b);
let combined = expr!(expr1 + "c" * 1);
// Complex nested expressions
let xor = expr!(a * !b + !a * b);
let complex = expr!((a + b) * c);
// Can compose sub-expressions
let sub_expr1 = expr!(a * b);
let sub_expr2 = expr!(c + !a);
let combined = expr!(sub_expr1 + sub_expr2);