Compile is a convenience function that constructs a new Env using the provided EnvOption values, compiles the expression string, and plans an executable Program. Warning: Creating a new environment for every compilation is expensive. Environment setup should be done once and shared across expressio
(expression string, opts ...EnvOption)
| 24 | // Warning: Creating a new environment for every compilation is expensive. Environment setup should be done once |
| 25 | // and shared across expression compilations when the options remain the same. |
| 26 | func Compile(expression string, opts ...EnvOption) (Program, error) { |
| 27 | env, err := NewEnv(opts...) |
| 28 | if err != nil { |
| 29 | return nil, err |
| 30 | } |
| 31 | ast, iss := env.Compile(expression) |
| 32 | if iss.Err() != nil { |
| 33 | return nil, iss.Err() |
| 34 | } |
| 35 | prg, err := env.Program(ast, EvalOptions(OptOptimize)) |
| 36 | if err != nil { |
| 37 | return nil, err |
| 38 | } |
| 39 | return prg, nil |
| 40 | } |