Documentation ¶
Overview ¶
Package eval provides mathematical expression evaluation.
Index ¶
- type Comp
- type Context
- func (c *Context) Copy(other *Context)
- func (c *Context) CopyFuncs(other *Context)
- func (c *Context) CopyVars(other *Context)
- func (c *Context) Delete(name string)
- func (c *Context) DeleteFunc(name string)
- func (c *Context) DeleteVar(name string)
- func (c *Context) Reset()
- func (c *Context) ResetFuncs()
- func (c *Context) ResetVars()
- func (c *Context) Set(name string, value any)
- func (c *Context) SetFunc(name string, value Func)
- func (c *Context) SetFuncsTo(other *Context)
- func (c *Context) SetTo(other *Context)
- func (c *Context) SetVar(name string, value Var)
- func (c *Context) SetVarsTo(other *Context)
- type Expr
- type Func
- type Funcs
- type LogOp
- type LogPre
- type NumOp
- type NumPre
- type Token
- type TokenType
- type Var
- type Vars
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
Context is context that is given when compiling and evaluating expressions. Context contains variables and functions that can be used in expressions.
func DefaultContext ¶
func DefaultContext() *Context
DefaultContext returns a context with standard math constants, standard math functions, and basic logic functions
func LogicalContext ¶
func LogicalContext() *Context
LogicalContext returns a context with basic logical functions
func MathContext ¶
func MathContext() *Context
MathContext returns a context with the standard math functions and constants
func NewContextFrom ¶
NewContextFrom makes a new context by copying the other context
func (*Context) Copy ¶
Copy copies the variables and functions of the other context and does not delete existing variables and functions
func (*Context) CopyFuncs ¶
CopyFuncs copies the funcs from the other context and does not delete existing functions
func (*Context) CopyVars ¶
CopyVars copies the vars from the other context and does not delete existing variables
func (*Context) DeleteFunc ¶
DeleteFunc deletes the given function
func (*Context) SetFuncsTo ¶
SetFuncsTo sets the funcs of the context to the funcs of the other context
type Expr ¶
Expr is an expression that can be evaluated
type Func ¶
A Func is a function that can be used in expressions. Functions take any number of arguments of any type, and return one argument of any type and an error. Use eval/fun to easily make functions.
func NewFunc1 ¶
NewFunc1 makes a function that can be used in expressions from a function that takes a single argument and returns a single value.
func NewFunc2 ¶
NewFunc2 makes a function that can be used in expressions from a function that takes two arguments and returns a single value.
type Funcs ¶
Funcs is a group of named functions that can be used when evaluating expressions.
func DefaultFuncs ¶
func DefaultFuncs() Funcs
DefaultFuncs returns a set of functions containing all of the standard math functions, and basic logic functions
func MathFuncs ¶
func MathFuncs() Funcs
MathFuncs returns a set of functions with all of the standard math functions
func NewFuncsFrom ¶
NewFuncsFrom makes a new set of functions by copying the other functions
func (Funcs) Copy ¶
Copy copies the given functions to v. It does not remove the existing functions in v, but it will override any functions with the same name as copied functions.
type Token ¶
Token is a Token in an expression
type TokenType ¶
type TokenType int
TokenType represents the type of an expression token
const ( // Value is type Var VAR TokenType = iota // Value is type Func FUNC // float64 NUM // literal BOOL // ({[ LEFT // )}] RIGHT // , SEP // Value is type NumOp NUMOP // Value is type NumPre NUMPRE // Value is type Comp COMP // Value is type LogOp LOGOP // Value is type LogPre LOGPRE )
TokenType Constants
type Var ¶
type Var any
A Var is a variable that can be used in expressions. Variables can be of any type and hold any value.
type Vars ¶
Vars is a group of named variables that can be used in expressions.
func DefaultVars ¶
func DefaultVars() Vars
DefaultVars returns a set of variables containing all of the standard math constants
func MathConsts ¶
func MathConsts() Vars
MathConsts returns a set of variables with all of the standard math constants
func NewVarsFrom ¶
NewVarsFrom makes a new set of variables by copying the other variables
func (Vars) Copy ¶
Copy copies the given variables to v. It does not remove the existing variables in v, but it will override any variables with the same name as copied variables.