Celixir.Sigil (Celixir v0.2.0)

Copy Markdown View Source

Provides the ~CEL sigil for compile-time parsing of CEL expressions.

Usage

import Celixir.Sigil

# Parse at compile time, evaluate at runtime
ast = ~CEL|request.method == "GET" && user.role == "admin"|
Celixir.Evaluator.eval(ast, env)

# With the 'e' modifier, evaluates immediately with an empty environment
result = ~CEL|1 + 2 * 3|e

Summary

Functions

Parses a CEL expression at compile time into an AST.

Functions

sigil_CEL(term, modifiers)

(macro)

Parses a CEL expression at compile time into an AST.

Modifiers:

  • (none): returns the parsed AST
  • e: evaluates with an empty environment and returns the result

Examples

import Celixir.Sigil

ast = ~CEL|1 + 2|
{:ok, 3} = Celixir.Evaluator.eval(ast, Celixir.Environment.new())

7 = ~CEL|3 + 4|e