Crate product_farm_farmscript

Crate product_farm_farmscript 

Source
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§

BuiltinFn
Description of a built-in function
CompileOptions
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§

BinaryOp
Binary operators
CompileError
Compilation error
Expr
A FarmScript expression
FnCategory
Function category
Literal
A literal value
ParseError
Parse error
TokenKind
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)