@@ -12,9 +12,12 @@ import (
1212 "github.com/antonmedv/expr/vm"
1313)
1414
15+ // Option for configuring config.
16+ type Option func (c * conf.Config )
17+
1518// Eval parses, compiles and runs given input.
1619func Eval (input string , env interface {}) (interface {}, error ) {
17- if _ , ok := env .(conf. Option ); ok {
20+ if _ , ok := env .(Option ); ok {
1821 return nil , fmt .Errorf ("misused expr.Eval: second argument (env) should be passed without expr.Env" )
1922 }
2023
@@ -41,7 +44,7 @@ func Eval(input string, env interface{}) (interface{}, error) {
4144// as well as all fields of embedded structs and struct itself.
4245// If map is passed, all items will be treated as variables.
4346// Methods defined on this type will be available as functions.
44- func Env (i interface {}) conf. Option {
47+ func Env (i interface {}) Option {
4548 return func (c * conf.Config ) {
4649 if _ , ok := i .(map [string ]interface {}); ok {
4750 c .MapEnv = true
@@ -51,42 +54,42 @@ func Env(i interface{}) conf.Option {
5154}
5255
5356// Operator allows to override binary operator with function.
54- func Operator (operator string , fn ... string ) conf. Option {
57+ func Operator (operator string , fn ... string ) Option {
5558 return func (c * conf.Config ) {
5659 c .Operators [operator ] = append (c .Operators [operator ], fn ... )
5760 }
5861}
5962
6063// AsBool tells the compiler to expect boolean result.
61- func AsBool () conf. Option {
64+ func AsBool () Option {
6265 return func (c * conf.Config ) {
6366 c .Expect = reflect .Bool
6467 }
6568}
6669
6770// AsInt64 tells the compiler to expect int64 result.
68- func AsInt64 () conf. Option {
71+ func AsInt64 () Option {
6972 return func (c * conf.Config ) {
7073 c .Expect = reflect .Int64
7174 }
7275}
7376
7477// AsFloat64 tells the compiler to expect float64 result.
75- func AsFloat64 () conf. Option {
78+ func AsFloat64 () Option {
7679 return func (c * conf.Config ) {
7780 c .Expect = reflect .Float64
7881 }
7982}
8083
8184// Optimize turns optimizations on or off.
82- func Optimize (b bool ) conf. Option {
85+ func Optimize (b bool ) Option {
8386 return func (c * conf.Config ) {
8487 c .Optimize = b
8588 }
8689}
8790
8891// Compile parses and compiles given input expression to bytecode program.
89- func Compile (input string , ops ... conf. Option ) (* vm.Program , error ) {
92+ func Compile (input string , ops ... Option ) (* vm.Program , error ) {
9093 config := & conf.Config {
9194 Operators : make (map [string ][]string ),
9295 Optimize : true ,
@@ -128,7 +131,7 @@ func Compile(input string, ops ...conf.Option) (*vm.Program, error) {
128131// Parse parses input string to a program.
129132//
130133// Deprecated: use expr.Compile instead.
131- func Parse (input string , ops ... conf. Option ) (* vm.Program , error ) {
134+ func Parse (input string , ops ... Option ) (* vm.Program , error ) {
132135 return Compile (input , ops ... )
133136}
134137
0 commit comments