Documentation
¶
Overview ¶
[1] https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html used for reference of expression evaluation logic.
Index ¶
- Constants
- func SetLiteral(tok *Token)
- func ToBoolean(op *Operand) bool
- type Associativity
- type Operand
- func Boolean(b bool) *Operand
- func Eval(expression []byte) (*Operand, error)
- func EvalStr(expression string) (*Operand, error)
- func EvalVar(expression []byte, varFunc VariableFunc) (*Operand, error)
- func EvalVarStr(expression string, varFunc VariableFunc) (*Operand, error)
- func Evaluate(tokens []*Token, varFunc VariableFunc) (*Operand, error)
- func Null() *Operand
- func Number(f float64) *Operand
- func Regexp(r *regexp.Regexp) *Operand
- func String(s string) *Operand
- func Undefined() *Operand
- type OperandType
- type Operator
- type OperatorDetail
- type Token
- type TokenCategory
- type VariableFunc
Constants ¶
View Source
const ( // public aliases StringOperand = otString NumberOperand = otNumber BooleanOperand = otBoolean NullOperand = otNull UndefinedOperand = otUndefined RegexpOperand = otRegexp VariableOperand = otVariable )
Variables ¶
This section is empty.
Functions ¶
func SetLiteral ¶
func SetLiteral(tok *Token)
Types ¶
type Associativity ¶
type Associativity byte // left, right
type Operand ¶
func Eval ¶
Eval evaluates expression and returns the result. No external variables used. See EvalVar for more.
func EvalVar ¶
func EvalVar(expression []byte, varFunc VariableFunc) (*Operand, error)
EvalVar evaluates expression and returns the result. External variables can be used via varFunc.
func EvalVarStr ¶ added in v0.9.4
func EvalVarStr(expression string, varFunc VariableFunc) (*Operand, error)
EvalStrVar evaluates expression and returns the result. External variables can be used via varFunc.
func Evaluate ¶
func Evaluate(tokens []*Token, varFunc VariableFunc) (*Operand, error)
Evaluate evaluates the previously parsed expression
func (*Operand) SetBoolean ¶
func (*Operand) SetUndefined ¶
func (op *Operand) SetUndefined()
type OperandType ¶
type OperandType byte // string, number, boolean, null, undefined
type OperatorDetail ¶
type OperatorDetail struct {
Associativity Associativity
Precedence int
Arguments int
}
type Token ¶
type Token struct {
Category TokenCategory
Operator Operator
Operand
}
type TokenCategory ¶
type TokenCategory byte // operator, literal (operand), parentheses
type VariableFunc ¶
Click to show internal directories.
Click to hide internal directories.