github.com/naivesound/expr-go

Tiny, fast and extendable expression evaluator in Go


License
MIT
Install
go get github.com/naivesound/expr-go

Documentation

expr - tiny yet super fast math expression evaluator in Go

GoDoc Build Status codecov.io

Example

vars := map[string]expr.Var{
    "x": NewVar(5),
}
funcs := map[string]expr.Func{
    "next": NewFunc(func(args expr.FuncArgs, env expr.FuncEnv) expr.Num {
        return expr.Num(args[0].Eval()+1)
    }),
}
vars["x"].Set(5)
e, err := expr.Parse("y=x+5/next(x)", vars, funcs)
if err != nil {
    log.Fatal(err)
}
result := e.Eval()
log.Println(result)
log.Println(vars["y"])