Documentation
¶
Overview ¶
Package eval provides a simple lexical analyzer for processing logical expressions. It converts human-readable logical operators (and, or, not) to their Go equivalents (&&, ||, !).
Index ¶
- Variables
- func CtxWithParam(ctx context.Context, param Param) context.Context
- func DefaultParamKey() string
- func MustRegisterEvalFunc(name string, v any)
- func RegisterEvalFunc(name string, v any) error
- type ExprCompiler
- type Expression
- type GenericParameter
- type H
- type Lexer
- type NoOPParameter
- type Param
- type ParamGroup
- type Parameter
- type StaticExprOptimizer
- type SyntaxError
- type Value
Constants ¶
This section is empty.
Variables ¶
var ErrIndexOutOfRange = errors.New("index out of range")
Functions ¶
func CtxWithParam ¶
CtxWithParam returns a new context with the parameter.
func DefaultParamKey ¶
func DefaultParamKey() string
DefaultParamKey returns the default key of the parameter.
func MustRegisterEvalFunc ¶
MustRegisterEvalFunc registers a function for eval. If an error occurs, it will panic.
func RegisterEvalFunc ¶
RegisterEvalFunc registers a function for eval. The function must be a function with one return value. And Allowed to overwrite the built-in function.
Types ¶
type ExprCompiler ¶
type ExprCompiler interface {
// Compile compiles the expression and returns the expression.
Compile(expr string) (Expression, error)
}
ExprCompiler is an evaluator of the expression.
type Expression ¶
type Expression interface {
// Execute evaluates the expression and returns the value.
Execute(params Parameter) (Value, error)
}
Expression is an expression which can be evaluated to a value.
func Compile ¶
func Compile(expr string) (Expression, error)
Compile compiles the expression and returns the expression.
type GenericParameter ¶
type GenericParameter struct {
// Value is the wrapped value
Value reflect.Value
// contains filtered or unexported fields
}
GenericParameter is a parameter that wraps a generic value.
func (*GenericParameter) Clear ¶
func (g *GenericParameter) Clear()
Clear clears the cache of the parameter.
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer performs lexical analysis on input strings. It uses Go's standard scanner to tokenize the input and processes specific identifiers for logical operations.
type NoOPParameter ¶
type NoOPParameter struct{}
NoOPParameter is a no-op parameter. Its does nothing when calling the Get method.
type Param ¶
type Param = any
Param is an alias of any type. It is used to represent the parameter of the xmlSQLStatement and without type limitation.
func ParamFromContext ¶
ParamFromContext returns the parameter from the context.
type ParamGroup ¶
type ParamGroup []Parameter
ParamGroup is a group of parameters which implements the Parameter interface.
type Parameter ¶
type Parameter interface {
// Get returns the value of the named parameter with the type of reflect.Value.
Get(name string) (reflect.Value, bool)
}
Parameter is the interface that wraps the Get method. Get returns the value of the named parameter.
func NewGenericParam ¶
NewGenericParam creates a generic parameter. if the value is not a map, struct, slice or array, then wrap it as a map.
func NewParameter ¶
NewParameter creates a new parameter with the given value.
type StaticExprOptimizer ¶
type StaticExprOptimizer struct{}
StaticExprOptimizer is used to optimize static expressions at compile time
type SyntaxError ¶
type SyntaxError struct {
// contains filtered or unexported fields
}
SyntaxError represents a syntax error. The error occurs when parsing the expression.
func (*SyntaxError) Unwrap ¶
func (s *SyntaxError) Unwrap() error
Unwrap returns the underlying error.