product-farm-farmscript
Human-friendly DSL that compiles to JSON Logic for intuitive rule authoring.
Overview
FarmScript is a domain-specific language designed for business users to write rules without learning JSON Logic syntax. It compiles to JSON Logic for execution.
Write this:
if age < 25 then base_rate * 1.5
else if age < 35 then base_rate * 1.2
else base_rate
Instead of this:
Features
- Natural syntax - Reads like English, not code
- Type inference - Automatic type detection from context
- Error messages - Clear, actionable error descriptions
- Zero runtime - Compiles to JSON Logic at build time
- IDE support - Syntax highlighting and completion (coming soon)
Part of Product-FARM
This crate is part of Product-FARM, an enterprise-grade rule engine featuring:
- 3M+ evaluations/sec with bytecode compilation
- Natural language YAML - Define products in human-readable format
- LLM-powered evaluation - Use AI for complex rule interpretation
- 1 million rules tested at 96k rules/sec
Installation
[]
= "0.2"
Usage
use ;
// Parse and compile FarmScript
let script = r#"
if customer_type == "premium" then
base_price * 0.9
else if quantity > 100 then
base_price * 0.95
else
base_price
"#;
let json_logic = compile_to_json_logic?;
// Now execute with product-farm-json-logic or product-farm-rule-engine
Syntax Reference
Variables
age # Simple variable
customer.address.city # Nested access
items[0].price # Array access
Operators
# Arithmetic
price + tax
total - discount
quantity * unit_price
amount / count
# Comparison
age < 25
status == "active"
score >= threshold
# Logical
is_member and has_discount
is_premium or is_vip
not is_blocked
Conditionals
if condition then result
if condition then
result_a
else
result_b
if condition_1 then result_1
else if condition_2 then result_2
else default_result
Functions
min(a, b, c)
max(price, floor_price)
round(calculated_value, 2)
Related Crates
| Crate | Description |
|---|---|
| product-farm-core | Core domain types |
| product-farm-json-logic | JSON Logic execution |
| product-farm-rule-engine | DAG executor |
| product-farm-yaml-loader | YAML definitions |
Documentation
License
MIT License - see LICENSE for details.