Expand description
FarmScript - Human-friendly expression language for Product-FARM
FarmScript compiles to JSON Logic for execution, providing a natural syntax for writing business rules and expressions.
§Example
// FarmScript
alert_acknowledged and time_since_alert_secs < 120
// Compiles to JSON Logic
{"and": [{"var": "alert_acknowledged"}, {"<": [{"var": "time_since_alert_secs"}, 120]}]}§Features
- Natural language operators:
is,isnt,equals,same_as - Path-style variables:
/users/count - Safe division:
a /? b(returns 0),a /! b(returns null) - Template strings:
`Hello {name}!` - SQL-like queries:
from items where x > 0 select x * 2 - Method chaining:
items.filter(x => x > 0).map(x => x * 2) - Truthy check:
x? - Null coalescing:
a ?? b
Structs§
- Builtin
Fn - Description of a built-in function
- Compile
Options - Compilation options
- Compiler
- The FarmScript to JSON Logic compiler
- Lexer
- The lexer that tokenizes FarmScript source
- Parser
- The FarmScript parser
- Span
- Span in source code
- Token
- Token with kind and position
Enums§
- Binary
Op - Binary operators
- Compile
Error - Compilation error
- Expr
- A FarmScript expression
- FnCategory
- Function category
- Literal
- A literal value
- Parse
Error - Parse error
- Token
Kind - Token kinds
- UnaryOp
- Unary operators
Statics§
- BUILTINS
- All built-in functions
Functions§
- compile
- Compile FarmScript source to JSON Logic
- compile_
with_ options - Compile FarmScript source to JSON Logic with options
- get_
builtin - Get builtin by name
- parse
- Parse FarmScript source to AST (for inspection/transformation)
- tokenize
- Tokenize FarmScript source (for debugging)