| Crates.io | product-farm-farmscript |
| lib.rs | product-farm-farmscript |
| version | 0.2.0 |
| created_at | 2026-01-04 01:29:55.605667+00 |
| updated_at | 2026-01-04 01:29:55.605667+00 |
| description | FarmScript DSL - Human-friendly expression language that compiles to JSON Logic |
| homepage | |
| repository | https://github.com/ayushmaanbhav/product-farm |
| max_upload_size | |
| id | 2021130 |
| size | 182,334 |
Human-friendly DSL that compiles to JSON Logic for intuitive rule authoring.
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:
{
"if": [
{"<": [{"var": "age"}, 25]}, {"*": [{"var": "base_rate"}, 1.5]},
{"<": [{"var": "age"}, 35]}, {"*": [{"var": "base_rate"}, 1.2]},
{"var": "base_rate"}
]
}
This crate is part of Product-FARM, an enterprise-grade rule engine featuring:
[dependencies]
product-farm-farmscript = "0.2"
use product_farm_farmscript::{Parser, compile_to_json_logic};
// 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(script)?;
// Now execute with product-farm-json-logic or product-farm-rule-engine
age # Simple variable
customer.address.city # Nested access
items[0].price # Array access
# 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
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
min(a, b, c)
max(price, floor_price)
round(calculated_value, 2)
| 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 |
MIT License - see LICENSE for details.