expr

package
v1.6.7 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedBinaryExpr = errors.New("unsupported binary expression")

ErrUnsupportedBinaryExpr is the error that the binary expression is unsupported

Functions

func NewOperationError

func NewOperationError(left, right reflect.Value, operator string) error

NewOperationError creates a new OperationError. It takes the left and right values that caused the error, and the operator that was being applied.

Types

type ADDExprExecutor

type ADDExprExecutor struct{}

ADDExprExecutor is the executor for +

func (ADDExprExecutor) Exec

func (ADDExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type ANDExprExecutor

type ANDExprExecutor struct{}

ANDExprExecutor is the executor for &&

func (ANDExprExecutor) Exec

func (ANDExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type BinaryExprExecutor

type BinaryExprExecutor interface {
	// Exec execute the binary expression
	// right is the right value of the binary expression
	// next is the function to get the left value of the binary expression
	// return the result of the binary expression
	Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)
}

BinaryExprExecutor is the interface for binary expression executor

func FromToken

func FromToken(t token.Token) (BinaryExprExecutor, error)

FromToken returns the BinaryExprExecutor from the token

type BoolOperator

type BoolOperator struct {
	OperatorExpr
}

BoolOperator represents a boolean operator. It embeds OperatorExpr to inherit its methods.

func (BoolOperator) Operate

func (o BoolOperator) Operate(left, right reflect.Value) (reflect.Value, error)

Operate method implements the Operator interface for BoolOperator. It performs the operation represented by the operator on the two boolean values.

type COMMENTExprExecutor

type COMMENTExprExecutor struct{}

func (COMMENTExprExecutor) Exec

func (COMMENTExprExecutor) Exec(_, _ func() (reflect.Value, error)) (reflect.Value, error)

type ComplexOperator

type ComplexOperator struct {
	OperatorExpr
}

ComplexOperator represents a complex operator. It embeds OperatorExpr to inherit its methods.

func (ComplexOperator) Operate

func (o ComplexOperator) Operate(left, right reflect.Value) (reflect.Value, error)

Operate method implements the Operator interface for ComplexOperator. It performs the operation represented by the operator on the two complex values.

type EQLExprExecutor

type EQLExprExecutor struct{}

EQLExprExecutor is the executor for ==

func (EQLExprExecutor) Exec

func (EQLExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type FloatOperator

type FloatOperator struct {
	OperatorExpr
}

FloatOperator represents a float operator. It embeds OperatorExpr to inherit its methods.

func (FloatOperator) Operate

func (o FloatOperator) Operate(left, right reflect.Value) (reflect.Value, error)

Operate method implements the Operator interface for FloatOperator. It performs the operation represented by the operator on the two float values.

type GEQExprExecutor

type GEQExprExecutor struct{}

GEQExprExecutor is the executor for >=

func (GEQExprExecutor) Exec

func (GEQExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type GTRExprExecutor

type GTRExprExecutor struct{}

GTRExprExecutor is the executor for >

func (GTRExprExecutor) Exec

func (GTRExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type GenericOperator

type GenericOperator struct {
	OperatorExpr
}

GenericOperator represents a generic operator. It embeds OperatorExpr to inherit its methods.

func (GenericOperator) Operate

func (o GenericOperator) Operate(left, right reflect.Value) (reflect.Value, error)

Operate method implements the Operator interface for GenericOperator. It performs the operation represented by the operator on the two values, which can be of any type.

type IntOperator

type IntOperator struct {
	OperatorExpr
}

IntOperator represents an integer operator. It embeds OperatorExpr to inherit its methods.

func (IntOperator) Operate

func (o IntOperator) Operate(left, right reflect.Value) (reflect.Value, error)

Operate method implements the Operator interface for IntOperator. It performs the operation represented by the operator on the two integer values.

type InvalidTypeOperator

type InvalidTypeOperator struct {
	OperatorExpr
}

InvalidTypeOperator represents a type operator. It embeds OperatorExpr to inherit its methods.

func (InvalidTypeOperator) Operate

func (o InvalidTypeOperator) Operate(left, right reflect.Value) (result reflect.Value, err error)

Operate method implements the Operator interface for InvalidTypeOperator. It performs the operation represented by the operator on the two values, which are of invalid type.

type LANDExprExecutor

type LANDExprExecutor struct{}

LANDExprExecutor is the executor for &&

func (LANDExprExecutor) Exec

func (LANDExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type LEQExprExecutor

type LEQExprExecutor struct{}

LEQExprExecutor is the executor for <=

func (LEQExprExecutor) Exec

func (LEQExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type LORExprExecutor

type LORExprExecutor struct{}

LORExprExecutor is the executor for ||

func (LORExprExecutor) Exec

func (LORExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type LPARENExprExecutor

type LPARENExprExecutor struct{}

LPARENExprExecutor is the executor for (

func (LPARENExprExecutor) Exec

func (LPARENExprExecutor) Exec(_, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type LSSExprExecutor

type LSSExprExecutor struct{}

LSSExprExecutor is the executor for <

func (LSSExprExecutor) Exec

func (LSSExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type MULExprExecutor

type MULExprExecutor struct{}

MULExprExecutor is the executor for *

func (MULExprExecutor) Exec

func (MULExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type NEQExprExecutor

type NEQExprExecutor struct{}

NEQExprExecutor is the executor for !=

func (NEQExprExecutor) Exec

func (NEQExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type NOTExprExecutor

type NOTExprExecutor struct{}

NOTExprExecutor is the executor for !

func (NOTExprExecutor) Exec

func (NOTExprExecutor) Exec(_, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type ORExprExecutor

type ORExprExecutor struct{}

ORExprExecutor is the executor for ||

func (ORExprExecutor) Exec

func (ORExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type OperationError

type OperationError struct {
	// contains filtered or unexported fields
}

OperationError represents an operation error between two values. It contains the left and right values that caused the error, and the operator that was being applied.

func (OperationError) Error

func (c OperationError) Error() string

Error method implements the error interface. It returns a string describing the error.

type Operator

type Operator interface {

	// Operate performs an operation between two values.
	Operate(left, right reflect.Value) (reflect.Value, error)
}

Operator defines an interface for operators. It has a single method, Operate, which performs an operation between two values.

type OperatorExecutor

type OperatorExecutor struct {
	Operator
}

OperatorExecutor is the executor for operator

func (OperatorExecutor) Exec

func (c OperatorExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression

type OperatorExpr

type OperatorExpr int

OperatorExpr represents an operator expression. It is an integer type that represents different types of operators.

const (
	Add  OperatorExpr = iota // +
	Sub                      // -
	Mul                      // *
	Quo                      // /
	Rem                      // %
	And                      // &
	Land                     // &&
	Or                       // |
	Lor                      // ||
	Eq                       // ==
	Ne                       // !=
	Lt                       // <
	Le                       // <=
	Gt                       // >
	Ge                       // >=
)

func (OperatorExpr) String

func (e OperatorExpr) String() string

String method returns the string representation of the operator.

type QUOExprExecutor

type QUOExprExecutor struct{}

QUOExprExecutor is the executor for /

func (QUOExprExecutor) Exec

func (QUOExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type REMExprExecutor

type REMExprExecutor struct{}

REMExprExecutor is the executor for %

func (REMExprExecutor) Exec

func (REMExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type RPARENExprExecutor

type RPARENExprExecutor struct{}

RPARENExprExecutor is the executor for ) it just return the value

func (RPARENExprExecutor) Exec

func (RPARENExprExecutor) Exec(x, _ func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type SUBExprExecutor

type SUBExprExecutor struct{}

SUBExprExecutor is the executor for -

func (SUBExprExecutor) Exec

func (SUBExprExecutor) Exec(x, y func() (reflect.Value, error)) (reflect.Value, error)

Exec execute the binary expression implement BinaryExprExecutor interface

type StringOperator

type StringOperator struct {
	OperatorExpr
}

StringOperator represents a string operator. It embeds OperatorExpr to inherit its methods.

func (StringOperator) Operate

func (o StringOperator) Operate(left, right reflect.Value) (reflect.Value, error)

Operate method implements the Operator interface for StringOperator. It performs the operation represented by the operator on the two string values.

type UintOperator

type UintOperator struct {
	OperatorExpr
}

UintOperator represents an unsigned integer operator. It embeds OperatorExpr to inherit its methods.

func (UintOperator) Operate

func (o UintOperator) Operate(left, right reflect.Value) (reflect.Value, error)

Operate method implements the Operator interface for UintOperator. It performs the operation represented by the operator on the two unsigned integer values.

Jump to

Keyboard shortcuts

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