expr

package
v0.4.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GreaterThan    ExprComparisonOperator = "gt"
	GreaterOrEqual ExprComparisonOperator = "gte"
	LessThan       ExprComparisonOperator = "lt"
	LessOrEqual    ExprComparisonOperator = "lte"
	Equal          ExprComparisonOperator = "eq"
	NotEqual       ExprComparisonOperator = "neq"

	And ExprLogicalOperator = "and"
	Or  ExprLogicalOperator = "or"
	Not ExprLogicalOperator = "not"

	Number  ExprValueType = "number"
	String  ExprValueType = "string"
	Boolean ExprValueType = "boolean"

	ConstantExprType   ExprType = "const"
	VariantExprType    ExprType = "var"
	ComparisonExprType ExprType = "comparison"
	LogicalExprType    ExprType = "logical"
	NotExprType        ExprType = "not"
)

Variables

This section is empty.

Functions

func MarshalExpr

func MarshalExpr(e Expr) ([]byte, error)

Types

type ComparisonExpr

type ComparisonExpr struct {
	Type     ExprType               `json:"type"` // compare
	Operator ExprComparisonOperator `json:"operator"`
	Left     Expr                   `json:"left"`
	Right    Expr                   `json:"right"`
}

func (ComparisonExpr) Eval

func (c ComparisonExpr) Eval(variables map[string]map[string]any) (*EvalResult, error)

func (ComparisonExpr) GetType

func (c ComparisonExpr) GetType() ExprType

type ComparisonExprRaw

type ComparisonExprRaw struct {
	Type     ExprType               `json:"type"`
	Operator ExprComparisonOperator `json:"operator"`
	Left     json.RawMessage        `json:"left"`
	Right    json.RawMessage        `json:"right"`
}

func (ComparisonExprRaw) ToComparisonExpr

func (r ComparisonExprRaw) ToComparisonExpr() (ComparisonExpr, error)

type ConstantExpr

type ConstantExpr struct {
	Type      ExprType      `json:"type"`
	Value     string        `json:"value"`
	ValueType ExprValueType `json:"valueType"`
}

func (ConstantExpr) Eval

func (c ConstantExpr) Eval(variables map[string]map[string]any) (*EvalResult, error)

func (ConstantExpr) GetType

func (c ConstantExpr) GetType() ExprType

type EvalResult

type EvalResult struct {
	Type  ExprValueType
	Value any
}

func (*EvalResult) And

func (e *EvalResult) And(other *EvalResult) (*EvalResult, error)

func (*EvalResult) Equal

func (e *EvalResult) Equal(other *EvalResult) (*EvalResult, error)

func (*EvalResult) GetBool

func (e *EvalResult) GetBool() (bool, error)

func (*EvalResult) GetFloat64

func (e *EvalResult) GetFloat64() (float64, error)

func (*EvalResult) GreaterOrEqual

func (e *EvalResult) GreaterOrEqual(other *EvalResult) (*EvalResult, error)

func (*EvalResult) GreaterThan

func (e *EvalResult) GreaterThan(other *EvalResult) (*EvalResult, error)

func (*EvalResult) LessOrEqual

func (e *EvalResult) LessOrEqual(other *EvalResult) (*EvalResult, error)

func (*EvalResult) LessThan

func (e *EvalResult) LessThan(other *EvalResult) (*EvalResult, error)

func (*EvalResult) Not

func (e *EvalResult) Not() (*EvalResult, error)

func (*EvalResult) NotEqual

func (e *EvalResult) NotEqual(other *EvalResult) (*EvalResult, error)

func (*EvalResult) Or

func (e *EvalResult) Or(other *EvalResult) (*EvalResult, error)

type Expr

type Expr interface {
	GetType() ExprType
	Eval(variables map[string]map[string]any) (*EvalResult, error)
}

func UnmarshalExpr

func UnmarshalExpr(data []byte) (Expr, error)

type ExprComparisonOperator

type ExprComparisonOperator string

type ExprLogicalOperator

type ExprLogicalOperator string

type ExprType

type ExprType string

type ExprValueSelector

type ExprValueSelector struct {
	Id   string        `json:"id"`
	Name string        `json:"name"`
	Type ExprValueType `json:"type"`
}

type ExprValueType

type ExprValueType string

type LogicalExpr

type LogicalExpr struct {
	Type     ExprType            `json:"type"` // logical
	Operator ExprLogicalOperator `json:"operator"`
	Left     Expr                `json:"left"`
	Right    Expr                `json:"right"`
}

func (LogicalExpr) Eval

func (l LogicalExpr) Eval(variables map[string]map[string]any) (*EvalResult, error)

func (LogicalExpr) GetType

func (l LogicalExpr) GetType() ExprType

type LogicalExprRaw

type LogicalExprRaw struct {
	Type     ExprType            `json:"type"`
	Operator ExprLogicalOperator `json:"operator"`
	Left     json.RawMessage     `json:"left"`
	Right    json.RawMessage     `json:"right"`
}

func (LogicalExprRaw) ToLogicalExpr

func (r LogicalExprRaw) ToLogicalExpr() (LogicalExpr, error)

type NotExpr

type NotExpr struct {
	Type ExprType `json:"type"` // not
	Expr Expr     `json:"expr"`
}

func (NotExpr) Eval

func (n NotExpr) Eval(variables map[string]map[string]any) (*EvalResult, error)

func (NotExpr) GetType

func (n NotExpr) GetType() ExprType

type NotExprRaw

type NotExprRaw struct {
	Type ExprType        `json:"type"`
	Expr json.RawMessage `json:"expr"`
}

func (NotExprRaw) ToNotExpr

func (r NotExprRaw) ToNotExpr() (NotExpr, error)

type VariantExpr

type VariantExpr struct {
	Type     ExprType          `json:"type"`
	Selector ExprValueSelector `json:"selector"`
}

func (VariantExpr) Eval

func (v VariantExpr) Eval(variables map[string]map[string]any) (*EvalResult, error)

func (VariantExpr) GetType

func (v VariantExpr) GetType() ExprType

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL