Documentation
¶
Overview ¶
Example ¶
package main import ( "fmt" "github.com/richardwilkes/toolbox/eval/f64d4eval" ) func main() { e := f64d4eval.NewEvaluator(nil, true) result, err := e.Evaluate("1 + sqrt(2)") if err != nil { panic(err) } fmt.Println(result) }
Output: 2.4142
Index ¶
- func NextArg(args string) (arg, remaining string)
- type Evaluator
- type Function
- type OpFunc
- type Operator
- func Add(f OpFunc, unary UnaryOpFunc) *Operator
- func And(f OpFunc) *Operator
- func CloseParen() *Operator
- func Divide(f OpFunc) *Operator
- func Equal(f OpFunc) *Operator
- func GreaterThan(f OpFunc) *Operator
- func GreaterThanOrEqual(f OpFunc) *Operator
- func LessThan(f OpFunc) *Operator
- func LessThanOrEqual(f OpFunc) *Operator
- func Modulo(f OpFunc) *Operator
- func Multiply(f OpFunc) *Operator
- func Not(f UnaryOpFunc) *Operator
- func NotEqual(f OpFunc) *Operator
- func OpenParen() *Operator
- func Or(f OpFunc) *Operator
- func Power(f OpFunc) *Operator
- func Subtract(f OpFunc, unary UnaryOpFunc) *Operator
- type UnaryOpFunc
- type VariableResolver
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Evaluator ¶
type Evaluator struct { Resolver VariableResolver Operators []*Operator Functions map[string]Function // contains filtered or unexported fields }
Evaluator is used to evaluate an expression. If you do not have any variables that will be resolved, you can leave Resolver unset. StdOperators() and StdFunctions() can be used to populate the Operators and Functions fields.
func (*Evaluator) EvaluateNew ¶
EvaluateNew reuses the Resolver, Operators, and Functions from this Evaluator to create a new Evaluator and then resolves an expression with it.
type OpFunc ¶
type OpFunc func(left, right interface{}) (interface{}, error)
OpFunc provides a signature for an Operator's Evaluate function.
type Operator ¶
type Operator struct { Symbol string Precedence int Evaluate OpFunc EvaluateUnary UnaryOpFunc }
Operator provides an operator implementation for the Evaluator.
type UnaryOpFunc ¶
type UnaryOpFunc func(arg interface{}) (interface{}, error)
UnaryOpFunc provides a signature for an Operator's EvaluateUnary function.
type VariableResolver ¶
VariableResolver is used to resolve variables in expressions into their values.